Results 1 to 18 of 18

Thread: Using TrackPopupMenu API to open menu designed with VB Menu Editor

  1. #1

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Question Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Hello,
    How can I use the TrackPopupMenu API to open a menu designed with Menu Editor that I would normally display through:
    Code:
    Popupmenu MenuName, Flags, X, Y, DefaultMenu
    Specifically, what combination of GetMenu and/or GetSubMenu should I use (or maybe even other API calls) to transform MenuName (a menu object in VB6) to the needed menu handle (LONG value) needed in TrackPopupMenu?
    Also, as important as getting the menu to appear is setting the default (bold) menu item through API also.


    Waiting for your help...
    Thanks in advance.
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by TupacShakur View Post
    Also, as important as getting the menu to appear is setting the default (bold) menu item through API also.
    Call the SetMenuDefaultItem function.


    EDIT

    What are you trying to achieve with TrackPopupMenu?
    Last edited by Bonnie West; Jun 21st, 2013 at 09:09 AM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    I use this function extensively, so here's some code. Note that like other menus, for some reason the image size is limited to 13x13. Getting around this is very complicated and I'd recommend clsMenuImage by Leandro Ascierto - no ocx or user ctl, just a class module. If you don't need bigger images or images at all, here's a code that I use to display a 'View' menu for a listview containing a display of files like Explorer.

    NOTE::: This is not a fully functional copy-pastable code, it's merely a snippet from a full program just to demonstrate how TPM works.

    Code:
    Public Function ViewMenuPopup2() As Long
    
    Dim i As Long, j As Long
    Dim hMenu As Long, hSubMenuView As Long, hSubMenuSort As Long
    Dim midCmd As Long
    Dim mii As MENUITEMINFO
    Dim mii2 As MENUITEMINFO
    Dim pt As POINTAPI
    Dim lSortID() As Long
    Dim sSortCur As String
    
    Const sView = "View"
    Const sLarge = "Large Icons"
    Const sSmall = "Small Icons"
    Const sList = "List"
    Const sDetails = "Details"
    Const sTiles = "Tiles"
    Const sThumb = "Thumbnails"
    Const sSortA = "Sort Ascending"
    Const sSortD = "Sort Descending"
    
    Const mtxSort = "Sort By"
    
    
    Const sNewF = "New Folder"
    Const sAddF = "Add All Files"
    Const sAddA = "Add All"
    Const sRefr = "Refresh"
    
    Const idView = 14000
    Const idLarge = 14001
    Const idSmall = 14002
    Const idList = 14003
    Const idDetails = 14004
    Const idTiles = 14005
    Const idThumbs = 14008
    Const idSortA = 14006
    Const idSortD = 14007
    Const midSort = 13000
    Const idNewF = 13002
    Const idAddF = 13003
    Const idAddA = 13004
    Const idRefr = 13005
    Const midTest1 = 13001
    Const idSortBase = 15000
    Const mtxTest1 = "Test"
    
    
    
    Call GetCursorPos(pt)
    hMenu = CreatePopupMenu()
    
    
    iCurViewMode = CInt(ListView_GetView(m_hwndLV))
    
    With mii
        .cbSize = Len(mii)
    
        'Construct Sort By menu: the whole point of doing this by hand
        'Add all the currently visible columns as sort options
        
        hSubMenuSort = CreateMenu()
        
        ReDim lSortID(ListView1.ColumnHeaders.count - 1)
        For i = 0 To UBound(lSortID)
            lSortID(i) = idSortBase + i + 1
            sSortCur = ListView1.ColumnHeaders(i + 1).Text
            .fMask = MIIM_ID Or MIIM_TYPE
            .fType = MFT_STRING
            .wID = lSortID(i)
            .dwTypeData = sSortCur
            .cch = Len(sSortCur)
            Call InsertMenuItem(hSubMenuSort, 0, False, mii)
        Next i
        .fMask = MIIM_ID Or MIIM_TYPE
        .fType = MFT_SEPARATOR
        .wID = 0
        Call InsertMenuItem(hSubMenuSort, 0, False, mii)
        
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP Or MIIM_STATE Or MIIM_CHECKMARKS
        .wID = idSortA
        .dwTypeData = sSortA
        .cch = Len(sSortA)
        .fState = IIf(mnuViewArrangeAZ.Checked = True, MFS_CHECKED, MFS_UNCHECKED)
        .hbmpChecked = CLng(Picture11(21).Picture)
        .hbmpUnchecked = CLng(Picture11(11).Picture)
        Call InsertMenuItem(hSubMenuSort, 9998, True, mii)
        
        .wID = idSortD
        .dwTypeData = sSortD
        .cch = Len(sSortD)
        .fState = IIf(mnuViewArrangeZA.Checked = True, MFS_CHECKED, MFS_UNCHECKED)
        .hbmpChecked = CLng(Picture11(22).Picture)
        .hbmpUnchecked = CLng(Picture11(12).Picture)
    
        Call InsertMenuItem(hSubMenuSort, 9999, True, mii)
        
        'Construct View submenu
        hSubMenuView = CreateMenu()
        .fMask = MIIM_ID Or MIIM_STRING 'Or MIIM_BITMAP
        .wID = idThumbs
        .dwTypeData = sThumb
        .cch = Len(sThumb)
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
        
        
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idTiles
        .dwTypeData = sTiles
        .hbmpItem = IIf(iCurViewMode = 4, CLng(Picture12(9).Picture), CLng(Picture12(8).Picture))
        .cch = Len(sTiles)
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idDetails
        .dwTypeData = sDetails
        .cch = Len(sDetails)
        .hbmpItem = IIf(iCurViewMode = 1, CLng(Picture11(20).Picture), CLng(Picture11(10).Picture))
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idList
        .dwTypeData = sList
        .cch = Len(sList)
        .hbmpItem = IIf(iCurViewMode = 3, CLng(Picture11(19).Picture), CLng(Picture11(9).Picture))
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
        .wID = idSmall
        .dwTypeData = sSmall
        .cch = Len(sSmall)
        .hbmpItem = IIf(iCurViewMode = 2, CLng(Picture11(18).Picture), CLng(Picture11(8).Picture))
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
        .wID = idLarge
        .dwTypeData = sLarge
        .cch = Len(sLarge)
        .hbmpItem = IIf(iCurViewMode = 0, CLng(Picture11(17).Picture), CLng(Picture11(7).Picture))
        Call InsertMenuItem(hSubMenuView, 0, True, mii)
        
       
        
        'Create New Folder
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idNewF
        .dwTypeData = sNewF
        .cch = Len(sNewF)
        .hbmpItem = CLng(Picture12(0).Picture)
        Call InsertMenuItem(hMenu, 0, True, mii)
        
        'Sep
        .fMask = MIIM_ID Or MIIM_TYPE
        .fType = MFT_SEPARATOR
        .wID = 0
        Call InsertMenuItem(hMenu, 1, True, mii)
        
        'Add all files
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idAddF
        .dwTypeData = sAddF
        .cch = Len(sAddF)
        .hbmpItem = CLng(Picture12(2).Picture)
        Call InsertMenuItem(hMenu, 2, True, mii)
        
        'Add all
        .fMask = MIIM_ID Or MIIM_STRING
        .wID = idAddA
        .dwTypeData = sAddA
        .cch = Len(sAddA)
        Call InsertMenuItem(hMenu, 3, True, mii)
        
        
        'Insert View Submenu
        .fMask = MIIM_SUBMENU Or MIIM_TYPE
        .fType = MFT_STRING
        .wID = idView
        .dwTypeData = sView
        .cch = Len(sView)
        .hSubMenu = hSubMenuView
        Call InsertMenuItem(hMenu, 4, True, mii)
        
        'Insert Sort Submenu
        .fMask = MIIM_SUBMENU Or MIIM_TYPE
        .fType = MFT_STRING
        .wID = idSortBase
        .dwTypeData = mtxSort
        .cch = Len(sView)
        .hSubMenu = hSubMenuSort
        Call InsertMenuItem(hMenu, 5, True, mii)
    
        'Sep
        .fMask = MIIM_ID Or MIIM_TYPE
        .fType = MFT_SEPARATOR
        .wID = 0
        Call InsertMenuItem(hMenu, 6, True, mii)
    
        'Refresh
        .fMask = MIIM_ID Or MIIM_STRING Or MIIM_BITMAP
        .wID = idRefr
        .dwTypeData = sRefr
        .cch = Len(sRefr)
        .hbmpItem = CLng(Picture11(13).Picture)
        Call InsertMenuItem(hMenu, 7, True, mii)
        
    End With
    
    
    midCmd = TrackPopupMenu(hMenu, TPM_LEFTBUTTON Or TPM_RIGHTBUTTON Or TPM_LEFTALIGN Or TPM_TOPALIGN Or TPM_HORIZONTAL Or TPM_RETURNCMD, pt.x, pt.y, 0, Form1.ListView1.hWnd, 0)
    
    
    If midCmd Then
        DoEvents
        Select Case midCmd
            Case idNewF
                CreateNewDirectory m_hwndLV
                bFlagNewDir = True
                Exit Function
            Case idAddF 'Add All Files
                SetSelect "*", 1
                Call Command5_Click
                RefreshView 'bug: items disappear from LV1 when Command5_Click is called
                            '     but not when it's actually clicked. *** VB?
            Case idAddA 'Add All
                ListView_SelectAll ListView1.hWnd
                Call Command5_Click
            Case idRefr
                RefreshView
            Case idLarge
                Call SwitchView(LV_VIEW_ICON)
            Case idSmall
                Call SwitchView(LV_VIEW_SMALLICON)
            Case idList
                Call SwitchView(LV_VIEW_LIST)
            Case idDetails
                Call SwitchView(LV_VIEW_DETAILS)
            Case idTiles
                Call mnuViewTiles_Click
            Case idSortA
                ListView1.SortOrder = lvwAscending
                Call ModifyMenu(hSubMenuSort, idSortA, MF_BYCOMMAND Or MF_CHECKED, idSortA, ByVal 0&)
                Call ModifyMenu(hSubMenuSort, idSortD, MF_BYCOMMAND Or MF_UNCHECKED, idSortD, ByVal 0&)
                mnuViewArrangeAZ.Checked = True
                mnuViewArrangeZA.Checked = False
               
                Call SortListview
            Case idSortD
                ListView1.SortOrder = lvwDescending
                Call ModifyMenu(hSubMenuSort, idSortD, MF_BYCOMMAND Or MF_CHECKED, idSortD, ByVal 0&)
                Call ModifyMenu(hSubMenuSort, idSortA, MF_BYCOMMAND Or MF_UNCHECKED, idSortA, ByVal 0&)
                mnuViewArrangeZA.Checked = True
                mnuViewArrangeAZ.Checked = False
               
                Call SortListview
            Case Is > 15000
                Call ListView1_ColumnClick(ListView1.ColumnHeaders(midCmd - 15000))
        End Select
    End If 'midCmd
    ViewMenuPopup = midCmd
    
    Call DestroyMenu(hSubMenuSort)
    Call DestroyMenu(hSubMenuView)
    Call DestroyMenu(hMenu)
    
    End Function
    This is the type of menu it produces:


    Also: For a bold default item, you add MF_DEFAULT to the MenuItemInfo struct's .fState property.

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    VB6's Menu controls don't expose their hMenu values so there isn't much you can do with them in terms of API calls.

  5. #5
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by dilettante View Post
    VB6's Menu controls don't expose their hMenu values so there isn't much you can do with them in terms of API calls.
    Well they do (GetMenu works fine, you just pass it the forms .hWnd).

    So anyway, I misunderstood the initial question. I'll leave my other post up there if you want to overcome the limitations. But anyway:
    Code:
    Public Function UseTPM(lMenuPos As Long) As Long
    Dim pt As POINTAPI
    
    Call GetCursorPos(pt)
    
    Dim midCmd As Long
    Dim hMenu As Long
    Dim hSubMenu As Long
    
    hMenu = GetMenu(Me.hWnd)
    hSubMenu = GetSubMenu(hMenu, lMenuPos)
    
    midCmd = TrackPopupMenu(hSubMenu, TPM_LEFTBUTTON Or TPM_RIGHTBUTTON Or TPM_LEFTALIGN Or TPM_TOPALIGN Or TPM_HORIZONTAL Or TPM_RETURNCMD, pt.x, pt.y, 0, Form1.hWnd, 0)
    
    Select Case midCmd
    [...]
    End Function
    If you want to process those commands, you need to know their IDs. These are not constant (from run to run) I believe, so each time your program starts,

    Assuming midFile() is a public long array for your file menu,

    Code:
    Private Sub AssignMenuIDs()
    'Copies the item id numbers for the main menu bar
    Dim hMenu As Long
    Dim hSubMenu As Long
    Dim i As Long
    
    hMenu = GetMenu(Me.hWnd)
    
    'File menu- 13 items
    hSubMenu = GetSubMenu(hMenu, 0)
    ReDim midFile(13)
    For i = 0 To 13
        midFile(i) = GetMenuItemID(hSubMenu, i)
    Next i
    Last edited by fafalone; Jun 21st, 2013 at 12:00 PM.

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Ahh, ok. You mean start there and work your way down using GetSubMenu() calls.

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by dilettante View Post
    Ahh, ok. You mean start there and work your way down using GetSubMenu() calls.
    The submenus are handled automatically- hSubMenu here is really just the menu titles, like on many forms GetSubMenu(0) would be the File menu. You'd need to get their command IDs into the array to process the selection, but say if your file menu had a submenu, there's no additional processing required.

    For getting those IDs from a submenu, you would just do something like this:
    Code:
    'View Menu - 18 items (not including the sub-submenu)
    hSubMenu = GetSubMenu(hMenu, 2)
    ReDim midView(18)
    For i = 0 To 18
        midView(i) = GetMenuItemID(hSubMenu, i)
    Next i
    
    Dim hSubMenu2 As Long
    hSubMenu2 = GetSubMenu(hSubMenu, 1)
    Then go through GetMenuItemID loops for hSubMenu2.

  8. #8
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by TupacShakur View Post
    How can I use the TrackPopupMenu API to open a menu designed with Menu Editor that I would normally display through:
    Code:
    Popupmenu MenuName, Flags, X, Y, DefaultMenu
    Specifically, what combination of GetMenu and/or GetSubMenu should I use (or maybe even other API calls) to transform MenuName (a menu object in VB6) to the needed menu handle (LONG value) needed in TrackPopupMenu?
    The way I understand it, you want to retrieve the handle of the menu shown by the PopupMenu method. If so, then a possible approach is through subclassing. My tests revealed that the WM_INITMENU and WM_INITMENUPOPUP messages can provide the required menu handle (WM_INITMENU is sent earlier). These messages can't tell you though, whether that menu handle belongs to a popup menu or not. To address that, you may want to set a flag variable during the WM_ENTERMENULOOP message and unset it during the WM_EXITMENULOOP message. Alternatively, you can also do it during the WM_CONTEXTMENU and WM_UNINITMENUPOPUP messages.

    BTW, MSDN says:

    Quote Originally Posted by MSDN
    The older TrackPopupMenu function is still supported, but new applications should use the TrackPopupMenuEx function.
    Last edited by Bonnie West; Jun 21st, 2013 at 12:45 PM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    My tests revealed that the WM_INITMENU and WM_INITMENUPOPUP messages can provide the required menu handle (WM_INITMENU is sent earlier).
    To be clear, are you referring to menus not otherwise shown on the main menu bar for your app, since GetMenu can't see those? In which case just providing the strings and position info yourself is a much better approach than trying to capture and copy another popup menu... because wouldn't it need to be displayed once before you could get its handle? In any case, better to just re-make the menu.

  10. #10
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by fafalone View Post
    To be clear, are you referring to menus not otherwise shown on the main menu bar for your app, since GetMenu can't see those?
    Yes.

    Quote Originally Posted by fafalone View Post
    In which case just providing the strings and position info yourself is a much better approach than trying to capture and copy another popup menu... because wouldn't it need to be displayed once before you could get its handle? In any case, better to just re-make the menu.
    True. That is why I've asked in post #2 what the OP wanted to achieve. I couldn't figure out what he was trying to do.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  11. #11

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Sorry for not posting any feedback earlier, but was handling some other hiccups that arose in my app.
    So I haven't tried anything yet, but I see so many suggestions and maybe also a misunderstanding of what I want to achieve. Maybe I wasn't clear enough in my original phrasing of the question, or even in my assumption of what APIs to use. Then again, maybe I was. Anyways, here's what I meant:

    In the VB IDE, I have designed a menu for my app. Well, several menu items with subitems (File, Edit, Tools, Help). Also, I have 2 invisible menus that are invoked on right click events of certain controls (label, picturebox). Up to this point, I've always done this through a
    Code:
    Me.Popupmenu MenuName, Flags, X, Y, BoldItem
    call. For reasons that are not particularly important to this topic, I am simply looking for an alternative way to achieve what the Popuomenu VB call does, which is show the menu passed to it. I have code that is processed within this menu (for example, submenu_click does something, etc...). All I'm looking for is a way to display the menu through a different means than the native Popupmenu VB method. So I looked into API calls, and I came across TrackPopupMenu.

    I'm not sure if this changes anything... Anyway, do any of your suggestions apply? Or is there another way altogether?
    Thanks again.
    Last edited by TupacShakur; Jun 22nd, 2013 at 06:42 AM.
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  12. #12
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    I think VB's PopupMenu method internally calls the TrackPopupMenu API, so you would just be making things harder for yourself.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  13. #13
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    The method I posted in comments 5 and 7 are what you are looking for, but only for menus that are already visible. For the hidden menus, there's no easy way to do it. Either subclassing, showing the menu once and copying its details, or you'd have to open your exe's resource file in code and read the menu information from that (if you can even do that with vb apps, I've only done it with other apps, and only for image resources at that, so it may not be possible).

  14. #14

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Hmm.. Well, I thought it was a simple thing.
    But before I delve into all this complicated stuff, I think a simple information might save me the hassle of it.
    See things changed a bit since I first asked, and now I may be able to achieve what I want by using the VB native PopupMenu method wrapped in another function. But to preserve its full functionality, I need to duplicate its parameters within my function. I tried it, and I'm facing some trouble with the X and Y parameters - namely, their default values as optional arguments. So what I'm asking now: What values for X and Y sent to PopupMenu trigger its default behavior of using the cursor's position.

    P.S: GetCurPos fails to emulate the default X and Y coordinates used by PopupMenu in many situations, so I'm only looking for the values for X and Y that trigger PopupMenu's default behavior.
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  15. #15
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,647

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    If I had to guess I'd say you'd need the ClientToScreen or ScreenToClient function if the menu is popping up someplace far away from the cursor.

  16. #16
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by TupacShakur View Post
    But to preserve its full functionality, I need to duplicate its parameters within my function. I tried it, and I'm facing some trouble with the X and Y parameters - namely, their default values as optional arguments. So what I'm asking now: What values for X and Y sent to PopupMenu trigger its default behavior of using the cursor's position.

    P.S: GetCurPos fails to emulate the default X and Y coordinates used by PopupMenu in many situations, so I'm only looking for the values for X and Y that trigger PopupMenu's default behavior.
    Hmm... The PopupMenu's signature is:

    Code:
    Sub PopupMenu(Menu As object, [Flags], [X], [Y], [DefaultMenu])
    Flags, X, Y and DefaultMenu were all declared Optional ByRef ... As Variant.

    You're aware of the IsMissing function, right?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  17. #17

    Thread Starter
    Hyperactive Member TupacShakur's Avatar
    Join Date
    Mar 2002
    Location
    Da Land Of Da Heartless...
    Posts
    493

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    ^^Well, I wasn't aware of the IsMissing function, and that helped me achieve what I want, albeit at the expense of 8 select case conditions (8 is the combination of True or False returned by IsMissing, and X or Y or DefaultMenu that I need to check for in the wrapper function, hence 2^3 = 8).
    This works and is perfectly fine, but just for the sake of doing things right, is there some other way that I'm missing?
    "And Now I'm Lika Major Threat, Cause I Remind U Of The Things U Were Made To Forget!" - (2PAC)

    "Now They Label Me a Lunatic, Couldn't Care Less, Death or Success is What I Quest, Cause I'm Fearless!" - (2PAC)

    " There's a light at the end of every tunnel, just pray it's not a train!! "



    I am 100% addicted to Tupac. What about you?
    I am 24% addicted to Counterstrike. What about you?
    The #1 Tupac Fans Web Site | The Official Tupac Web Site

  18. #18
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Using TrackPopupMenu API to open menu designed with VB Menu Editor

    Quote Originally Posted by TupacShakur View Post
    ... but just for the sake of doing things right, is there some other way that I'm missing?
    Have you tried it like this?

    Code:
    Private Sub MyPopupMenu(ByRef Menu As Menu, Optional ByRef Flags As Variant, _
                                                Optional ByRef X As Variant, _
                                                Optional ByRef Y As Variant, _
                                                Optional ByRef DefaultMenu As Variant)
        PopupMenu Menu, Flags, X, Y, DefaultMenu
    End Sub
    When nothing is passed to any of that subroutine's optional Variant parameters, those skipped arguments will have their "missing" flag bit set. When those parameters are passed to the intrinsic PopupMenu method, it will assume that the arguments that have their "missing" flag bit set are really missing.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Tags for this Thread

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