CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108

    how to SendMessage to menu?

    Hi all!

    I don know how to send a message to menu where the menu is locate outside of my application.. It is totally out of my control... So I decide to use SendMessage() to control that menu...

    So I am having trouble in the syntax, what should I pass in for the 3rd and 4th parameter? I have done the SendMessage() in this way:

    Code:
    SendMessage(hWnd, WM_COMMAND, x, y)
    Am I doing the right way? Please inform me if the above code is not correct..

    THank YOu @!

  2. #2
    Join Date
    Feb 2002
    Posts
    3,788

    Re: how to SendMessage to menu?

    Originally posted by huahsin68
    Hi all!

    I don know how to send a message to menu where the menu is locate outside of my application.. It is totally out of my control... So I decide to use SendMessage() to control that menu...

    So I am having trouble in the syntax, what should I pass in for the 3rd and 4th parameter? I have done the SendMessage() in this way:

    Code:
    SendMessage(hWnd, WM_COMMAND, x, y)
    Am I doing the right way? Please inform me if the above code is not correct..

    THank YOu @!
    see attached. 2 solution are explained there:
    1. using PostMessage
    2. using EnableMenuItem
    Attached Files Attached Files

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396
    It is not clear, what you want to do with this menu which "is locate outside of your application"....
    Please, be more precisely!

  4. #4
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    Thanks to Alin!!

    Your code really make me feel suprise... THank YOu!! But why don you use SendMessage()? Hmm~ Basically I want to select or click on the menu, not make it gray... And have a question, your code is to make the "NEW" menu become gray, and then when I run the exe, it make the "NEW" and "OPEN" menu become gray? Can you explain why this happen? THank YOu @!

    To VictorN:

    Hmm~ For example here, I have a VB program with menu, and then I have a C++ program with button... And from C++ program, I click on the C++ program's button, it will then hit on the VB's menu... just that the way... Can I do that using SendMessage()?

    Or do you think Alin's idea is good? I mean he is using PostMessage() instead of SendMessage()... Which 1 better?

    THank YOu @!

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396
    do you think Alin's idea is good? I mean he is using PostMessage() instead of SendMessage()... Which 1 better?
    It is very dangerous to SendMessage to other application/other thread: you could get into a serious deadlock situation! Your app will wait for the reply from another one and nobody knows how long it can last

  6. #6
    Join Date
    Feb 2002
    Posts
    3,788
    Your code really make me feel suprise... THank YOu!! But why don you use SendMessage()? Hmm~ Basically I want to select or click on the menu, not make it gray... And have a question, your code is to make the "NEW" menu become gray, and then when I run the exe, it make the "NEW" and "OPEN" menu become gray? Can you explain why this happen? THank YOu @!
    as i alreadytold you i provided you with 2 different methods to gray/check a menu item. you're the on to decide which one fits you best.

    About ::SendMessage, what VictorN said makes perfect sense.

  7. #7
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    as i alreadytold you i provided you with 2 different methods to gray/check a menu item. you're the on to decide which one fits you best.
    yup! I just notice yesterday... sorry..
    It is very dangerous to SendMessage to other application/other thread: you could get into a serious deadlock situation! Your app will wait for the reply from another one and nobody knows how long it can last
    OIC ... now I understand... Hmmm~ Does this the only case that not suitable for SendMessage()?

    And then this haven solve my problem, how to make it click on the menu..?

    THank YOu @!

  8. #8
    Join Date
    Dec 2002
    Posts
    214
    to avoid deadlock you can use SendMessageTimeout()

  9. #9
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    But how to make it click on the menu?

    Or may be I should said that how to click on the menu in programming way?

    THank YOu @!

  10. #10
    Join Date
    May 2004
    Location
    Malaysia
    Posts
    108
    I think I solve the problem... I do like this:

    HWND g_hWnd=NULL;
    int nMenuID;

    EnumWindows(EnumBFEWindows, MYWINDOW); // this will return the my window's handle to g_hWnd..

    hMenu = GetMenu(g_hWnd); // from the hWnd I get the menu handle...
    nMenuID = GetMenuItemID(hMenu, 6); // get the menu id from the menu handle.. 6 is the position of the menu which I use to click on...

    SendMessage(hwndWinView, WM_COMMAND, nMenuID, NULL); // hit the menu...

    Thats all I done...

    But how can I SendMessage() to hit the button?

    THank YOu @!
    Last edited by huahsin68; June 24th, 2004 at 10:30 PM.

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