Jump to content
Sign in to follow this  
cherdeg

[SOLVED] Set system cursor

Recommended Posts

cherdeg

Hi,

I would like to know how to set the system mouse cursor, meaning the global cursor shown if moving the mouse outside an AutoIT gui. I know that this can be only done by DllCall() and read all KIP's posts regarding this topic. But to my great disappointment I seem to be to stupid to understand...would someone here be able to come up with a working function _SetCursor()?

Many thanks for your upcoming efforts,

Best Regards and a beautiful weekend,

Chris

Edited by cherdeg

Share this post


Link to post
Share on other sites
cherdeg

I tried that code, but 1) it uses a cursor from another theme but the standard white one and 2) the reset to the cursor set before running the script fails on my system, I've got to use the control panel to get the default cursor back.

The following 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
Edited by cherdeg

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.