Click here to Skip to main content
6,595,444 members and growing! (20,397 online)
Email Password   helpLost your password?
Multimedia » GDI » GDI Objects     Intermediate

Display Animated Cursors stored in Resources

By Bernd Wißler

Demonstrates how to use an animated gif stored in your resource file as an animated cursor
VC6, GDI, Dev
Posted:14 Dec 1999
Views:76,755
Bookmarked:14 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
12 votes for this article.
Popularity: 4.10 Rating: 3.80 out of 5

1

2

3
1 vote, 33.3%
4
2 votes, 66.7%
5
  • Download demo project - 21 Kb
  • Download source files - 1 Kb
  • This article describes how you can display an animated cursor that is created from an animated gif and stored in your applications resources.

    Before you can display it, you must import the animated gif into your resource file. You do this by declaring the animated gif file as a new user defined resource named "ANICURSOR" within your resource file.

    /////////////////////////////////////////////////////////////////////////////
    
    //
    
    // ANICURSORS
    
    //
    
    
    IDR_HORSE_CURSOR        ANICURSORS DISCARDABLE  "res\\horse.ani"
    

    You then use the following function which loads the gif and displays it as an animated cursor:

     
    //
    
    // LoadAnimatedCursor: Loads an animated gif from the resource as an cursor
    
    //
    
    HCURSOR LoadAniCursor(UINT nID)
    {
    	HINSTANCE hInst=AfxGetInstanceHandle();
    	HRSRC hRes=FindResource(hInst,MAKEINTRESOURCE(nID),"ANICURSORS");
    	DWORD dwSize=SizeofResource(hInst, hRes);
    	HGLOBAL hGlob=LoadResource(hInst, hRes);
    	LPBYTE pBytes=(LPBYTE)LockResource(hGlob); 
    	return (HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);
    }
    

    To display the cursor, call SetCursor(LoadAniCursor(ID_ANIMATED_HORSE))

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    Bernd Wißler


    Member

    Location: Germany Germany

    Other popular GDI articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 16 of 16 (Total in Forum: 16) (Refresh)FirstPrevNext
    QuestionCannot work in Multiple Documents dialog Pinmemberkevanphua17:40 27 May '07  
    GeneralLoading 256-color animated cursors? PinmemberBartosz Bien11:33 7 Jun '06  
    GeneralWhere to put LoadAniCursor()? Pinmemberlasombra197923:31 28 Nov '04  
    GeneralMSFlexgrid distribute? PinmemberJosé Luis Sogorb8:22 28 Nov '04  
    GeneralUne autre facon, qui marche sur toutes plateformes: PinsussJoshu18:36 22 Mar '03  
    GeneralResource leak! PinmemberRobert Space22:01 19 Mar '02  
    GeneralA different way... PinmemberSibilant16:44 1 Mar '02  
    GeneralCURSOR DISAPPEARS PinmemberSibilant8:55 1 Mar '02  
    GeneralHave a solution for Win9X Here Pinmemberfigmo14:35 24 Oct '01  
    GeneralRe: Have a solution for Win9X Here PinmemberAnonymous15:15 24 Oct '01  
    GeneralRe: Have a solution for Win9X Here PinmemberNonni23:45 5 Nov '01  
    GeneralUsing the example code PinmemberRon Maman0:53 27 Nov '00  
    GeneralCreateIconFromResource() Always failed !!! PinsussHomles Chen0:10 22 Sep '00  
    GeneralWorking great but.... PinsussKishk9110:21 10 Mar '00  
    GeneralWorking great but.... PinsussKishk9110:21 10 Mar '00  
    GeneralNot a GIF, but a simple ANI cursor! PinsussPPEscher14:14 22 Jan '00  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 14 Dec 1999
    Editor: Chris Maunder
    Copyright 1999 by Bernd Wißler
    Everything else Copyright © CodeProject, 1999-2009
    Web13 | Advertise on the Code Project