CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2001
    Posts
    10

    Activate menu option with API call

    Hi All

    I added a menu to my MDIForm with VB. now I scanning the menu by making API calls and getting each menu item.
    I have 2 Q's:

    1) how do I simulate mouse click on some item using API call(SendMessage?)
    2) If for this item there is code in the click event within the
    form, will it be executed?

    TIA
    Yair


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Activate menu option with API call

    You need to get the menu item info:


    private Type MenuItemInfo
    cbSize as Long
    fMask as Long
    fType as Long
    fState as Long
    wID as Long
    hSubMenu as Long
    hbmpChecked as Long
    hbmpUnchecked as Long
    dwItemData as Long
    dwTypeData as Long
    cch as Long
    End Type

    private Declare Sub CopyMemoryMenuItemInfo Lib "kernel32" Alias "RtlMoveMemory" (Destination as MenuItemInfo, byval Source as Long, byval Length as Long)

    private Declare Function GetMenuItemInfoApi Lib "user32" Alias "GetMenuItemInfoA" (byval hMenu as Long, byval un as Long, byval b as Boolean, lpMenuItemInfo as MenuItemInfo) as Long




    Use:


    public Function GetMenuItemInfo(byval hMenu as Long, byval un as Long, byval b as Boolean) as MenuItemInfo

    Dim lRet as Long
    Dim miiThis as MenuItemInfo

    lRet = GetMenuItemInfoApi(hMenu, un, b, miiThis)

    GetMenuItemInfo = miiThis


    End Function




    And send this to the window as the wParam of a WM_COMMAND message.

    And yes, the VB event will be fired.

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Feb 2001
    Posts
    10

    Re: Activate menu option with API call

    Hi Duncan

    thnx for the light speed reply.

    Sorry but I still missing a point,
    miiThis is of a structure type yet wParam declared as long
    so VB screams "Type mismatch"

    Yair


  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Activate menu option with API call

    Oops - forgot the vital bit.
    The menu command identifier you need to pass in the SendMessage() api is

    Dim lRet as Long

    lRet = SendMessageByNum(me.Hwnd, WM_COMMAND, miiThis.wId, 0&)




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  5. #5
    Join Date
    Feb 2001
    Posts
    10

    Re: Activate menu option with API call

    Hi Duncan

    This is what I tried in the first place but the VB event wasn't
    fired niether then nor now.

    Thank's again

    Regards,
    Yair


  6. #6
    Join Date
    Feb 2001
    Posts
    10

    Re: Activate menu option with API call

    I have found the missing link.

    if one want the VB event to be fired he should call to
    PostMessage instead of SendMessage

    Regards,
    Yair


  7. #7
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Activate menu option with API call

    Of course - Doh!

    Sendmessage doesn't work if called from the same thread that the emssage is intended for. I had copied my code out of a project I wrote to manipulate word's windows so it worked there.

    Top fix, by the way.

    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured