开发者

VC++ win32 API programming :how to change mouse cursor

开发者 https://www.devze.com 2022-12-08 04:22 出处:网络
I am trying to change the mouse cursor and write the code below but doesn\'t work. It seems IDC_CURSOR_WHITE should be put into a rc file. I tried and failed. At last I came here seeking your guidance

I am trying to change the mouse cursor and write the code below but doesn't work. It seems IDC_CURSOR_WHITE should be put into a rc file. I tried and failed. At last I came here seeking your guidance. Help! Thanks.

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: The rc file code. And the error is mouse cousor not defined.

// 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
/////////////////////////////////////////////////开发者_如何学JAVA////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED


From the snippets you posted, in the code you are loading the cursors using IDC_CURSOR_WHITE and IRC_CURSOR_BLACK, but you are including them in the .rc file as IDC_CURSOR1 and IDC_CURSOR2.


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 resource.h file in your .rc file and then define 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 the resource in a particular file, I just include the resource.h file and use the particular cursor. So again in your case, if you want to use the cursor in test.cpp file.

test.cpp
#include "resource.h"
....
hBlackCursor = LoadCursor(hInst, MAKEINTRESOURCE(IDC_BLACK_CURSOR));
.....

I hope this helps. For further information MSDN is always your friend.

http://msdn.microsoft.com/en-us/library/ms648380%28VS.85%29.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消