Cursor is Always an Hourglass

Started by
8 comments, last by Darklighter 16 years, 9 months ago
I'm working on a game framework with DirectX/Win32. One of the main classes, "Game", is similiar to the XNA "Game" class. You derive from it and override the loop methods. I made a test program to test it and it works just fine. The only problem is, the cursor is always an hourglass as long as the cursor is within the window. It seems to be recieving and using WndProc to process messages just fine. It responds to closing the window and Alt-F4. Wouldn't the hourglass mean it wasn't? Anyways, I'll give you the loop code:

// Start the game loop.
while (m_running)
{
	// Read Windows messages.
	if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
	{
		// Check for quit message.
		if (msg.message == WM_QUIT) {
			value = 0;
			m_running = false;
		}

		// Decode and pass message.
		TranslateMessage(&msg);
		DispatchMessage(&msg);

	} else {

		// Update the game.
		Update();

		// Draw the game.
		Draw();
	}
}

And the WndProc code:

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

    return DefWindowProc( hWnd, msg, wParam, lParam );
}

Advertisement
Change the 'if-else' statement to a 'while' loop so that Windows can process all messages instead of just one per loop.
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))

Then just update and draw after the loop.

Good Luck.
0xa0000000
Hmm... I'm still getting that same problem, even with the while loop.

All the examples I saw for this type of loop used that if-else statement, anyways.
What do your RegisterClassEx() and CreateWindows() calls look like?
0xa0000000
// Create the window class structure.	WNDCLASSEX wc;	ZeroMemory(&wc, sizeof(WNDCLASSEX));	// Fill the structure with info.	wc.cbClsExtra = 0;	wc.cbSize = sizeof(WNDCLASSEX);	wc.cbWndExtra = 0;	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);	wc.hCursor = LoadCursor(hInstance, IDC_ARROW);	wc.hIcon = NULL;	wc.hIconSm = NULL;	wc.hInstance = hInstance;	wc.lpfnWndProc = (WNDPROC)wndProc;	wc.lpszClassName = "SLICK Window";	wc.lpszMenuName = NULL;	wc.style = CS_HREDRAW | CS_VREDRAW;	// Register the class with Windows.	if (RegisterClassEx(&wc) == 0)		return false;	// Fullscreen or not?	DWORD style = WS_OVERLAPPEDWINDOW;	if (fullscreen)		style = WS_EX_TOPMOST | WS_VISIBLE | WS_POPUP;	// Create a new window.	m_window = CreateWindow(		"SLICK Window",		title,		style,		CW_USEDEFAULT,		CW_USEDEFAULT,		width,		height,		NULL,		NULL,		hInstance,		NULL);	// Check for window creation.	if (m_window == NULL)		return false;	// Show the window.	ShowWindow(m_window, SW_SHOW);	UpdateWindow(m_window);	// Successful registration.	return true;
LoadCursor() shouldn't be taking an HINSTANCE as its first parameter when loading standard Windows cursors. Pass in NULL instead.
Did you set your WNDCLASS wc.hCursor = LoadCursor(NULL, IDC_ARROW)
??
-durfy
The code all looks fine to me. [EDIT-What Darklighter found could be the problem] Are you using any WinAPI calls in the game code that might be interfering with the message loop?

Gamedev has some great articles on this stuff. You might want to check them out just as reference.

Creating a Win32 Window Wrapper Class

Getting Rid of the Windows Message Pump
& Solving the ALT-TAB Problem


Setting up a window

Good Luck!
0xa0000000
Wow, that was it! What Darklighter said! I guess I just assumed I should pass that hInstance in, because it was asking for one. Thanks so much!

Just for my own knowledge, why would doing that cause the cursor to change?
Quote:Original post by Uphoreum
Just for my own knowledge, why would doing that cause the cursor to change?


Because Microsoft says so. [smile]

LoadCursor() returns NULL if you're trying to load a predefined system cursor using an HINSTANCE. The resulting HCURSOR in the WNDCLASSEX structure is not valid, so the application ends up using the last loaded cursor (in this case, the hourglass from when the application was starting up).

This topic is closed to new replies.

Advertisement