Jump to content

(.cur)


Recommended Posts

Something like this?

#Include <WinAPI.au3>

Global $hCursor = LoadCursorFromFile(@ScriptDir & 'cursor.cur')    ; change it with your cursor file

$hForm = GUICreate('Example', 400, 400)
GUIRegisterMsg(0x0020,'WM_SETCURSOR')
GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3

DestroyCursor($hCursor)

Func WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)
    _WinAPI_SetCursor($hCursor)
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

Func LoadCursorFromFile($sPath)
    Local $aRet = DllCall("user32.dll","handle","LoadCursorFromFile","str",$sPath)
    If @error Then
        Return False
    Else
        Return $aRet[0]
    EndIf
EndFunc

Func DestroyCursor($hCursor)
    Local $aRet = DllCall("user32.dll","bool","DestroyCursor","handle",$hCursor)
    If @error Then
        Return False
    Else
        Return $aRet[0]
    EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

So

if i have a gui that is 400x400

is there any way to divide the qui into 4 regions

for example

region1=(0, 200, 0, 0)

region2=(200, 0, 200, 400)

region3=(0, 200, 400, 0)

region4=(0, 0, 200, 200)

Then if possible i would like to modify your script to change the cur file based on region

thank you

Link to comment
Share on other sites

This could be a way

#Include <WinAPI.au3>

AutoItSetOption("MouseCoordMode",2)

Global $tRegion1, $tRegion2, $tRegion3, $tRegion4
Global $tPoint = DllStructCreate("struct; long X;long Y; endstruct")

SetRegion()
Global $hCursor1 = LoadCursorFromFile(@ScriptDir & 'cursor1.cur')    ; change it with your cursor file
Global $hCursor2 = LoadCursorFromFile(@ScriptDir & 'cursor2.cur')    ; change it with your cursor file
Global $hCursor3 = LoadCursorFromFile(@ScriptDir & 'cursor3.cur')    ; change it with your cursor file
Global $hCursor4 = LoadCursorFromFile(@ScriptDir & 'cursor4.cur')    ; change it with your cursor file

$hForm = GUICreate('Example', 400, 400)
GUIRegisterMsg(0x0020,'WM_SETCURSOR')
GUISetState()

Do
    Sleep(10)
Until GUIGetMsg() = -3

DestroyCursor($hCursor1)
DestroyCursor($hCursor2)
DestroyCursor($hCursor3)
DestroyCursor($hCursor4)

Func WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)
    DllStructSetData($tPoint,"X",MouseGetPos(0))
    DllStructSetData($tPoint,"Y",MouseGetPos(1))
    If PtInRect($tRegion1,$tPoint) Then _WinAPI_SetCursor($hCursor1)
    If PtInRect($tRegion2,$tPoint) Then _WinAPI_SetCursor($hCursor2)
    If PtInRect($tRegion3,$tPoint) Then _WinAPI_SetCursor($hCursor3)
    If PtInRect($tRegion4,$tPoint) Then _WinAPI_SetCursor($hCursor4)
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

Func SetRegion()
    $tRegion1 = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
    DllStructSetData($tRegion1,"Left",0)
    DllStructSetData($tRegion1,"Top",0)
    DllStructSetData($tRegion1,"Right",200)
    DllStructSetData($tRegion1,"Bottom",200)
    $tRegion2 = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
    DllStructSetData($tRegion2,"Left",200)
    DllStructSetData($tRegion2,"Top",0)
    DllStructSetData($tRegion2,"Right",400)
    DllStructSetData($tRegion2,"Bottom",200)
    $tRegion3 = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
    DllStructSetData($tRegion3,"Left",0)
    DllStructSetData($tRegion3,"Top",200)
    DllStructSetData($tRegion3,"Right",200)
    DllStructSetData($tRegion3,"Bottom",400)
    $tRegion4 = DllStructCreate("struct; long Left;long Top;long Right;long Bottom; endstruct")
    DllStructSetData($tRegion4,"Left",200)
    DllStructSetData($tRegion4,"Top",200)
    DllStructSetData($tRegion4,"Right",400)
    DllStructSetData($tRegion4,"Bottom",400)
EndFunc

Func LoadCursorFromFile($sPath)
    Local $aRet = DllCall("user32.dll","handle","LoadCursorFromFile","str",$sPath)
    If @error Then
        Return False
    Else
        Return $aRet[0]
    EndIf
EndFunc

Func DestroyCursor($hCursor)
    Local $aRet = DllCall("user32.dll","bool","DestroyCursor","handle",$hCursor)
    If @error Then
        Return False
    Else
        Return $aRet[0]
    EndIf
EndFunc

Func PtInRect(ByRef $tRect, ByRef $tPoint)
    Local $aResult = DllCall("user32.dll", "bool", "PtInRect", "struct*", $tRect, "struct", $tPoint)
    If @error Then
        Return SetError(1, 0, False)
    Else
        Return $aResult[0]
    EndIf
EndFunc

When the words fail... music speaks.

Link to comment
Share on other sites

Bishop

I'm having some issues including a case in your code

I kept it simple while blending it with a gui that has a transparent region

but the case is not working. All i am trying to do is move the mouse

under the mouse move command.

But before i waste to much of your time, will mouse move disable

the cursor function and not show the cursor?

#include <GUIConstants.au3>
#Include <WinAPI.au3>

Local $btn1
Global $hCursor = LoadCursorFromFile(@MyDocumentsDir & '180.ani')    ; change it with your cursor file
Global $gCursor = LoadCursorFromFile(@MyDocumentsDir & 'cur.ani')    ; change it with your cursor file

$gui = GUICreate("GUI", 500, 500)
$btn1 = GUICtrlCreateButton("tool create item", 30, 40, 100, 30)

_GUICreateInvRect($gui, 100, 150, 200, 200)

GUISetState()
GUIRegisterMsg(0x0020,'WM_SETCURSOR')
 
Do     
    Sleep(10)
    
    
    
    
Until GUIGetMsg() = -3
DestroyCursor($hCursor)

While 1
  If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
  Sleep(10)
Wend

Func _GUICreateInvRect($hwnd, $l, $t, $w, $h)
  $pos = WinGetPos($hwnd)

  $1 = 0
  $2 = 0
  $3 = $pos[2]
  $4 = $t
  $ret = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $1, "long", $2, "long", $3, "long", $4)
  $1 = 0
  $2 = 0
  $3 = $l
  $4 = $pos[3]
  $ret2 = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $1, "long", $2, "long", $3, "long", $4)
  $1 = $l + $w
  $2 = 0
  $3 = $pos[2]
  $4 = $pos[3]
  $ret3 = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $1, "long", $2, "long", $3, "long", $4)
  $1 = 0
  $2 = $t + $h
  $3 = $pos[2]
  $4 = $pos[3]
  $ret4 = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", $1, "long", $2, "long", $3, "long", $4)

  DllCall("gdi32.dll", "long", "CombineRgn", "long", $ret[0], "long", $ret[0], "long", $ret2[0], "int", 2)
  DllCall("gdi32.dll", "long", "CombineRgn", "long", $ret[0], "long", $ret[0], "long", $ret3[0], "int", 2)
  DllCall("gdi32.dll", "long", "CombineRgn", "long", $ret[0], "long", $ret[0], "long", $ret4[0], "int", 2)

  DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hwnd, "long", $ret[0], "int", 1)
 

EndFunc


                                                    


Func WM_SETCURSOR($hWnd, $iMsg, $wParam, $lParam)    
    _WinAPI_SetCursor($hCursor)     
    Return _WinAPI_DefWindowProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc

Func LoadCursorFromFile($sPath)     
    Local $aRet = DllCall("user32.dll","handle","LoadCursorFromFile","str",$sPath)    
    If @error Then       
        Return False     
    Else      
        
    Return $aRet[0]    
    EndIf
EndFunc

Func DestroyCursor($hCursor)    
        Local $aRet = DllCall("user32.dll","bool","DestroyCursor","handle",$hCursor)   
        If @error Then       
            Return False     
        Else         
            Return $aRet[0]   
        EndIf
    EndFunc
    
    
    Switch $btn1
          
  Case $btn1
             MouseMove(1011, 101)
                MouseMove(1012, 102)
                MouseMove(1013, 103)
                MouseMove(1014, 104)
                MouseMove(1015, 105)
                MouseMove(1016, 106)
                MouseMove(1017, 107)
                MouseMove(1018, 108)
                MouseMove(1019, 109)
                MouseMove(1020, 110)
                MouseMove(1021, 111)
                MouseMove(1023, 111)
                MouseMove(1025, 111)
                MouseMove(1027, 111)
                MouseMove(1029, 111)
                MouseMove(1031, 111)
                MouseMove(3103, 111)
                MouseMove(1035, 111)
            EndSwitch
Link to comment
Share on other sites

It's all about this region. You get WM_SETCURSOR message when your mouse cursor is over your GUI but if you made a hole in your GUI this change all things because under your mouse now will be other window.

When the words fail... music speaks.

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...