Problem with PostThreadMessage with date time activex control (Windows XP  MFC application)

Posted on 2007-07-26
Last Modified: 2013-12-14

I'm getting a problem with a PostThreadMessage call within a MFC application.
The PostThreadMessage  receive handler is implemeneted in the application class(CWinAPP derived class) with ON_THREAD_MESSAGE handler as :
The PostThreadMessage is invoked from a different thread on a basis of certain events and this scenario works except one case:

The application is build in with a datetime activex control in a dialogbox within the same application. If I open this activex control at the same time, when the PostThreadMessage happens, the receive handler doesn't get executed. Also I have checked the return value of the

PostThreadMessage call and it returns without any error message. I guess the message is getting posted in the thread queue, for some reason it is not being consumed during the activex control runtime?

Appreciate any inputs on this...

Question by:pphari
    LVL 43

    Accepted Solution

    What is being passed - MFC objects are NOT thread safe.  You must passs a window handle instead (eg. with GetSafeHwnd() ).
    LVL 22

    Expert Comment

    >>PostThreadMessage call and it returns without any error message.

    For test purpose will you simply try calling the Sleep function after failure and call PostThreadMessage again, repeat until to check if PostThreadMessage succeeds ?

    However PostThreadMessage is not guaranteed to work if there are any UI components in the thread.
    if the thread has UI components and a MessageBox or menu is active or any other subordinate message loop the subordinate message loop will simply discard all thread messages. This is clearly stated in the documentation of PostThreadMessage. To communicate with the main GUI thread, you can use PostMessage . So otherwise use PostMessage to send a particular message to the handle of a window.

    LVL 22

    Assisted Solution

    Following KB article may be useful
    Q183116 : PRB: PostThreadMessage Messages Lost When Posted to UI Thread


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Title # Comments Views Activity
    sumDigits challenge 9 71
    format the code in java 6 60
    ShiftLeft challenge 21 50
    Specific format 21 105
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    I made this because I wanted to get e-mail with a attached csv file so I'd would be able to import user input into a MS Excel template, but I also wanted to register/save all inputs from each day in a file on the server. 1st - It creates a temp C…
    The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
    The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now