Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Save cursor in a file (.CUR file format)?

Status
Not open for further replies.

dc2000

Programmer
Jun 7, 2005
48
US
Hi everyone:

Does anyone know how to save a cursor in a file? Any links regarding .CUR file format?

Any info will be appreciated...
 
Hey, thanks. I'll check into it. I think I found a solution. There's a good article in MSDN and an example called IconPro
Yes, this is about icons, but at the end it says, "Cursors, in Win32, are very similar to icons". There's one data member in the header of a .CUR file that is different from the .ICO file. So this is exactly what you said.

I haven't tried it yet, but here's how it should work:
(1) Use GetIconInfo with an HCURSOR:

Code:
ICONINFO ii;
if(!GetIconInfo(hCursor, &ii) || ii.fIcon != FALSE)
{
    //Error, handle is not a cursor, or is a bad one
}
(2) Then inspect two members of ICONINFO: hbmMask and hbmColor which are two bitmaps for a mask and color image of a cursor. Both are regular bitmaps, so we can use GetObject to retrieve all the info for the header of .CUR file (which format you can find in that MSDN article above), and GetDIBits to retrieve graphic bits.

The only thing that first confused me was the fact the HCURSOR handle carries information only about cursor currently displayed and doesn't have any other images the cursor might have in a resource file. Evidently when it is loaded by LoadCursor or LoadImage all of them are discarded and not stored in memory. (As well as icons, by the way.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top