How to use PeekMessage with wxWidgets?

Started by
3 comments, last by Aldacron 10 years, 6 months ago

I can't find a solution anywhere... Currently i have the following:


if(!wxEntryStart(hInstance, hPrevInstance, lpCmdLine, nCmdShow ))
	{
		return -1;
	}

	wxTheApp->CallOnInit();

	MSG msg;

	while (true)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT) break;
			
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	wxEntryCleanup();

But if i press the close button, nothing happens...

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Advertisement

Are you sure its compatible with the framework if you directly use the WinAPI and you dont need to use some wx function?

From the look of it the window procedure seems to not call DestroyWindow on WM_CLOSE or not call PostQuitMessage on WM_DESTROY.

Are you sure its compatible with the framework if you directly use the WinAPI and you dont need to use some wx function?

From the look of it the window procedure seems to not call DestroyWindow on WM_CLOSE or not call PostQuitMessage on WM_DESTROY.

Yes that's why i'm asking. There may be a function but i can't find it...

"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

Isn't this break breaking out of the if statement? If so, it'll end up inside the while (true), so the loop will never end.

Long time since I last used this keyword, several years to be precise.

@edit: forget about it, break should actually jump right out of the while loop. Just tested it.

Searching on the internet, found this, and it looks like that if you pass the message on, windows should do it. But in your code you're breaking out of the loop before dispatching the message. Maybe moving the IF to after the translate and dispatch functions can do it. Still, I don't have wxWidget installed so I can't test it myself, sorry.

When working with GUI frameworks like wxWidgets, you aren't supposed to be tapping into the OS event pump. I assume you are doing this because you want to get some sort of render loop going. This wxWidgets wiki page should help in that case.

This topic is closed to new replies.

Advertisement