Link to home
Start Free TrialLog in
Avatar of mikehui
mikehui

asked on

PostThreadMessage and PeekMessage

I've written the code using VC++5.0 in WinNT as follow:

...
void main() {
...
   ft = (HANDLE) _beginthreadex(NULL, sz, POne, 0, 0,(unsigned int*) &dft);
   r = PostThreadMessage(dft, WM_NULL, 0,0);
   Sleep(5000);
...
}

void POne() {
...
   MG msg;
   for(;;) {
      if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
      (
         printf("Message Received!\n");
         break;
      }
      WaitMessage();
   }
...
}

In running the above code, the 'Message Received' does not prompt. But it work on Win95 successfully. I've no idea about this problem. Does any suggestion or advice for me?
Thank you for your attention.

Regards,
Michael

Avatar of mikehui
mikehui

ASKER

Edited text of question.
What messages should it be geting?  probably none.   You might try using AttachThreadInput() so that it gets some of the input messages that would be going to the main thread.

What is it that you are trying to do?
ASKER CERTIFIED SOLUTION
Avatar of PinTail
PinTail
Flag of United Kingdom of Great Britain and Northern Ireland 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
Avatar of mikehui

ASKER

Does any time interval required in a sequence of  PostThreadMessage function call?
Do you mean 'Is there a time interval required between calls to PostThreadMessage'.

No, the Threads Message Queue will continue to accept messages as fast as you can post them, however, you should check the return from PostThreadMessage, since it can sometimes fail - for reasons unclear -