Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / Peek/Translate/Dispatch in a thread... Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

February 24, 2005, 10:23 AM


So i have just tried to pull out my message [Peek/Translate/Dispatch] part from a thread that is used for rendering the my ddraw surface.

And i kind of ran into a minor problem, weeee.. lucky me. =P

I want to put my Peek/Translate/Dispatch part in a separate thread and and be able to adjust the responsiveness of the program (actually give the ddraw thread more fps) but its not working quite as i wanted.

Is there a fundamental problem with doing this?

Because when pull it out to another thread my "PeekMessage" gives me a 0 (null) reply. Saying that there are no messages in que. So all of this results in my window and ddrawsurface becomes nonresponsive.

These are the only windows specific functions that i am calling in the ddraw thread routine:


The source for my message dispatch thread is:

  2. void eventThread(int *a)
  3. {
  4.         HWND wnd = getmyWindow();
  5.         MSG message;
  7.         while(1)
  8.         {
  9.                 Sleep(*a);
  10.                 while (PeekMessage(&message,wnd,0,0,PM_REMOVE))
  11.                 {
  12.                         TranslateMessage(&message);
  13.                         DispatchMessage(&message);
  14.                 }
  15.         }
  16. }

So can anyone help me out here?



February 24, 2005, 01:55 PM

If you really want to do this, you should keep the PeekMessage stuff in your main thread and put the rendering in the secondary thread.


February 24, 2005, 03:43 PM

Well that does not help me at all... The problem occur no matter
where i put my peek stuff, except when its in the ddraw thread.

I'll go with my intended design for now
but thanks anyway.



February 24, 2005, 05:00 PM

Windows are associated with the thread that they are created in.
You cannot run a message pump in another thread for them, it has to be in the thread that created them.


February 25, 2005, 02:23 AM

I had kinda same question some threads earlier...

A tip that was given me, to use NULL as second parameter
in the PeekMessage function...


Hope it helps


February 25, 2005, 03:20 AM

No it was actually {FluffysWhole} that was right.
I checked msdn and as he said. The peek/dispatch loop
has to be located inside the same process/thread as


This thread contains 6 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.