Sign in to follow this  
Followers 0
jennico

reset default cursor on exit

16 posts in this topic

hi there,

i am using this function i found in the forum to change the cursor icon within a game:

Global Const $OCR_APPSTARTING = 32650
Global Const $OCR_NORMAL = 32512
Global Const $OCR_CROSS = 32515
Global Const $OCR_HAND = 32649
Global Const $OCR_IBEAM = 32513
Global Const $OCR_NO = 32648
Global Const $OCR_SIZEALL = 32646
Global Const $OCR_SIZENESW = 32643
Global Const $OCR_SIZENS = 32645
Global Const $OCR_SIZENWSE = 32642
Global Const $OCR_SIZEWE = 32644
Global Const $OCR_UP = 32516
Global Const $OCR_WAIT = 32514

;~ _SetCursor(@WindowsDir & "\cursors\3dgarro.cur", $OCR_NORMAL)
;~ _SetCursor(@WindowsDir & "\cursors\3dwarro.cur", $OCR_NORMAL)
_SetCursor(@WindowsDir & "\cursors\banana.ani", $OCR_NORMAL)

;==================================================================
; $s_file - file to load cursor from
; $i_cursor - system cursor to change
;==================================================================
Func _SetCursor($s_file, $i_cursor)
   Local $newhcurs, $lResult
   $newhcurs = DllCall("user32.dll", "int", "LoadCursorFromFile", "str", $s_file)
   If Not @error Then
      $lResult = DllCall("user32.dll", "int", "SetSystemCursor", "int", $newhcurs[0], "int", $i_cursor)
      If Not @error Then
         $lResult = DllCall("user32.dll", "int", "DestroyCursor", "int", $newhcurs[0])
      Else
         MsgBox(0, "Error", "Failed SetSystemCursor")
      EndIf
   Else
      MsgBox(0, "Error", "Failed LoadCursorFromFile")
   EndIf
EndFunc  ;==>_SetCursor

this works fine. but - does anyone know how i can reset the cursor to the default (previous) on program exit ?

thanx in advance

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites



Solution is in OnAutoitExit call

DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", 0, 'int', $IDC_ARROW)oÝ÷ Ù©ÝIëRÊË^+«²ÒyâèiЮ®Ê+jÓÒ   ªÞ¦·yø§yÛ-jwZ­×.®Ê+²«z+&¢·¢je{±jjey«­¢+Ù
½¹ÍÐÀÌØí%
}II=ôÌÈÔÄÈ()±½°
½¹ÍÐÀÌØí=
I}AAMQIQ%9ôÌÈØÔÀ)±½°
½¹ÍÐÀÌØí=
I}9=I50ôÌÈÔÄÈ)±½°
½¹ÍÐÀÌØí=
I}
I=MLôÌÈÔÄÔ)±½°
½¹ÍÐÀÌØí=
I}!9ôÌÈØÐä)±½°
½¹ÍÐÀÌØí=
I}% 4ôÌÈÔÄÌ)±½°
½¹ÍÐÀÌØí=
I}9

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I hate to hijack this, but I'm looking for a middle finger cursor. I know about the joke program, but my antivirus deletes to on the spot. I'm looking for the cur file. anybody got it?

edit....found it.....disregard.

Edited by Volly

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

hi zedna,

Func _SetStdCursor($i_idc_cursor, $i_cursor)
   Local $newhcurs, $lResult
   $newhcurs = DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", 0, 'int', $i_idc_cursor)
   If Not @error Then
      $lResult = DllCall("user32.dll", "int", "SetSystemCursor", "int", $newhcurs[0], "int", $i_cursor)
      If @error Then
         MsgBox(0, "Error", "Failed SetSystemCursor")
      EndIf
   Else
      MsgBox(0, "Error", "Failed LoadCursor")
   EndIf
EndFunc;==>_SetStdCursor

this sounds fine. didn't know the hwnd.

try tomorrow.

@ Shevilie:

this is not quite the problem. i don't need the cursor ID

but i think zedna has the right answer. at least i can reset to system cursor - but still it's not possible to return a custom cursor set, i guess ? just in case someone who plays my game has altered the system cursor before.....

