Click here to Skip to main content
Click here to Skip to main content

Tagged as

Create a cursor from an ICON

, 5 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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
Chief Technology Officer Rational Technologies
Bangladesh Bangladesh
C++ is not C with classes, JQuery is not Javascript, Google Search is not Learning, Design Patterns are not fashion, A code written in 2005 is not backdated just because it's 2015
Follow on   Twitter

Comments and Discussions

 
GeneralIf you don't want the cursor hotspot to be at [x,y] == [0,0]... Pinmemberslposey11-Jan-11 12:53 
GeneralTrivial for someone as talented as you maybe, who has the wh... PinmemberMukit, Ataul10-Jan-11 19:39 
GeneralReason for my vote of 1 It's trivial! Why reprint the MSDN h... PinmemberCarc10-Jan-11 11:35 
GeneralRe: Does this code snippet exist on MSDN? Do you have a link? PinprotectorAspDotNetDev1-Sep-11 9:00 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 5 Jan 2011
Article Copyright 2011 by Mukit, Ataul
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid