|
-
Oct 7th, 2005, 08:10 AM
#1
Thread Starter
Addicted Member
A sub menu problem
Hey,
I posted a question in api yesterday, but the one person that responded
didn't have the time to help much. This is a more simple version of the
same question. If I'm not suppose to ask basically the same question in
another forum, then let me know and I will remove it. This is really bugging
me!
Here we go...
mnuMain
....mnuOpen
In the code below, I can get the height of the main menu, and the
.left position of the text. If you click on mnuMain, the first item is
mnuOpen. Here's the question...
How can I retrieve the same information for mnuOpen as I did
for mnuMain?
VB Code:
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type DRAWITEMSTRUCT
CtlType As Long
CtlID As Long
itemID As Long
itemAction As Long
itemState As Long
hwndItem As Long
hdc As Long
rcItem As RECT
itemData As Long
End Type
Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" _
(ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
Private Declare Function GetMenu Lib "user32" (ByVal Hwnd As Long) As Long
Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
ByVal nPos As Long) As Long
Private Declare Function GetMenuItemRect Lib "user32" (ByVal Hwnd As Long, _
ByVal hMenu As Long, ByVal uItem As Long, lprcItem As RECT) As Long
Private Sub Form_Load()
Dim lngMenu As Long
Dim lngSubMenu As Long
Dim rcItem As RECT
'get menu handle
lngMenu = GetMenu(Me.Hwnd)
'get rectangle for the first item of the menu
Call GetMenuItemRect(Me.Hwnd, lngMenu, 0, rcItem)
'height of first item in pixels
Label1.Caption = rcItem.Bottom - rcItem.Top
Label2.Caption = rcItem.Left
End Sub
Thanks in advance,
Ron
-
Oct 7th, 2005, 10:39 AM
#2
Re: A sub menu problem
try this
VB Code:
Private Sub mnuMain_Click()
Dim lngMenu As Long
Dim lngSubMenu As Long
Dim rcItem As RECT
'get menu handle
lngMenu = GetMenu(Me.Hwnd)
lngSubMenu = GetSubMenu(lngMenu, 0)
'get rectangle for the first item of the menu
Call GetMenuItemRect(Me.Hwnd, lngSubMenu, 0, rcItem)
'height of first item in pixels
Debug.Print rcItem.Bottom - rcItem.Top
Debug.Print rcItem.Left
End Sub
-
Oct 7th, 2005, 11:07 AM
#3
Thread Starter
Addicted Member
Re: A sub menu problem
Hey moeur,
I get 17 for the height, and 356 for the left. 356 is not right...it should
be 21 or 22.
I'm using Win98, VB5.
Thanks,
Ron
-
Oct 7th, 2005, 11:12 AM
#4
Thread Starter
Addicted Member
Re: A sub menu problem
I think the left should be maybe 16 in WinXP.
-
Oct 7th, 2005, 11:13 AM
#5
Re: A sub menu problem
Are you looking for coordiantes relative to your form?
I think this gives coordiantes relative to the screen which means you'll have to subtract the left pixel location of your form.
-
Oct 7th, 2005, 11:26 AM
#6
Thread Starter
Addicted Member
Re: A sub menu problem
I need the measurement to the text of the sub menu. If you look at my
post yesterday, you'll see what I'm talking about...
http://www.vbforums.com/showthread.php?t=364349
thanks
-
Oct 7th, 2005, 11:58 AM
#7
Thread Starter
Addicted Member
Re: A sub menu problem
this seems to work...
VB Code:
Private Sub mnuMain_Click()
Dim lngMenu As Long
Dim lngSubMenu As Long
Dim rcItem As RECT
'get menu handle
lngMenu = GetMenu(Me.hwnd)
lngSubMenu = GetSubMenu(lngMenu, 0)
'get rectangle for the first item of the menu
Call GetMenuItemRect(Me.hwnd, lngSubMenu, 0, rcItem)
'height of first item in pixels
'Debug.Print rcItem.Bottom - rcItem.Top
'Debug.Print rcItem.Left
Label1.Caption = rcItem.Bottom - rcItem.Top
'the word "Open" in the submenu has 25 pixels
Label2.Caption = ((rcItem.Right - rcItem.Left) - 25) \ 2
End Sub
What do you think? What operating system do you have?
-
Oct 7th, 2005, 12:05 PM
#8
Re: A sub menu problem
try this
VB Code:
Label2.Caption = rcItem.Left - Me.ScaleX(Me.Left, vbTwips, vbPixels)
-
Oct 7th, 2005, 12:12 PM
#9
Thread Starter
Addicted Member
-
Oct 7th, 2005, 12:16 PM
#10
Re: A sub menu problem
That is correct. the left position of the menu within the form is 4 pixels.
-
Oct 7th, 2005, 12:18 PM
#11
Re: A sub menu problem
I'll dl your code from the other thread to see what you are trying to do.
-
Oct 7th, 2005, 12:24 PM
#12
Thread Starter
Addicted Member
Re: A sub menu problem
I'm trying to find the distance (pixels) from the left edge of the menu
to the left edge of the menu text.
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|