CSharp/C# >> wpf animated cursor

by Andy O'Neill » Fri, 22 Jan 2010 20:45:07 GMT

I'm trying to use an animated cursor in a WPF application.
Something is going wrong and I can't work it out.
I wonder if anyone has come across this previously.


I copy stopwtch.ani to the project folder.
Add it to the project.
Set it's build property to resource

Use the following code snippet:
StreamResourceInfo sri = Application.GetResourceStream
(new Uri("stopwtch.ani", UriKind.Relative));
Cursor customCursor = new Cursor(sri.Stream);
this.Cursor = customCursor;

error
Cannot locate resource 'stopwtch.ani'.


Thanks in anticipation.

Similar Threads

1. Displaying animated cursors.

Hi all,
I want to display an animated cursor associated to the cursor property of a
control.
but the animated cursors (.ani files) are not supported by the Cursor class.
Is there any other way to do it.
Thanks!!


2. Animated cursor as a resource

3. Displaying Animated Cursor

Hello,

I am trying to display an animated cursor.
I found several examples, but none of the
examples seem to work in my SDI app.
When I use the anmiated cursor, the cursor
completely vanishes.

How can I display an animated cursor in an
SDI app?  VS2008 MFC

BOOL CMyFormView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
{

//    ::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)) ;  //this works
      ::SetCursor(LoadAnimatedCursor(IDR_HOURGLASS)); //this fails
     
      return true;
}

HCURSOR CMyFormView::LoadAnimatedCursor(UINT nResID)
{
	HRSRC 
hRes=FindResource(AfxGetInstanceHandle(),MAKEINTRESOURCE(nResID),"ANICURSORS");
	DWORD dwSize=SizeofResource(AfxGetInstanceHandle(),hRes);
	HGLOBAL hGlob=LoadResource(AfxGetInstanceHandle(),hRes);
	LPBYTE pBytes=(LPBYTE)LockResource(hGlob);	
	HCURSOR 
hCur=(HCURSOR)CreateIconFromResource(pBytes,dwSize,FALSE,0x00030000);	
	return hCur;
}

TIA,
-jc

4. Animated Cursors for Pocket PC 2002? - Windows CE

5. Using Animated Cursors

Hi,
Anyone knowes how to use Animated Cursors ( *.ani files) in Winform
Applications ?

According to MSDN , The Cursor class in the framework does not support
animated Cursors, only regular ones ( *.cur files).

Any known workarounds ?

Thanks,

Eli.

6. animated cursors - VB.Net

7. Loading animated cursor resource

I'm trying to load an animated cursor resource directly from the exe file.
I have added it in into the assembly and set it's build action to embedded
resource.

I have a function written as follows:

Private Function GetResCursor(ByVal strIdentifier As String) As Cursor
     Return New
Cursor([Assembly].GetExecutingAssembly().GetManifestResourceStream(strIdenti
fier))
End Function

When I call the function with the following:
     m_BusyCursor = GetResCursor("FileSearch.cross.cur")
everything works just fine and I'm able to change the cursor.

However, when I call GetResCursor with this:
     m_BusyCursor = GetResCursor("FileSearch.busy.ani")
and specify an animated cursor, I receive the following exception:

        An unhandled exception of type 'System.ArgumentException' occurred
in system.windows.forms.dll
        Additional information: Invalid image format. The image file may be
corrupt.

I know the image isn't corrupt as I'm able to use this animated cursor file
under mouse properties.

Any suggestions???

Thanks

Brant


8. Animated GIFs don't animate