Link to home
Start Free TrialLog in
Avatar of pphari
pphari

asked on

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

Hello,

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 :
ON_THREAD_MESSAGE(WM_DSEXECEVENTHANDLER, ExecuteEventHandler)
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...

Thanks
Hari
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>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.

-MAHESH
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial