Skip to main content
gamedev.net
🔒 Locked

[C++/winapi] unresponsive window

Started by Trillian 3 replies 500+ views
Original Post
Trillian
Trillian
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)
Smit
Smit
Do you call DefWindowProc( ) in your Window Procedure function for messages that you arn't handling?
Trillian
Trillian
I've just step-by-stepped my program and yes, some messages go to the DefWindowProc
Trillian
Trillian
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.
Trillian
Trillian
[solved] by playing around with settings

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.