2

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



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


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

2 回答 2

1

从您发布的代码片段中,您在代码中使用IDC_CURSOR_WHITEand加载游标IRC_CURSOR_BLACK,但您将它们作为IDC_CURSOR1and包含在 .rc 文件中IDC_CURSOR2

于 2009-10-08T09:12:41.953 回答
1

这就是我需要使用资源时所做的。首先,我创建一个 resource.h 文件并使用唯一整数定义资源名称。在 .rc 文件中包含 resource.h 文件,然后定义实际资源。因此,在您的情况下,文件应如下所示

resource.h
#define IDC_BLACK_CURSOR   1001

resource.rc
#include "resource.h"
......
IDC_BLACK_CURSOR CURSOR "cursor1.cur"

现在要使用特定文件中的资源,我只需包含 resource.h 文件并使用特定的光标。所以在你的情况下,如果你想在 test.cpp 文件中使用光标。

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

我希望这有帮助。如需更多信息,MSDN 始终是您的朋友。

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

于 2009-10-09T01:54:38.993 回答