Results 1 to 12 of 12

Thread: A sub menu problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Question 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:
    1. Private Type RECT
    2.         Left As Long
    3.         Top As Long
    4.         Right As Long
    5.         Bottom As Long
    6. End Type
    7.  
    8. Private Type DRAWITEMSTRUCT
    9.         CtlType As Long
    10.         CtlID As Long
    11.         itemID As Long
    12.         itemAction As Long
    13.         itemState As Long
    14.         hwndItem As Long
    15.         hdc As Long
    16.         rcItem As RECT
    17.         itemData As Long
    18. End Type
    19.  
    20. Private Declare Function ModifyMenu Lib "user32" Alias "ModifyMenuA" _
    21. (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long, _
    22. ByVal wIDNewItem As Long, ByVal lpString As Any) As Long
    23. Private Declare Function GetMenu Lib "user32" (ByVal Hwnd As Long) As Long
    24. Private Declare Function GetMenuItemID Lib "user32" (ByVal hMenu As Long, _
    25. ByVal nPos As Long) As Long
    26. Private Declare Function GetSubMenu Lib "user32" (ByVal hMenu As Long, _
    27. ByVal nPos As Long) As Long
    28. Private Declare Function GetMenuItemRect Lib "user32" (ByVal Hwnd As Long, _
    29. ByVal hMenu As Long, ByVal uItem As Long, lprcItem As RECT) As Long
    30.  
    31. Private Sub Form_Load()
    32.     Dim lngMenu As Long
    33.     Dim lngSubMenu As Long
    34.     Dim rcItem As RECT
    35.    
    36.     'get menu handle
    37.     lngMenu = GetMenu(Me.Hwnd)
    38.    
    39.     'get rectangle for the first item of the menu
    40.     Call GetMenuItemRect(Me.Hwnd, lngMenu, 0, rcItem)
    41.  
    42.     'height of first item in pixels
    43.     Label1.Caption = rcItem.Bottom - rcItem.Top
    44.     Label2.Caption = rcItem.Left
    45. End Sub

    Thanks in advance,
    Ron

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: A sub menu problem

    try this
    VB Code:
    1. Private Sub mnuMain_Click()
    2.     Dim lngMenu As Long
    3.     Dim lngSubMenu As Long
    4.     Dim rcItem As RECT
    5.     'get menu handle
    6.     lngMenu = GetMenu(Me.Hwnd)
    7.     lngSubMenu = GetSubMenu(lngMenu, 0)
    8.     'get rectangle for the first item of the menu
    9.     Call GetMenuItemRect(Me.Hwnd, lngSubMenu, 0, rcItem)
    10.     'height of first item in pixels
    11.     Debug.Print rcItem.Bottom - rcItem.Top
    12.     Debug.Print rcItem.Left
    13. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    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

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: A sub menu problem

    I think the left should be maybe 16 in WinXP.

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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.

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    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

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: A sub menu problem

    this seems to work...

    VB Code:
    1. Private Sub mnuMain_Click()
    2.     Dim lngMenu As Long
    3.     Dim lngSubMenu As Long
    4.     Dim rcItem As RECT
    5.     'get menu handle
    6.     lngMenu = GetMenu(Me.hwnd)
    7.     lngSubMenu = GetSubMenu(lngMenu, 0)
    8.     'get rectangle for the first item of the menu
    9.     Call GetMenuItemRect(Me.hwnd, lngSubMenu, 0, rcItem)
    10.     'height of first item in pixels
    11.     'Debug.Print rcItem.Bottom - rcItem.Top
    12.     'Debug.Print rcItem.Left
    13.     Label1.Caption = rcItem.Bottom - rcItem.Top
    14.  
    15.     'the word "Open" in the submenu has 25 pixels
    16.     Label2.Caption = ((rcItem.Right - rcItem.Left) - 25) \ 2
    17. End Sub

    What do you think? What operating system do you have?

  8. #8
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: A sub menu problem

    try this
    VB Code:
    1. Label2.Caption = rcItem.Left - Me.ScaleX(Me.Left, vbTwips, vbPixels)

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    Re: A sub menu problem

    I get 4

  10. #10
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: A sub menu problem

    That is correct. the left position of the menu within the form is 4 pixels.

  11. #11
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: A sub menu problem

    I'll dl your code from the other thread to see what you are trying to do.

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Posts
    154

    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
  •  



Click Here to Expand Forum to Full Width