in this case i should better be able to save the current cursor set on game start. is that possible ?

thank you all

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

but i think zedna has the right answer. at least i can reset to system cursor - but still it's not possible to return a custom cursor set, i guess ? just in case someone who plays my game has altered the system cursor before.....

in this case i should better be able to save the current cursor set on game start. is that possible ?

thank you all

j.

What about GetCursor() API?

See: MSDN

Share this post


Link to post
Share on other sites

wow, i don't like this msdn, but i will work myself thru..... :-)

thanx j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

well, i read it. so anyone who can translate

HCURSOR GetCursor(VOID) and

BOOL GetCursorInfo(

PCURSORINFO pci

);

into autoit for me ?

i am not so specialised yet.... :-(

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

well, i read it. so anyone who can translate

HCURSOR GetCursor(VOID) and

BOOL GetCursorInfo(

PCURSORINFO pci

);

into autoit for me ?

i am not so specialised yet.... :-(

j.

HCURSOR GetCursor(VOID);

$hcursor = DllCall("user32.dll", "hwnd", "GetCursor")

Share this post


Link to post
Share on other sites

thanx again,

i am really sorry for my innocent scripting soul, but i will be learning these things. :)

muchas gracias


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

well, i read it. so anyone who can translate

BOOL GetCursorInfo(

PCURSORINFO pci

);

typedef struct {

DWORD cbSize;

DWORD flags;

HCURSOR hCursor;

POINT ptScreenPos;

} CURSORINFO, *PCURSORINFO, *LPCURSORINFO;

$struct = DllStructCreate("dword;dword;hwnd;long;long")
DllStructSetData($struct,1, DllStructGetSize($struct))

$return = DllCall("user32.dll", "int", "GetCursorInfo", "ptr", DllStructGetPtr($struct))
If $return[0] = 0 Then
    MsgBox(48,'Error','Error code = ' & $return[0])
Else    
    MsgBox(0,'Info','Flag = ' & DllStructGetData($struct,2) & @CRLF & 'Handle = ' & DllStructGetData($struct,3) & @CRLF & _
        'Pos.X = ' & DllStructGetData($struct,4) & @CRLF & 'Pos.Y = ' & DllStructGetData($struct,5) )
EndIf

$struct = 0

Share this post


Link to post
Share on other sites

wow in this way i can study very well. merci beaucoup.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

hello zedna and others !

i'm returning to the problem again.

the advanced script you offered unfortunately does not return the standard cursors. in fact nothing happens.

Func _SetStdCursor($i_idc_cursor, $i_cursor)
   Local $newhcurs, $lResult
   $newhcurs = DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", 0, 'int', $i_idc_cursor)
   If Not @error Then
      $lResult = DllCall("user32.dll", "int", "SetSystemCursor", "int", $newhcurs[0], "int", $i_cursor)
      If @error Then
         MsgBox(0, "Error", "Failed SetSystemCursor")
      EndIf
   Else
      MsgBox(0, "Error", "Failed LoadCursor")
   EndIf
EndFunc;==>_SetStdCursor

i assume the line

$newhcurs = DllCall("user32.dll", "hwnd", "LoadCursor", "hwnd", 0, 'int', $i_idc_cursor)

is not correct.

maybe someone can work it over once more. i found lots of entries in the forum concerning the setcursor-setstdcursor problem but no solution so far.

meanwhile i scripted a workaround using the control panel, opening the mouse properties and hence reset them to default. this scrippet can be attached to the exit of the program. it will reestablish the standard cursors and works quite secure. thus still it's a bit clumsy, but the best way to to do it until someone finds the right dll call thing.

i add my few lines here. the script works on a german system, so all others than germans have to translate the commented parts into their language.

the script works with the status bar information, in case the status bar isn't turned on this will automatically be done.

Opt("SendKeyDelay",1)
        Run("control panel")
        Do;  translate these comments into your language
            WinActivate("Systemsteuerung"); <=  'control panel'  
        Until WinActive("Systemsteuerung"); <=  'control panel'
        Do
            WinActivate("Systemsteuerung"); <=  'control panel'
            Send("m");                 <=   'm'  for mouse
            $a=StatusbarGetText("Systemsteuerung"); <=  'control panel'
            If $a="" Then 
                WinActivate("Systemsteuerung"); <=  'control panel'
                Send("!a{DOWN}{ENTER}");      <=    the "!a" might be "!v" for 'View' in English
            EndIf
        Until StringLeft($a,5)="Passt"; <=  'fits (?)'   <= status bar info when 'mouse' clicked
        WinActivate("Systemsteuerung"); <=  'control panel'
        Send("{ENTER}")     
        Do
            WinActivate("Eigenschaften von Maus");  <=  'mouse properties'
        Until WinActive("Eigenschaften von Maus");  <=  'mouse properties'
        Send("^{TAB}{ENTER}")
        WinClose("Systemsteuerung");    <=  'control panel'
        Exit

so pls help anyone with the dll call, because my script is a bit clumsy.

so long and i hope you like my workaround in the meantime.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Alas, due to a bug(?) in SetSystemCursor(), you should copy a cursor handle before calling the SetSystemCursor.

Give a replica into the monster instead of the original.

In other words, SetSystemCursor() deletes cursor handle after it changed the cursor figure.

Global Const $OCR_IBEAM = 32513
Global $hCursor, $hOriginalIBeam, $hCopyCursor

$userDll = DllOpen( "user32.dll" )


$hOriginalIBeam = DllCall( $userDll, "ptr", "LoadCursorFromFile", "str", @WindowsDir & "\Cursors\beam_r.cur" )
$hCursor = DllCall( $userDll, "ptr", "LoadCursorFromFile", "str", @ScriptDir & "\banana.cur" )
If $hCursor[0] = 0 Then
    MsgBox( 0, "Exception", "Please, put a cursor file 'banana.cur' into the script folder." )
EndIf

$hCopyCursor = DllCall( $userDll, "ptr", "CopyImage", "ptr", $hCursor[0], "uint", 2, "int", 0, "int", 0, "uint", 0 ) 
DllCall( $userDll, "ptr", "SetSystemCursor", "ptr", $hCopyCursor[0], "int", $OCR_IBEAM )
        
Sleep( 3000 )

$hCopyCursor = DllCall( $userDll, "ptr", "CopyImage", "ptr", $hOriginalIBeam[0], "uint", 2, "int", 0, "int", 0, "uint", 0 ) 
DllCall( $userDll, "ptr", "SetSystemCursor", "ptr", $hCopyCursor[0], "int", $OCR_IBEAM ) 

Sleep( 3000 )

; without the CopyImage(), the following SetSystemCursor()s won't work

$hCopyCursor = DllCall( $userDll, "ptr", "CopyImage", "ptr", $hCursor[0], "uint", 2, "int", 0, "int", 0, "uint", 0 ) 
DllCall( $userDll, "ptr", "SetSystemCursor", "ptr", $hCopyCursor[0], "int", $OCR_IBEAM )
        
Sleep( 3000 )

$hCopyCursor = DllCall( $userDll, "ptr", "CopyImage", "ptr", $hOriginalIBeam[0], "uint", 2, "int", 0, "int", 0, "uint", 0 ) 
DllCall( $userDll, "ptr", "SetSystemCursor", "ptr", $hCopyCursor[0], "int", $OCR_IBEAM )  

Sleep( 3000 )


DllCall( $userDll, "int", "DestroyCursor", "ptr", $hCursor[0] )
DllCall( $userDll, "int", "DestroyCursor", "ptr", $hOriginalIBeam[0] )

DllClose( $userDll )
Edited by ibon

Share this post


Link to post
Share on other sites

This one works:

Global 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

Share this post


Link to post
Share on other sites

#16 ·  Posted

the solution is easy:

to reset cursor to default, use:

Global Const $SPI_SETCURSORS = 0x57 
DllCall("user32.dll", "int", "SystemParametersInfo", "int", $SPI_SETCURSORS, "int", 0, "int", 0, "int", 0)

cheers j ^_^


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0