Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Restore default cursor
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Divers
Thread ID:
00043737
Message ID:
00044423
Vues:
48
This code shows how to reset the mouse cursors to the default cursor scheme set in Control Panel.

In order to simplify the code, I dropped any error checking and variable declaration. If you want to use this code, I strongly recommend you to include error handling code (you'll find some comments inside the code for basic error checking) and also, proper variable declaration.

Vlad
*-- Declare Win32API functions to manage mouse cursors
declare integer LoadCursorFromFile in Win32API ;
                string 
declare integer LoadCursor in Win32API ;
                integer, integer
declare integer SetSystemCursor in Win32API ;
                integer, integer

*-- Declare Win32API functions to manage registries
declare integer RegOpenKey in Win32API ;
                integer, string, integer @
declare integer RegCloseKey in Win32API ;
                integer
declare integer RegQueryValueEx in Win32API;
                integer, string, integer, ;
                integer @, string @, integer @

*-- Declare an array for internal cursor identifiers
dimension laCursorIDs[14]
laCursorIDs[ 1] = 32650
laCursorIDs[ 2] = 32512  && OCR_NORMAL
laCursorIDs[ 3] = 32515  && OCR_CROSS
laCursorIDs[ 4] = 32651
laCursorIDs[ 5] = 32513  && OCR_IBEAM 
laCursorIDs[ 6] = 32648  && OCR_NO 
*-- I couldn't find any documentation
*   about this mouse pointer.
*   The value I use here is just a guess.
*   It works, but it may be wrong.
laCursorIDs[ 7] = 32647  && ?
laCursorIDs[ 8] = 32646  && OCR_SIZEALL
laCursorIDs[ 9] = 32643  && OCR_SIZENESW
laCursorIDs[10] = 32645  && OCR_SIZENS
laCursorIDs[11] = 32642  && OCR_SIZENWSE
laCursorIDs[12] = 32644  && OCR_SIZEWE
laCursorIDs[13] = 32516  && OCR_UP
laCursorIDs[14] = 32514  && OCR_WAIT

*-- Declare an array for registry cursor names
dimension laCursorNames[14]
laCursorNames[ 1] = "AppStarting"
laCursorNames[ 2] = "Arrow"
laCursorNames[ 3] = "Crosshair"
laCursorNames[ 4] = "Help"
laCursorNames[ 5] = "IBeam" 
laCursorNames[ 6] = "No" 
laCursorNames[ 7] = "NWPen"
laCursorNames[ 8] = "SizeAll"
laCursorNames[ 9] = "SizeNESW"
laCursorNames[10] = "SizeNS"
laCursorNames[11] = "SizeNWSE"
laCursorNames[12] = "SizeWE"
laCursorNames[13] = "UpArrow"
laCursorNames[14] = "Wait"

lnHKEY_CURRENT_USER = -2147483647

*-- All mouse cursors registered under
*   HKEY_CURRENT_USER\Control Panel\Cursors
lnRegistryHandle = 0
*-- RegOpenKey returns 0 if successful.
lnError = RegOpenKey( lnHKEY_CURRENT_USER,;
                      "Control Panel\Cursors",;
                      @lnRegistryHandle)

*-- Loop for all mouse cursors and:
*     1. Retrieve the registry setting
*        IE: The file name of the cursor.
*        It is an empty string if standard cursor.
*     2. Load cursor from file or from standard.
*     3. Restore the cursor.
for lnI = 1 to 14
   if lnI = 7
      *-- I don't know the ID for this cursor
      loop
   endif
   lnCursorNameSize = 256
   lcCursorName = space( lnCursorNameSize)
   lnType = 0
   *-- Retrieve the file name of the cursor.
   *-- RegQueryValueEx returns 0 if successful.
   lnError = RegQueryValueEx( lnRegistryHandle, ;
                              laCursorNames[ lnI], ;
                              0, ;
                              @lnType, ;
                              @lcCursorName, ;
                              @lnCursorNameSize)
   lcCursorName = left( lcCursorName, lnCursorNameSize - 1)
   if empty( lcCursorName)
      *-- Standard mouse cursor
      *-- LoadCursor returns >0 if successful
      lnCursorHandle = LoadCursor( 0, laCursorIDs[ lnI])
   else
      *-- Mouse cursor from file
      *-- LoadCursorFromFile returns >0 if successful
      lnCursorHandle = LoadCursorFromFile( lcCursorName)
   endif
   *-- SetSystemCursor returns 0 if fails
   lnError = SetSystemCursor( lnCursorHandle, laCursorIDs[ lnI])
endfor

*-- RegCloseKey returns 0 if successful.
lnError = RegCloseKey( lnRegistryHandle)
return
>>:) Almost obviuosly: you can take each key from HKEY_CURRENT_USER\Control Panel\Cursors and restore the mouse cursors using SetSystemCursor(). :)
>>
>Can you give me an idea how to get these keys programmatically? I can do the restoring easily enough...Thanks.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform