sohfeyr Posted May 9, 2006 Share Posted May 9, 2006 I'm trying to set the windows cursor to an hourglass during a long I/O operation. Thing is, I can't get the cursor to change. $val = DllCall("user32.dll","long","LoadCursor","long",0,"long",32514) $err = @error ConsoleWrite("Error: " & $err & @cr) ConsoleWrite("Value: " & $val & @cr) ConsoleWrite(@cr) $val = DllCall("user32.dll","long","SetCursor","long",32514) $err = @error ConsoleWrite("Error: " & $err & @cr) ConsoleWrite("Value: " & $val & @cr) This results in: Error: 0 Value: Error: 0 Value: - and the cursor doesn't change at all! Any ideas? Other approaches? (using Windows XP Pro SP2) Mine:Time Functions - Manipulate the system clock! | WinControlList (WinGetClassList++) | .Net Setup Wrapper, Detect or install .Net | Writing and using a VB .NET COM object in AutoItNot mine, but highly recommended:AutoItTreeViewExtension plugin | Menu code | Callback helper dll | Auto3Lib - Control the uncontrollable | Creating COM objects in AutoIt | Using .Net framework classes in AutoIt Link to comment Share on other sites More sharing options...
GaryFrost Posted May 9, 2006 Share Posted May 9, 2006 I'm trying to set the windows cursor to an hourglass during a long I/O operation. Thing is, I can't get the cursor to change. $val = DllCall("user32.dll","long","LoadCursor","long",0,"long",32514) $err = @error ConsoleWrite("Error: " & $err & @cr) ConsoleWrite("Value: " & $val & @cr) ConsoleWrite(@cr) $val = DllCall("user32.dll","long","SetCursor","long",32514) $err = @error ConsoleWrite("Error: " & $err & @cr) ConsoleWrite("Value: " & $val & @cr) This results in: - and the cursor doesn't change at all! Any ideas? Other approaches? (using Windows XP Pro SP2) Pretty sure this works, but uses a file to load the cursor from expandcollapse popup 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 [code=auto:0] SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options... 1 year later... MrCreatoR Posted September 22, 2007 MrCreatoR MVPs 3.5k Must AutoIt! Share Posted September 22, 2007 GaryFrostPretty sure this works, but uses a file to load the cursor fromIt's work great, thanks a lot.. but how about Getting the used cursor before i set cursor? (so i can set back the originaly cursor that used by user when my script is exit).I mean function like _GetCursor()... is it possible? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options... eltorro Posted September 24, 2007 eltorro Active Members 588 more or less the same as the latter of the former. Share Posted September 24, 2007 I snipped this from a script of mine. It keep the cursor set to an hourglass when the mouse is over your gui. Global Const $OCR_WAIT = 32514 Global Const $WM_SETCURSOR = 0x0020 GuiCreate("test") GUISetState() GUIRegisterMsg($WM_SETCURSOR, "WM_CALLBACK") Local $hWaitCur = _LoadCursor($OCR_WAIT) Local $hOrigCur = _SetCursor($hWaitCur) ConsoleWrite(@error &" "&@extended&@LF) While (1) If GUIGetMsg() = -3 Then ExitLoop sleep(10) WEnd GUIRegisterMsg($WM_SETCURSOR, "") _SetCursor($hOrigCur) $hWaitCur = 0 $hOrigCur = 0 ;=============================================================================== ; Call back for GuiRegisterMsg. ;=============================================================================== Func WM_CALLBACK($hWndGUI, $MsgID, $WParam, $LParam) #forceref $hWndGUI, $MsgID, $WParam, $LParam Switch $MsgID Case $WM_SETCURSOR Return 1 EndSwitch EndFunc ;==>WM_CALLBACK ;=============================================================================== ; Function Name : _LoadCursor ; Description : Load cursor API ; Parameter(s) : $iCursor - IN - ; Requirement(s) : ; Return Value(s) : Handle to cursor, 0 on error ; User CallTip : ; Author(s) : ; Note(s) : ;=============================================================================== Func _LoadCursor($iCursor) Return _API(DllCall("user32.dll", "int", "LoadCursorA", "hwnd", 0, "int", $iCursor)) EndFunc ;==>_LoadCursor ;=============================================================================== ; Function Name : _SetCursor ; Description : Set the mouse curs ; Parameter(s) : $hCursor The handle to the new cursor ; Requirement(s) : ; Return Value(s) : Handle to previous cursor , 0 on error ; User CallTip : ; Author(s) : ; Note(s) : Application must handle WM_SETCURSOR notification. ;=============================================================================== Func _SetCursor($hCursor) Return _API(DllCall("user32.dll", "int", "SetCursor", "int", $hCursor)) EndFunc ;==>_SetCursor ;=============================================================================== ; _API ;=============================================================================== 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 Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
MrCreatoR Posted September 24, 2007 Share Posted September 24, 2007 Thanks, but it's for GUI, and i need globaly to change cursor, and then change it back to original. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
eltorro Posted September 24, 2007 Share Posted September 24, 2007 (edited) sohfeyr did not specify. Zedna posted something on restoring the cursor after calling SetSystemCursor. edit: Ahh... here it is. Edited September 24, 2007 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
eltorro Posted September 25, 2007 Share Posted September 25, 2007 I did some playing. expandcollapse popupGlobal 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 ;=============================================================================== ; _API ;=============================================================================== 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 Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
MrCreatoR Posted September 25, 2007 Share Posted September 25, 2007 Big Thanks eltorro, this solves the problem (no using files, but it's good anouth to use it for some tasks ). Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
cherdeg Posted November 17, 2008 Share Posted November 17, 2008 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 Link to comment Share on other sites More sharing options...
jennico Posted May 1, 2009 Share Posted May 1, 2009 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.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
DEFROG Posted November 4, 2009 Share Posted November 4, 2009 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 Thanks jennico, that is exactly what I have been looking for! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now