VC ++ win32 API programming: how to change mouse cursor
I am trying to change the mouse cursor and write the code below, but it doesn't work. Seems like IDC_CURSOR_WHITE
it should be put in rc. I have tried and failed. Finally I came here to ask for your guidance. Help! Thank.
IDC_CURSOR_WHITE IDC_CURSOR_BLACK not
hWhiteCursor = ::LoadCursor(hInstance, (LPCTSTR)IDC_CURSOR_WHITE);
hBlackCursor = ::LoadCursor(hInstance, (LPCTSTR)IDC_CURSOR_BLACK);
case WM_LBUTTONDOWN:
if ((type = ++type % 2) == 0)
SetCursor(hWhiteCursor);
else
SetCursor(hBlackCursor);
break;
case WM_SETCURSOR
return 0;
PS: Code of rc. And the mouse pointer error is undefined.
// Microsoft Visual C++ generated resource script.
//
#include "resource."
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE
BEGIN
"resource.\0"
END
3 TEXTINCLUDE
BEGIN
"\r\0"
END
2 TEXTINCLUDE
BEGIN
"#include ""afxres.h""\r\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Cursor
//
IDC_CURSOR_WHITE CURSOR "cursor1.cur"
IDC_CURSOR_BLACK CURSOR "cursor2.cur"
#endif // resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
source to share
This is what I do when I need to use resources. First, I create a resource.h file and define the resource name with a unique integer. Include the resource.h file in your .rc file and then identify the actual resource. So in your case the files should be as follows
resource.h
#define IDC_BLACK_CURSOR 1001
resource.rc
#include "resource.h"
......
IDC_BLACK_CURSOR CURSOR "cursor1.cur"
Now, to use a resource in a specific file, I just include the resource.h file and use the specific cursor. So, again in your case, if you want to use a cursor in the test.cpp file.
test.cpp
#include "resource.h"
....
hBlackCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_BLACK_CURSOR));
.....
Hope this helps. For more information, MSDN is always your friend.
http://msdn.microsoft.com/en-us/library/ms648380%28VS.85%29.aspx
source to share