Click here to Skip to main content
15,112,217 members
Articles / Desktop Programming / MFC
Tip/Trick
Posted 4 Jan 2011

Tagged as

Stats

14K views
4 bookmarked

Create a cursor from an ICON

Rate me:
Please Sign up or sign in to vote.
4.64/5 (4 votes)
5 Jan 2011CPOL
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);

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mukit, Ataul
Technical Lead Kotha Technologies
Bangladesh Bangladesh
If you are not in - you are out !
- Chapter 1

Comments and Discussions

 
GeneralIf you don't want the cursor hotspot to be at [x,y] == [0,0]... Pin
stefanya4211-Jan-11 12:53
professionalstefanya4211-Jan-11 12:53 
GeneralTrivial for someone as talented as you maybe, who has the wh... Pin
Mukit, Ataul10-Jan-11 19:39
MemberMukit, Ataul10-Jan-11 19:39 
GeneralRe: Trivial for someone as talented as you maybe, who has the wh... Pin
Southmountain7-Feb-20 7:27
MemberSouthmountain7-Feb-20 7:27 
GeneralReason for my vote of 1 It's trivial! Why reprint the MSDN h... Pin
Carc10-Jan-11 11:35
MemberCarc10-Jan-11 11:35 
GeneralRe: Does this code snippet exist on MSDN? Do you have a link? Pin
AspDotNetDev1-Sep-11 9:00
protectorAspDotNetDev1-Sep-11 9:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.