name22

Set GUI Cursor directly from resource

Dec 22nd, 2012
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #AutoIt3Wrapper_Res_File_Add=C:\Path\To\Cursor.cur, rt_cursor, CURSOR
  2. ;Adjust the path so it points to your .cur or .ani file. "rt_cursor" is the resource-type and "CURSOR" the resource name (to identify it when using multiple resources).
  3. ;The script needs to be compiled to function correctly (resource can only be loaded from compiled .exe).
  4.  
  5. #include <WindowsConstants.au3>
  6. #include <GUIConstants.au3>
  7. #include <Constants.au3>
  8. #include <WinAPI.au3>
  9. #include <WinAPIEx.au3>
  10.  
  11. ; -Author: name22 (www.autoit.de)
  12.  
  13. $hInstance = _WinAPI_GetModuleHandle("") ;Handle to the instance of this script.
  14. $hNewCur = _WinAPI_LoadImage($hInstance, "CURSOR", $IMAGE_CURSOR, 0, 0, 0) ;Load cursor from instance.
  15.  
  16. $hWnd_GUI = GUICreate("Cursor", 400, 400)
  17. GUISetState()
  18.  
  19. GUIRegisterMsg($WM_SETCURSOR, "_SetCursor") ;Called if cursor moves inside the GUI
  20.  
  21. While True
  22.     Switch GUIGetMsg()
  23.         Case $GUI_EVENT_CLOSE
  24.             ExitLoop
  25.     EndSwitch
  26. WEnd
  27.  
  28. GUIRegisterMsg($WM_SETCURSOR, "") ;De-register message
  29. _WinAPI_DestroyCursor($hNewCur) ;Delete resource from memory
  30.  
  31. Func _SetCursor($hWnd, $iMsg, $wParam, $lParam)
  32.     #forceref $hWnd, $iMsg, $wParam, $lParam
  33.     If _WinAPI_LoWord($lParam) = 1 Then ;Cursor is in client-area
  34.         _WinAPI_SetCursor($hNewCur) ;Set cursor
  35.         Return 1 ;Return and allow further processing.
  36.     EndIf
  37. EndFunc
RAW Paste Data