PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] why am i unable to create a successful message loop with PeekMessage()?

 July 12, 2022     loops, message, winapi     No comments   

Issue

My guess it's somehow receiving a WM_QUIT message, because that is what the while loop revolves around ( which according to the proc function happens whenever a WM_DESTROY message is processed)

The window automatically closes whenever i use PeekMessage instead of GetMessage , Im using PeekMessage in order to run the loop at maximum speed

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
if(!CreateMainWindow(hinstance, nCmdShow))
   return false;
//this works
while (GetMessage(&msg, (HWND) NULL, 0 , 0))
{
    TranslateMessage(&msg);
    DispatchMessage(&msg);
}
return (int) msg.wParam;
    UNREFERENCED_PARAMETER(lpCmdLine);
}    

//this automatically closes the window
int done = 0;
while (!done)
{
    if (PeekMessage (&msg, NULL, 0 ,0, PM_REMOVE))
    {

        if (msg.message = WM_QUIT)
            done = 1;
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
}
return msg.wParam;
    UNREFERENCED_PARAMETER(lpCmdLine);

here's the simple WinProc function

LRESULT CALLBACK WinProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM   
lParam)
{
switch( msg)
{
      Case WM_DESTROY: 
      PostQuitMessage(0);
      return 0;
}
return DefWindowProc ( hWnd, msg, wParam, lParam);
}

Solution

You are assigning WM_QUIT to msg.message instead of comparing it.



Answered By - Ton Plooij
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing