CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

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

    Hi everyone:

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

    Any info will be appreciated...

  2. #2
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

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

    I am not aware of any way to save to a cur given a cursor handle.
    But, here is some info on the .cur format.

    http://www.wotsit.org/
    Type in cur in the search box and you will see 4 results with the file format specifications.

  3. #3
    Join Date
    May 2005
    Posts
    4,954

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

    Quote Originally Posted by dc_2000
    Hi everyone:

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

    Any info will be appreciated...
    if you dont find anything over the net ( which i doubt ) you can always find it yourself.
    • create lets say a white cursor in the MSDV
    • export it to file
    • write program that read the whole bytes to memory find out what is the Data of the cursor ( white pixels ) and you will stay with the header. or other data you need to specify.
    • now you can try to create it yourself ( just replace color ) and open it in msdv see if its valid format.


    just an idea you can figure it out yourself with some testing.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

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

    There is the LockResource() function. It normally works with a handle you get using FindResource() and LoadResource(). But maybe you are lucky and it also works with a HCURSOR handle. I would at least try it by simply casting it to HGLOBAL. Then write the buffer to a file and see if it shows up as a cursor in explorer.
    Please don't forget to rate users who helped you!

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

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

    Hey guys -- thank you everyone. I think I found a solution. (kirants clued me in) There's a good article in MSDN and an example called IconPro (http://msdn.microsoft.com/library/en...msdn_icons.asp).

    Yes, you'd say 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.

    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.)

    As for using HCURSOR as HGLOBAL, I tried it and it didn't work. I'm sure there is a low-level kernel API that can take a graphics handle and transform it into memory lock, but I haven't delved into it. If you find it, please post it here

    I also wanted to use a guessing method suggested by golanshahar, but it's not as easy as it sounds.

    Thank you everyone again!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured