Sign in to follow this  

Problem with cursor (C++, win32)

This topic is 3493 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, I have been into win32 the last few days, and I made my first window with the help of other members. Now I have this problem. When I run, it runs fine, but the cursor doesn't change (I get the hourglass). I was told I had that because I hadn't filled the member for the class's cursor. So I did, and still, the same.. any suggestions?
#include <windows.h>
#include <tchar.h>

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE prevInstace, LPSTR lpCmdLine, int nShowCmd )
{
	WNDCLASS myWin = {};

	myWin.hbrBackground = reinterpret_cast< HBRUSH >(COLOR_WINDOW);
	myWin.hCursor = LoadCursor( hInstance, IDC_HAND );
	myWin.lpszClassName = _T("myClass");
	myWin.lpfnWndProc = WndProc;
	myWin.hInstance = hInstance;
	myWin.lpszClassName = _T("myWin"); //class name

	RegisterClass( &myWin );

	HWND hWndMain = CreateWindow( _T("myWin"),
								_T( "my 1st window"),
								WS_OVERLAPPEDWINDOW,
								CW_USEDEFAULT,
								CW_USEDEFAULT,
								CW_USEDEFAULT,
								CW_USEDEFAULT,
								NULL,
								NULL,
								hInstance,
								NULL);

	MSG msg;
	BOOL bRet;

	ShowWindow( hWndMain, SW_SHOW );
	UpdateWindow( hWndMain );

	while( bRet = GetMessage( &msg, NULL, 0, 0 ) != 0 )
	{
		if( bRet == -1 )
			return -1;
		else
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}
	}

	return 0;
}

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

	default:
      return( DefWindowProc( hWnd, uMsg, wParam, lParam ));
	}
}

Share this post


Link to post
Share on other sites
Well this is just a guess but from my experince iv noticed that alot of the newly created windows just as the program starts up does that.

i think you got two options to try the first is to call invalidaterect()
just msdn.com search it an it will explain itself the other is to call ShowCursor() to set the cursor to not be show then to show it and it might refresh it out of the hourglass basicly from what i can tell its just the system hanging up because the window has not refreshed.

Regards Jouei.

Remmeber to use the rateing system where applicable pepole appreacte it.

Share this post


Link to post
Share on other sites
What DarkLighter said.

Plus, unrelated to the cursor problem; move the return DefWindowProc OUTSIDE the switch. Do not place it in the default case.

That will save you some trouble later on once you start to process more events. There is no single default return value for all Windows messages. And there will be some events that need handling by you and DefWindowProc.

Share this post


Link to post
Share on other sites

This topic is 3493 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this