Jump to content

syscursor


klaus.s
 Share

Recommended Posts

Hi,

for changing the system-cursor I found several examples using LoadCursorFromFile. Searching for LoadCursor the only hit was here:

http://www.autoitscript.com/forum/index.ph...p;hl=loadcursor

(This magnifier is a very nice tool by the way.)

syscursor can change the system-cursor to another built-in cursor or to one stored locally in a cur-file. Only one flaw so far: a built-in cursor has to be sacrified if a custom-cursor is used. Maybe someone has further ideas about that.

--Klaus

syscursor.au3

Link to comment
Share on other sites

Updated version, flaws removed by using CopyIcon (CopyCursor does not work, XP/SP2), attached zip-file includes two cur-files.

#include <GUIConstants.au3>

menu()
func menu()

  local $msg, $gc[99], $n, $i, $t, $m

  GuiCreate( "syscursor", 155, 490, -1, -1)
  $n= 0

  $gc_roe= GUICtrlCreateCheckbox( "restore on exit", 3, 0, 150, 24)
  GUICtrlSetState( $gc_roe, $GUI_CHECKED)
  
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "000 default", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "101 selectGreen", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "102 selectRed", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "512 select", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "513 insert", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "514 wait", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "515 cross", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "516 arrowUp", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "641 select", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "642 stretchDiagonalBack", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "643 stretchDiagonalForward", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "644 stretchHorizontal", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "645 stretchVertical", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "646 move", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "648 avoid", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "649 hand", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "650 selectWait", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "651 selectQuestion", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateButton( "663 selectCD", 3, $n*24, 150, 24)

  GUISetState( @SW_SHOW)

  while true
    $msg = GUIGetMsg()
    if $msg = $GUI_EVENT_CLOSE then exitloop
    for $i= 1 to $n
      if $gc[$i] == $msg then
        syscursor( stringleft( guictrlread( $msg), 3) *1)
        exitloop
      endif
    next
  wend
  
  if GUICtrlRead( $gc_roe) = $GUI_CHECKED then
    syscursor( 0) ; reset to default
  endif  
  
endfunc

func syscursor( $i)

   global $syscursor_save
   global $syscursor_saved
   local $a, $k, $file

   if $syscursor_saved then     
     $a= $syscursor_save
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif
   $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", 32512)
   $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
   $syscursor_save= $a
   $syscursor_saved= true
   
   if $i > 500 then
     $k= 32000 +$i
     $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", $k)
     $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   elseif $i then
     $file= @scriptdir & "\" & $i & ".cur"
     $a= DllCall( "user32.dll", "int", "LoadCursorFromFile", "str", $file)
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif     

endfunc

syscursor20080217.zip

Link to comment
Share on other sites

Fails with animated cursors.

Clarification: By "fails" I don't mean errors, but animated cursors do not work (they are not animated, only still pictures).

I think you will know how to convert this. It's a delphi example using Animated Cursors :)

http://www.delphi3000.com/articles/article_2642.asp?SK=

Link to comment
Share on other sites

Thanks to all for your comments and feedback. Until now I did not consider these animated cursors and maybe a solution will come up. Because I like this swapping functionality of LoadCursor/SetSystemCursor as already shown in my first version, I added this in my newest version, along with some cleanup.

#include <GUIConstants.au3>

menu()
func menu()

  local $msg, $gc[99], $gc_roe, $gc_swap, $n, $i, $j

  GuiCreate( @ScriptName, 230, 520, -1, -1)

  $gc_roe= GUICtrlCreateCheckbox( "restore on exit", 3, 0)
  GUICtrlSetState( $gc_roe, $GUI_CHECKED)

  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "000 default", 3, $n*24, 150, 24, $WS_GROUP)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "101 selectGreen", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "102 selectRed", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "512 select (default)", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "513 insert", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "514 wait", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "515 cross", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "516 arrowUp", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "641 select (default)", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "642 stretchDiagonalBack", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "643 stretchDiagonalForward", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "644 stretchHorizontal", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "645 stretchVertical", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "646 move", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "648 avoid", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "649 hand", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "650 selectWait", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "651 selectQuestion", 3, $n*24, 150, 24)
  $n+= 1
  $gc[$n]= GUICtrlCreateRadio( "663 selectCD", 3, $n*24, 150, 24)

  $gc_swap= GUICtrlCreateButton( "swap cursor assignments of 512 and 513", _
    3, $n*24 +30)

  GUISetState( @SW_SHOW)

  while true
    $msg = GUIGetMsg()
    if $msg ==   $GUI_EVENT_CLOSE then exitloop
    if $msg == $gc_swap then
      $j= 1513
      syscursor( $j)
      msgbox( 0, @ScriptName, "Check cursor assignments " & _
        "(here and in editor), then press Ok to undo.")
      syscursor( $j)
      continueloop
    endif
    for $i= 1 to $n
      if $gc[$i] == $msg then
        $j= stringleft( guictrlread( $msg, 1), 3) *1
        syscursor( $j)
        exitloop
      endif
    next
  wend

  if GUICtrlRead( $gc_roe) = $GUI_CHECKED then
    syscursor( 0) ; reset to default
  endif

endfunc

func syscursor( $j)

   global $syscursor_save
   local $a, $k, $file

   if $j > 1500 then
     $k= 31000 +$j
     $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", $k)
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
     return
   endif

   if $syscursor_save <> "" then
     $a= $syscursor_save
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif
   $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", 32512)
   $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
   $syscursor_save= $a

   if $j > 500 then
     $k= 32000 +$j
     $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", $k)
     $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   elseif $j then
     $file= @scriptdir & "\" & $j & ".cur"
     $a= DllCall( "user32.dll", "int", "LoadCursorFromFile", "str", $file)
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif

endfunc

syscursor20080218.zip

Link to comment
Share on other sites

  • 8 months later...

Thanks to all for your comments and feedback. Until now I did not consider these animated cursors and maybe a solution will come up. Because I like this swapping functionality of LoadCursor/SetSystemCursor as already shown in my first version, I added this in my newest version, along with some cleanup.

func syscursor( $j)

   global $syscursor_save
   local $a, $k, $file

   if $j > 1500 then
     $k= 31000 +$j
     $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", $k)
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
     return
   endif

   if $syscursor_save <> "" then
     $a= $syscursor_save
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif
   $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", 32512)
   $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
   $syscursor_save= $a

   if $j > 500 then
     $k= 32000 +$j
     $a= DllCall( "user32.dll", "int", "LoadCursor", "int", 0, "int", $k)
     $a= DllCall( "user32.dll", "int", "CopyIcon", "int", $a[0])
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   elseif $j then
     $file= @scriptdir & "\" & $j & ".cur"
     $a= DllCall( "user32.dll", "int", "LoadCursorFromFile", "str", $file)
     DllCall( "user32.dll", "int", "SetSystemCursor", "int", $a[0], "int", 32512)
   endif

endfuncoÝ÷ Ûú®¢×©ZºÂ"ëÊ«~éܶ*'¢uÏHýâµö¢Ëhn¸§Ø^uçÚº[[iÉ,ÊÇ.®Ê+Ò̬rê좽4ÒìÊÇ.®Ê+ç]¡j÷§¡çßyËHßÛÞm¢·¬¶Þ¶º»(®ø¶¢{k¢ZZéZ¦^¶«¨´Ê.±ê®¢Õ²Ø^­æ©à{­#÷Eè­Û¸¬2N¢YhÂ)à¢w°¢¹,jëh×6Global Const $OCR_NORMAL = 32512
Global Const $OCR_IBEAM = 32513
Global Const $OCR_WAIT = 32514

$GUI = GuiCreate("test")
GUISetState()
    Local $hWaitCur
    $hWaitCur = _LoadCursor($OCR_WAIT)
    _SetSystemCursor($hWaitCur,$OCR_NORMAL)
    While 1
         If GUIGetMsg() = -3 Then ExitLoop
         sleep(10)
     WEnd
    _SetSystemCursor($hWaitCur,$OCR_NORMAL)
    $hWaitCur = 0

Func _LoadCursor($iCursor)
    Return SetError(@error,@extended ,_API(DllCall("user32.dll", "int", "LoadCursorA", "hwnd", 0, "int", $iCursor)))
EndFunc   ;==>_LoadCursor

Func _SetSystemCursor($hCursor,$iCursor)
    Return SetError(@error,@extended ,_API(DllCall("user32.dll", "int" ,"SetSystemCursor","int",$hCursor,"int",$iCursor)))
EndFunc

Func _API($v_ret)
    Local $err = @error
    Local $ext = @extended
    If Not $err Then
        If IsArray($v_ret) Then
            Return $v_ret[0]
        Else
            Return $v_ret
        EndIf
    EndIf
    Return SetError($err, $ext, 0)
EndFunc   ;==>_API
Edited by cherdeg
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...