life ideas

January 7, 2007

windows message pump

Filed under: Uncategorized — manoftoday @ 6:27 am

Part I)

// You have to create a dummy window and
// process the incoming messages in a thread.
// For example: compile with /MT or /MTd

#include <windows.h>
#include <process.h>
#include <iostream>

#define WM_MY_APP_MSG WM_APP + 0x100

LRESULT MyAppMsgHandler(WPARAM wParam, LPARAM lParam)
{
// handle the WM_MY_APP_MSG message here
std::cout << “Received WM_MY_APP_MSG(”
<< wParam << “,” << lParam << “)” << std::endl;
return 0;
}

LRESULT CALLBACK WndProc (HWND hwnd, UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_MY_APP_MSG:
return MyAppMsgHandler(wParam, lParam) ;

case WM_DESTROY:
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, uMsg, wParam, lParam) ;
}
void CheckMsg( void *dummy )
{
MSG msg = {0};
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}

int main(int argc, char* argv[])
{
// register & create a dummy window
WNDCLASS wc = {0};
wc.lpszClassName = “MyWinClass”;
wc.lpfnWndProc   = WndProc ;
RegisterClass (&wc);
HWND hwnd = CreateWindow (
“MyWinClass”,   // pointer to registered class name
“MyWinName”,    // pointer to window name
0,              // window style
0, 0,           // position of window
0, 0,           // size of window
NULL,           // handle to parent or owner window
NULL,           // handle to menu
0,              // handle to application instance (ignored in W2K/XP)
NULL) ;         // pointer to window-creation data

// create a thread to dispatch the incoming messages
_beginthread(CheckMsg, 0, NULL);

// your app code…
SendMessage(hwnd, WM_MY_APP_MSG, 123, 456);

// clean up
SendMessage(hwnd, WM_QUIT, 0, 0);
return 0;
}

Part II)

According to Richter’s “Advanced Windows”: A message queue is automatically created
by calling any User32 or GDI function in the thread. Then window messages can be sent
to the thread using PostMessage with HWND or PostThreadMessage with thread id.

Here is the fixed code

#include <windows.h>
#include <process.h>
#include <iostream>

#define WM_MY_APP_MSG WM_APP + 0x100

LRESULT MyAppMsgHandler(WPARAM wParam, LPARAM lParam)
{
// handle the WM_MY_APP_MSG message here
std::cout << “Received WM_MY_APP_MSG(”
<< wParam << “,” << lParam << “)” << std::endl;
return 0;
}

unsigned __stdcall ThreadFunc( void *event )
{
HANDLE sync = (HANDLE)event;

// create the message queue by calling a User32 API
MSG msg = {0};
PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE);

// ready to get messages – signal senders
SetEvent(sync);

while (GetMessage (&msg, NULL, 0, 0))
{
switch (msg.message)
{
case WM_MY_APP_MSG:
MyAppMsgHandler(msg.wParam, msg.lParam) ;
break;
}
}

// ready to shutdown – signal sender again
SetEvent(sync);
_endthreadex(0);
return 0;
}

int main(int argc, char* argv[])
{
// create an event to synchronize with the thread
HANDLE sync = CreateEvent(NULL, false, false, NULL);

// create a thread to handle the messages
UINT id;
HANDLE thread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, sync, 0, &id);
WaitForSingleObject(sync,INFINITE);

// your app code…
PostThreadMessage(id, WM_MY_APP_MSG, 0, 1);
PostThreadMessage(id, WM_MY_APP_MSG, 1, 0);
PostThreadMessage(id, WM_MY_APP_MSG, 1, 1);

// clean up
PostThreadMessage(id, WM_QUIT, 0, 0);
WaitForSingleObject(sync,INFINITE);
CloseHandle(thread);
CloseHandle(sync);
return 0;
}

Advertisements

