Jump to content
  • Advertisement
Sign in to follow this  

Cursor is Always an Hourglass

This topic is 3966 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

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 );
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

// 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;

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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).

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!