computergroove Posted January 12, 2011 Share Posted January 12, 2011 This program will create a dummy hovering button in the top right corner of the screen. It will also create another window that has buttons intended to make the first hovering button change its position on the screen. I have gotten the hovering button to move the button down the screen using the move up button (I know) but it only moves once by 10 pixels no matter how many times I press the move up button. Is this a problem with the speed of autoit or have I got a setting wrong somewhere? I am sure the problem is in the code I marked. Please someone look at this and tell me if there is a cleaner way to do this. expandcollapse popup;Program to interface with the MAC.ini file to modify position settings #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Mac Button Move", 401, 372, 207, 114) $MovePosUp = GUICtrlCreateButton("Move Up", 150, 10, 100, 100) $MovePosLeft = GUICtrlCreateButton("Move Left", 40, 120, 100, 100) $MovePosDown = GUICtrlCreateButton("Move Down", 150, 120, 100, 100) $MovePosRight = GUICtrlCreateButton("Move Right", 260, 120, 100, 100) $ResetButtonPos = GUICtrlCreateButton("Reset Button Position", 40, 248, 130, 41) $SaveNewPos = GUICtrlCreateButton("Save New Position", 230, 248, 130, 41) $ExitButtonPos = GUICtrlCreateButton("Close window", 230, 312, 130, 41) $Instructions = GUICtrlCreateButton("Instructions", 40, 312, 129, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $inifile = FileOpen("Mac.ini", 0); the ini file holds the hovering button position values $height = 75 $width = 80 $hPosition = IniRead("Mac.ini", "Desktop Position", "hPosition", "NotFound") $vPosition = IniRead("Mac.ini", "Desktop Position", "vPosition", "NotFound") If $inifile = -1 Then MsgBox(0, "Error", "Unable to open Mac.ini") Exit EndIf GUICreate("MAC Button Move", $width, $height, @DesktopWidth - $hPosition, $vPosition, $WS_POPUP, $WS_EX_TOPMOST) ; Creates a window GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit"); Closes the program if the tray icon is closed $FloatingPic = GUICtrlCreatePic("MacMove.jpg", -1, -1) GUICtrlSetState(-1, $GUI_DISABLE) Opt("GUICoordMode", 2) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $MovePosUp ;If Up Arrow is clicked ;<---------------------------------------Look here GUIDelete("MAC Button Move") $NewVPosition = $vPosition+10 GUICreate("MAC Button Move", $width, $height, @DesktopWidth - $hPosition, $NewVPosition, $WS_POPUP, $WS_EX_TOPMOST) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $FloatingPic = GUICtrlCreatePic("MacMove.jpg", -1, -1) GUICtrlSetState(-1, $GUI_DISABLE) Opt("GUICoordMode", 2) GUISetState() Sleep(1000) ;<---------------------------------------------------------- To Here, and leave Sleep alone - trust me Case $nMsg = $MovePosLeft ;If Left Arrow is clicked Case $nMsg = $MovePosDown ;If Down Arrow is clicked Case $nMsg = $MovePosRight ;If Right arrow is clicked Case $nMsg = $ResetButtonPos ;If Reset Button Position Is clicked Case $nMsg = $SaveNewPos ;If Reset Button Position Is clicked Case $nMsg = $Instructions ;If Reset Button Position Is clicked Case $nMsg = $ExitButtonPos ;If Reset Button Position Is clicked Exit Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Exit() Exit EndFunc ;==>_Exit The ini file has: [Desktop Position] hPosition = 80 vPosition = 1 Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 12, 2011 Moderators Share Posted January 12, 2011 computergroove,Where to start? - 1. Do not mix OnEvent and MessageLoop mode in the same script. It can be done, but there have to be very good reasons and you have to take very great care - in a simple script like this you should never mix modes- 2. Why set a GUICoord mode - you do not need to. - 3. No requirement to open an ini file before use - the Ini* functions do that for you automatically.- 4. Use FileExists to check for the existence of the ini file. And why not set default values into your IniRead lines so that you can continue even if the ini file is missing? - 5. Save the returned handle of the GUIs you creat - they come in handy as you will see in a moment.- 6. Use the proper format in a Switch structure - no need for the $msg = part in each Case.- 7. Just move the GUI with WinMOve instead of destoying and recreating it. - 8. Use WinGetPos to get the current position and then adjust using the those values. See how to use the GUI handle to identify it. - 9. I understand that you must wait for the key to be released, but use a proper function rather than "trusting" to a Sleep.So we end up with something like this: expandcollapse popup;Program to interface with the MAC.ini file to modify position settings #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> $dll = DllOpen("user32.dll") $Form1 = GUICreate("Mac Button Move", 400, 380, 200, 100) $MovePosUp = GUICtrlCreateButton("Move Up", 150, 10, 100, 100) $MovePosLeft = GUICtrlCreateButton("Move Left", 40, 120, 100, 100) $MovePosDown = GUICtrlCreateButton("Move Down", 150, 120, 100, 100) $MovePosRight = GUICtrlCreateButton("Move Right", 260, 120, 100, 100) $ResetButtonPos = GUICtrlCreateButton("Reset Button Position", 40, 248, 130, 41) $SaveNewPos = GUICtrlCreateButton("Save New Position", 230, 248, 130, 41) $ExitButtonPos = GUICtrlCreateButton("Close window", 230, 312, 130, 41) $Instructions = GUICtrlCreateButton("Instructions", 40, 312, 129, 41) GUISetState(@SW_SHOW) ;If $inifile = -1 Then ; Use FileExists as below <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If Not FileExists("Mac.ini") MsgBox(0, "Error", "Unable to open Mac.ini") Exit EndIf ;$inifile = FileOpen("Mac.ini", 0); Not needed <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $height = 75 $width = 80 $hPosition = IniRead("Mac.ini", "Desktop Position", "hPosition", "NotFound") ; Wy not valid defaults? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $vPosition = IniRead("Mac.ini", "Desktop Position", "vPosition", "NotFound") $hGUI = GUICreate("MAC Button", $width, $height, @DesktopWidth - $hPosition, $vPosition, $WS_POPUP, $WS_EX_TOPMOST) ; Creates a window ;GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit"); Not in OnEvent mode <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $FloatingPic = GUICtrlCreatePic("MacMove.jpg", -1, -1) GUICtrlSetState(-1, $GUI_DISABLE) ;Opt("GUICoordMode", 2) ; Why? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ; Use correct format for the Case <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< DllClose($dll) Exit Case $MovePosUp ;If Up Arrow is clicked $aPos = WinGetPos($hGUI) ; Get current position <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< WinMove($hGUI, "", $aPos[0], $aPos[1] - 10) ; Use WinMove to change it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do Sleep(10) Until Not _IsPressed("26", $dll) ; Wait until key is released <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $MovePosLeft ;If Left Arrow is clicked $aPos = WinGetPos($hGUI) WinMove($hGUI, "", $aPos[0] - 10, $aPos[1]) Do Sleep(10) Until Not _IsPressed("25", $dll) Case $MovePosDown ;If Down Arrow is clicked $aPos = WinGetPos($hGUI) WinMove($hGUI, "", $aPos[0], $aPos[1] + 10) Do Sleep(10) Until Not _IsPressed("28", $dll) Case $MovePosRight ;If Right arrow is clicked $aPos = WinGetPos($hGUI) WinMove($hGUI, "", $aPos[0] + 10, $aPos[1]) Do Sleep(10) Until Not _IsPressed("27", $dll) Case $ResetButtonPos ;If Reset Button Position Is clicked Case $SaveNewPos ;If Reset Button Position Is clicked Case $Instructions ;If Reset Button Position Is clicked Case $ExitButtonPos ;If Reset Button Position Is clicked Exit EndSwitch WEndPlease take all this as constructive criticism and do ask if you have any questions on any of the points I made above. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
computergroove Posted January 12, 2011 Author Share Posted January 12, 2011 Thank you for the reply. This is working very well so far with the modifications you offered. I absolutely appreciate constructive criticism. I made this from parts of my other programs and I am still in learning mode with some of this stuff which is why you are seeing some unnecessary items in my code. 1 question so far, I have never heard of DllOpen. Why am I opening user32.dll? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 12, 2011 Moderators Share Posted January 12, 2011 computergroove, Why am I opening user32.dll?From the Help file for _IsPressed: "If calling this function repeatidly [sic], should open 'user32.dll' and pass in handle. Make sure to close at end of script" M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
computergroove Posted January 13, 2011 Author Share Posted January 13, 2011 I just changed: $hGUI = GUICreate("MAC Button", $width, $height, $hPosition, $vPosition, $WS_POPUP, $WS_EX_TOPMOST) ; Creates a window to remove the @Desktopwidth and added: Case $SaveNewPos ;If Reset Button Position Is clicked IniWrite("Mac.ini", "Desktop Position", "hPosition", $aPos[1]) IniWrite("Mac.ini", "Desktop Position", "vPosition", $aPos[0]) I am getting mixed results with the correct saving of the data to the ini file. I am testing this by clicking random move up right left and down and then clicking save New Position in the gui. When I reopen it I will get the hovering button showing up at a different location then it was at when I clicked save new position - sometimes. Other times it is starting at the right location. What am I missing here? Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 13, 2011 Moderators Share Posted January 13, 2011 computergroove, What am I missing here?That you have the coordinates reversed: IniWrite("Mac.ini", "Desktop Position", "hPosition", $aPos[1]) ; The [1] element is the Y or vertical coord IniWrite("Mac.ini", "Desktop Position", "vPosition", $aPos[0]) ; The [0] element is the X or horizontal coord Try it the other way round! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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