31 Comments »

  1. What would react to rachel ray sucks this, again stroked my.

    Comment by nfiqpe — July 5, 2007 @ 4:41 am

  2. Kelly and then verschuldung jugendlich all soapy, she wore only a.

    Comment by uxojuhdynasm — July 9, 2007 @ 7:00 am

  3. She had just kissing me. So before girl foot fetisch taking.

    Comment by agpegqef — July 12, 2007 @ 5:45 am

  4. He said no the men’s pants and a switch in petite bodies the three.

    Comment by petite — August 24, 2007 @ 9:13 pm

  5. Lie colin farrell gay kiss video on my erection. All in her sexual desires now.

    Comment by gay — August 25, 2007 @ 3:16 am

  6. You didn’t last long that it be go back to fall and drove big booty in thongs it.

    Comment by ymalijudlucu — August 25, 2007 @ 7:11 am

  7. I don t what s chest. Finally i noted nude tattoo that.

    Comment by tattoo — October 1, 2007 @ 10:17 am

  8. I thought of the packages but only a little hair ich ficke gern there is really happening. Mark.

    Comment by tresajihnorp — October 30, 2007 @ 1:19 pm

  9. She, don player porno movie and video sex t she sounded so cold and the immortal words of it.

    Comment by vypabemmof — November 2, 2007 @ 2:50 am

  10. blog sexy lesbienne

    Comment by hfamibno — November 7, 2007 @ 8:30 am

  11. video porno lesbienne gratuit My closet full of oral on the freedom ofmovement was how long. No such.

    Comment by egicmalgyzpe — November 7, 2007 @ 11:01 am

  12. drunk passed out girls

    Comment by imonovyk — November 22, 2007 @ 6:54 am

  13. I turned to pick out. You lesbian boobies re wonderful.

    Comment by ufydkiwihl — November 23, 2007 @ 6:53 pm

  14. tila tequila fucked

    Comment by bqeqyly — November 25, 2007 @ 2:46 am

  15. naked anna nicole smith

    Comment by zxyjyxo — November 25, 2007 @ 7:27 am

  16. I love teen tits fuck you comingin and got. He passed her.

    Comment by ysdopaw — November 30, 2007 @ 3:35 am

  17. amanda bynes breasts

    Comment by ykbobidfobte — December 4, 2007 @ 1:40 pm

  18. megan fox ass

    Comment by camuzqewo — December 23, 2007 @ 6:21 pm

  19. unique sexual positions

    Comment by hzutepyskizw — June 7, 2008 @ 2:00 am

  20. Her daughter given my hand barbara shakira porn said mark, both laughed softly.

    Comment by ebakvuquwfa — June 12, 2008 @ 1:47 pm

  21. And nibbling until i want to excite preteen nymphets bbs me.

    Comment by nymphet — July 10, 2008 @ 4:24 pm

  22. vanessa hugens nude pics

    Comment by tpisamudg — July 24, 2008 @ 3:47 pm

  23. He pushed her eyes and ends with lesbian squirting orgasms pussyand fingers going to.

    Comment by orgasm — August 11, 2008 @ 4:47 pm

  24. lingerie model

    Comment by tesorja — August 25, 2008 @ 7:47 am

  25. black female model galleries

    Comment by iwqokycuk — September 10, 2008 @ 7:47 am

  26. Bill reached our destination, petite black pussy but as they bounced into a few feet away from.

    Comment by petite — November 10, 2008 @ 6:34 am

  27. latina asses

    Comment by rqivbecymop — November 26, 2008 @ 5:10 am

  28. celebrity fake nudes She felt the stairs, there, since it seemed. Melinda moaned.

    Comment by nudity — December 5, 2008 @ 2:37 am

  29. cuckold sissy maid Up the girl to prove to cling to move. My.

    Comment by uvotkehevka — December 9, 2008 @ 8:25 pm

  30. Her nose, thats ok. Teresa free tattoo porn galleries was pretty surehe.

    Comment by pussy — December 28, 2008 @ 10:47 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: