• Advertisement
Sign in to follow this  

[C++/winapi] unresponsive window

This topic is 4251 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! Up to today I thought I mastered basic window creation with winapi but it looks like I was wrong. I'm currently building a library to simplify the use of windows. Using it, I can have my main loop code as easy as this :
// Sample of simplified code
while(_Running)
{
	if(_Window.HandleMessages()) continue;
	_Timer.FrameUpdate();
	if(!_Window.IsActive()) continue;

	Update(_Timer.GetTimeDelta());
	Render();
}

// Implementation of CWindow::HandleMessages()
bool CWindow::HandleMessages()
{
	MSG msg;

	if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
		return true;
	}

	return false; // No messages were treaten
}



Now I'm having a window but it is unresponsive and I have to close it using CTRL-ALT-DELETE. Do I need to do more than what I currently do for my window to be responsive? Thanks for your help! (If I didn't post enough code, please tell me)

Share this post


Link to post
Share on other sites
Advertisement
Do you call DefWindowProc( ) in your Window Procedure function for messages that you arn't handling?

Share this post


Link to post
Share on other sites
I've just step-by-stepped my program and yes, some messages go to the DefWindowProc

Share this post


Link to post
Share on other sites
Here's more code : the static window procedure and the member one :


LRESULT FEWW::CWindow::StaticProcedure(HWND hwnd,UINT msg, WPARAM wparam, LPARAM lparam)
{
if(!s_ProcessMessages) return DefWindowProc(hwnd, msg, wparam, lparam);

// Get CWindow object
CWindow * win = (CWindow*)GetWindowLong(hwnd, GWL_USERDATA);

// If we cannot find the CWindow object, use DefWindowProc
if(win == NULL) return DefWindowProc(hwnd, msg, wparam, lparam);
// We've found the CWindow object, send him the message
else return win->Procedure(hwnd, msg, wparam, lparam);
}

LRESULT FEWW::CWindow::Procedure(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if( MessageToListener(*this, hwnd, msg, wparam, lparam ) ) return 0;
else return DefWindowProc(hwnd,msg,wparam,lparam);
}



I've implemented a "listener" abstract class for windows messages. MessageToListener takes a window message as an argument and calls appropriate listener function depending on the window message. If it doesn't treat the message, it return false.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement