CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Location
    UK (South)
    Posts
    93

    CPU hungry functions & the message pump. Problem with WM_CLOSE.

    In my application I some fucntions that wait for data from a data aquistion card. They therefore block the thread. In order to aleviate the problem I have used a message pump.


    MSG message;
    while(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
    {
    ::TranslateMessage(&message);
    :ispatchMessage(&message);
    }



    However I have found a strange thing occurs if I attempt to close the application whilst it is in this state. The Window for the App disappears as if the application has exited but the application continues to fuction continuing merrly to make more measurements etc. Is there anyway that I can ensure the shutdown of th app on WM_CLOSE?

    Simon Pettman.


  2. #2
    Join Date
    Apr 2000
    Location
    San Francisco, California, USA
    Posts
    4,467

    Re: CPU hungry functions & the message pump. Problem with WM_CLOSE.

    You should check for WM_QUIT message in the loop:


    MSG message;
    while (::PeekMessage(&message,NULL,0,0,PM_REMOVE))
    {
    if (message.message == WM_QUIT)
    {
    // repost WM_QUIT message so the main message loop will see it
    // and terminate properly
    PostQuitMessage(message.wParam);

    // do necessary cleanup and return
    return;
    }

    ::TranslateMessage(&message);
    :ispatchMessage(&message);
    }







    Russian Software Development Network -- http://www.rsdn.ru

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured