Create a cursor from an ICON






4.64/5 (4 votes)
This tip is about creating a cursor from an icon
HICON hIcon = AfxGetApp()->LoadStandardIcon(IDI_INFORMATION); ICONINFO iconinfo; GetIconInfo(hIcon, &iconinfo); ICONINFO cursorinfo; cursorinfo = iconinfo; cursorinfo.fIcon = FALSE; if(m_hCursor) // make sure m_hCursor the class member variable is initialzed to NULL { ::DestroyCursor(m_hCursor); } m_hCursor = ::CreateIconIndirect(&cursorinfo); // must delete the created bitmaps due to GetIconInfo call ::DeleteObject(iconinfo.hbmMask); ::DeleteObject(iconinfo.hbmColor); // Don't forget to destroy this cursor before application exiting ::SetCursor(m_hCursor);