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
3
  • 1
    What is the error you are getting while putting the resource in the rc file? Commented Oct 8, 2009 at 8:34
  • As well as what error are you getting, how are you putting it in the rc file? Commented Oct 8, 2009 at 8:38
  • What is the value of the hWhiteCursor and hBlackCursor handles? Commented Oct 8, 2009 at 10:05

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.