Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

Using color cursors !

How can I use colored cursors in my MFC application ?
I have try this but no cursor are loaded :

IDC_MYCOLORCURSOR is a 16 color cursor defined in the
resource.

BOOL CMyDialog::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
 {
  HCURSOR hCursor = LoadCursor(IDC_MYCOLORCURSOR);
  if (hCursor) // hCursor is always NULL. Why ?
   {
    ::SetCursor(hCursor);
    return TRUE;
   }

  return CDialog::OnSetCursor(pWnd,nHitTest,message);
 }

I have also try this :

static HANDLE g_hCursor;

BOOL CMyDialog::OnInitDialog()
 {
  ......
  g_hCursor = LoadImage(AfxGetInstanceHandle(), "IDC_MYCOLORCURSOR", IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
   // g_hCursor is always NULL (Also when the cursor is monochrome). Why ?
  ......
 }

BOOL MyDialog::DestroyWindow()
 {
  if (g_hCursor) DestroyCursor((HCURSOR)g_hCursor);
  ....
 }

BOOL CMyDialog::OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message)
 {
  HCURSOR hCursor = (HCURSOR)g_hCursor;
  if (hCursor)
   {
    ::SetCursor(hCursor);
    return TRUE;
   }

  return CDialog::OnSetCursor(pWnd,nHitTest,message);
 }
ASKER CERTIFIED SOLUTION
Avatar of plaroche
plaroche

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mike_marquet
mike_marquet

ASKER

I have already test this and it doesn't work !
When I create a color cursor whith the workshop (for example, an 16 colors cursor) and I load this cursor with your method, the cursor never appears.
I must also tell that whith the workshop, when I use for example the red color and then an other color, all colors became black.

How must I proceed to create a color cursor with the workshop of visual C++ 5.0 ?
Create 256 color icon resource with VC.


HCURSOR cursor = (HCURSOR)( AfxGetApp()->LoadIcon(IDI_ICON256) );

SetCursor( cursor );