C++ and STL
  Common Issues
  Destructor
  regex
  string
 MFC
  CButton
  CDialog
  CEdit
  CInternetSession
  CWinThread
  CWnd
 MS VS FAQ
  Compiling, building
  Debugging
  Editor
  Settings
 Win32, API
  Console
  File System
  Graphics
  Internet functions
  Kernel objects
  Security
  Sound
  Thread, process
  Window
 Windows NT/2K*
  Logon, logoff...
  Networking
  Service Packs
 | About
  About
  Links & Freeware

Powered by
CoderTown



How to add animated cursor (ANI) to an application?

A standard situation: I'd like to add *.ani cursor file into resources and then use it. But it's not that easy as seems to be. At least VS6 and VS7 won't help us a lot in this case.

You can see yourself that you couldn't add this file in project resourses without confusing. After some iterations what I found out is - it is better to make everything manually:

A. Define ID for the resource in resource.h file:

//resource.h
#define IDR_ANICURSORBUSY 134 //whatever id not used

B. Add next line to the project *.rc file (notice ANICURSOR section name here):

//MyProject.rc
IDR_ANICURSORBUSY   ANICURSOR  "res\\hourglas.ani"

Only this method allows having *.rc file still be browsable in Visual Studio.

To change cursor I use this:

// In the program
// To load file cursor I use this:
HCURSOR hCurBusy = ::LoadCursor(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_ANICURSOR));
HCURSOR hCurStandard = ::LoadCursor(NULL, IDC_ARROW);

//...

// To set at place you need
SetCursor(hCurBusy);

//...

// Revert to standard
SetCursor(hCurStandard);

Created: 2003-05-13
Updated: 2003-10-02

Google
 
Web visualcpp.net
msdn.microsoft.com codeguru.com