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

Thread: PostMessage() sends the message twice?

  1. #1
    Join Date
    Nov 2001
    Posts
    244

    PostMessage() sends the message twice?

    I use PostMessage() in OnInitDialog(), but for some reason, the Message is sent twice


    I tried different WM_ values as well, for example WM_USER+5, WM_USER+10, WM_USER+100 (thinking I was using the same WM_ value as another message).


    I have confirmed that I am only calling PostMessage once using a MessageBox directly before the PostMessage line.

    I put a messagebox in PreTranslateMessage (when the message = WM_USER+5 ), and it pops up twice!

    I even tried calling PostMessage from another function (via a CButton), it also sends the message twice. So its not specifically an OnInitDialog glitch.

    Any ideas?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,209

    Re: PostMessage() sends the message twice?

    PostMessage itself won't send the message twice, but there are (at least) two possibilities:

    1) Your WM_USER messages are being used by the system
    2) Your code is calling PostMessage multiple times (put some TRACE messages in there to determine if this is the case).

  3. #3
    Join Date
    Nov 2001
    Posts
    244

    Re: PostMessage() sends the message twice?

    1) I tried many different WM_USER+x messages, all of them send twice
    2) I checked that PostMessage is only being called once. I put a messagebox just before the PostMessage function, only one messagebox is displayed.

    I've been thinking, I have an MFC DLL file loaded during runtime (it has its own CDialog), do you think that is receiving the PostMessage command as well as the main app (MFC CDialog)?
    But why would PostMessage send it to other threads/dll's if the hWnd parameter is set to the main dialog (this)?

  4. #4
    Join Date
    Nov 2001
    Posts
    244

    Re: PostMessage() sends the message twice?

    ok I'm pretty sure its not the DLL posting the message. I loaded additional DLL's but it still posts the message twice. If it was the DLL's, wouldnt the message go to each DLL, and have the message posted *more* than twice?

    Has anyone else seen this problem?

    What functions could I override to trace the message? (besides pretranslatemessage)

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,209

    Re: PostMessage() sends the message twice?

    You'll have to track this down, but it is important to understand that PostMessage doesn't send a message twice so the issue is in your code (or the dll code).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)