CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: sendmessage

  1. #1
    Join Date
    Aug 2019
    Posts
    72

    sendmessage

    hi,

    this works as it launches Child Dialog.
    Code:
    sendmessage(hParentChildBtn, BN_CLICK,0,0)
    however, this does not work as it does not close the child dialog.
    Code:
    sendmessage(hChildOKBtn, BN_CLICK,0,0)
    using postmessage on both works.
    what is reason?.

  2. #2
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: sendmessage

    It's been too long since I've programmed Win32 in earnest. However, the difference between SendMessage() and PostMessage() is that SendMessage() only returns when the specified window procedure has processed the message whereas with PostMessage() the message is placed in the message queue for the specified window and then returns without waiting for the message to be processed.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    Aug 2019
    Posts
    72

    Re: sendmessage

    if I make one of them postmessage, the sendmessage on other would work. Or, if I make both postmessage, then they each work too.
    If I keep both sendmessage, then 2nd sendmessage waits for ever.

  4. #4
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: sendmessage

    As I said, probably because the SendMessage is waiting for completion which doesn't happen. PostMessage doesn't wait for completion.

    There might also be issues with the code called when a message is received. Is this code waiting for a message to be received (maybe indirectly) which isn't because the message was via SendMessage() rather than PostMessage()?
    Last edited by 2kaud; March 3rd, 2023 at 04:39 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: sendmessage

    First of all, there's no BN_CLICK message identifier defined in Windows headers. Unless you are defined your own, you've probable referred to BN_CLICKED, which also is not a message identifier, but a notification code usually sent by the Windows framework to the parent window, via WM_COMMAND message, as a result of a user action.

    Only in rare cases you have to explicitly send such notifications in your own code. Let' say you have to make a kind of UI automation and simulate user actions (click on a button, for example).
    Here is how to do:
    Code:
        // wParam contains control notification code in high word
        // and the control identifier in the low word
        WPARAM wParam = MAKEWPARAM(IDOK, BN_CLICKED);
        // lParam contains the control window handle
        // in most cases (as for example in MFC) this is ignored
        LPARAM lParam = (LPARAM)::GetDlgItem(hWndParent, IDOK);
        ::SendMessage(hWndParent, WM_COMMAND, wParam, wParam);
    No matter if you call SendMessage or PostMessage.

    See also:
    Last edited by ovidiucucu; March 7th, 2023 at 03:01 AM.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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