Microsoft KB Archive/137627

= How To Change the Mouse Pointer to Any .CUR or .ANI File =

Article ID: 137627

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition

-



This article was previously published under Q137627



SUMMARY
The ability to change the mouse pointer to a cursor file other than one of the default system cursors is available to Visual FoxPro through the Windows API. This feature set is available under both Windows 95 and Windows NT.

Visual FoxPro allows you to change the MousePointer property to specify one of the pointer shape available in the default 12 system pointers, and the DragIcon property allows you to set the pointer to any monochrome .cur file. However, in some cases, you might want a colored pointer or an animated pointer (.ani file). You can use the Windows API to do this.

The example in this article shows a method using LoadCursorFromFile and SetSystemCursor. There are other functions that may be useful as well such as CopyIcon, ClipCursor, GetCursor, and so on. See the Win32api.hlp file for more information on these functions.



MORE INFORMATION
The following code demonstrates a form with two command buttons. The upper button changes the pointer to an animated cursor and the lower button resets the pointer to the original cursor. The sample code is designed to run under Windows NT. It requires slight modification to run under Windows 95; instructions are given in comments.

Sample Code
PUBLIC oform1

oform1=CREATEOBJECT("form1") oform1.Show RETURN

DEFINE CLASS form1 AS form Caption = "Form1" Name = "Form1"

ADD OBJECT command1 AS commandbutton WITH ; Top = 72, ; Left = 96, ; Height = 29, ; Width = 94, ; Caption = "SetCursor", ; Name = "Command1"

ADD OBJECT command2 AS commandbutton WITH ; Top = 144, ; Left = 96, ; Height = 29, ; Width = 94, ; Caption = "ResetCursor", ; Name = "Command2"

PROCEDURE Init public currenthcurs,tempcurs,newhcurs,OCR_NORMAL OCR_NORMAL=32512 &&from winuser.h     ENDPROC

PROCEDURE command1.Click MyDir=space(255) declare Integer GetWindowsDirectory in Win32Api String @, Integer declare Integer CopyIcon in Win32Api Integer declare Integer LoadCursorFromFile in Win32Api String declare Integer SetCursor in Win32Api Integer declare SetSystemCursor in Win32Api Integer, Integer declare Integer GetCursor in Win32Api

currenthcurs=GetCursor tempcurs=CopyIcon(currenthcurs) len=GetWindowsDirectory(@MyDir,255) MyDir=left(MyDir,len)+"\System32\dinosaur.ani" && WindowsNT newhcurs=LoadCursorFromFile(MyDir) =SetSystemCursor(newhcurs,OCR_NORMAL) ENDPROC
 * Uncomment the next line and comment the previous line if running under
 * Windows 95, or set MyDir to the path to a valid .cur or .ani file.
 * MyDir=left(MyDir,len)+"\cursors\dinosaur.ani" && Windows95

PROCEDURE command2.Click =SetSystemCursor(tempcurs,OCR_NORMAL) ENDPROC ENDDEFINE

