computergroove Posted January 22, 2011 Share Posted January 22, 2011 Here is my source. The program used to work right but I must have added something that broke it. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\..\..\Skyaim Final\MacIcon.ico #AutoIt3Wrapper_outfile=..\..\..\Skyaim Final\MacMoveButton.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;Program to interface with the MAC.ini file to modify position settings #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Misc.au3> _Singleton("Mac Button Move") $dll = DllOpen("user32.dll"); DllOpen is a recomendation of _IsPressed in the help file. Make sure to close after script is done. $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 Not FileExists(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini")then MsgBox(0, "Error", "Unable to find Mac.ini") Exit EndIf $height = 75 $width = 80 $hPosition = IniRead(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "Desktop Position", "hPosition", "Mac.ini Not Found 103") $vPosition = IniRead(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "Desktop Position", "vPosition", "Mac.ini Not Found 104") $hGUI = GUICreate("MAC Button", $width, $height, $hPosition, $vPosition, $WS_POPUP, $WS_EX_TOPMOST) ; Creates a window GUICtrlCreatePic(@ProgramFilesDir & "\MyAreaCard Merchant\MacMove.jpg", 0, 0, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE DllClose($dll) Run(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.exe") 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 $aPos[0] = $hPosition $aPos[1] = $vPosition GUIDelete("MAC Button") $hGUI = GUICreate("MAC Button", $width, $height, $hPosition, $vPosition, $WS_POPUP, $WS_EX_TOPMOST) ; Creates a window $FloatingPic = GUICtrlCreatePic(@ProgramFilesDir & "\MyAreaCard Merchant\MacMove.jpg", 0, 0, $width, $height) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() Case $SaveNewPos ;$aPos[0] = $hPosition ;$aPos[1] = $vPosition IniWrite(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "Desktop Position", "hPosition", $aPos[0]) IniWrite(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "Desktop Position", "vPosition", $aPos[1]) Case $Instructions ;If Reset Button Position Is clicked MsgBox(0, "Instructions", "This program is for moving the My Area Card Button position on the screen." & @CR & "When you run this program you will see a MAC logo with the word 'move' in it." & @CR & "Press the up, down, left and right buttons to modify where the button is located on the screen and when you are satisfied with the position of the button press the 'Save New Position' button to save your changes." & @CR & "If you want to reset the button position to the location that it was in when you opened this program then press the 'Reset Button Position' button. " & @CR &"When you are finished press the 'Close Window' button.") Case $ExitButtonPos ;If Reset Button Position Is clicked DllClose($dll) Run(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.exe") Exit EndSwitch WEnd The ini file has: [Desktop Position] hPosition=15 vPosition=1 Everything works except when I hit the Save New Position ($SaveNewPos near the end of the script). When I save to the ini file I do not get any errors but when I stop and restart the program the button shows up in the same place every time instead of saving the new position. What is wrong? 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...
Developers Jos Posted January 22, 2011 Developers Share Posted January 22, 2011 You are sure you are allowed to write to the INI file? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
computergroove Posted January 22, 2011 Author Share Posted January 22, 2011 It used to work. It is in xp pro and I am logged in as an administrator. Are you saying that the code looks good? I have tried it on 2 machines and I get the same result. 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...
Developers Jos Posted January 22, 2011 Developers Share Posted January 22, 2011 Didn't see any mistakes at first glance and as you understand, it can't be ran just like that. Have you done any debugging to see if the INIWrite() statements are really executed and whether they were successful? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
taietel Posted January 22, 2011 Share Posted January 22, 2011 Try to put $aPos = WinGetPos($hGUI) just under this statement Case $SaveNewPosition Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
computergroove Posted January 22, 2011 Author Share Posted January 22, 2011 That fixed that problem. My problem now is that I need to close the MAC.exe during the startup of the above script. I have tried both: Case WinExists("Mac Hovering Button") WinClose("Mac Hovering Button") with no results and: If ProcessExists("MAC.exe") Then ProcessClose("MAC.exe") EndIf at the top of the script with no positive results. Is there a different way? 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...
taietel Posted January 22, 2011 Share Posted January 22, 2011 You're welcome. Everything works except when I hit the Save New Position In the first post you don't have these: [ code='text' ] ( Popup ) Case WinExists("Mac Hovering Button") WinClose("Mac Hovering Button") [ code='text' ] ( Popup ) If ProcessExists("MAC.exe") Then ProcessClose("MAC.exe") EndIf Are you sure you get the right window title/exe name? Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
computergroove Posted January 23, 2011 Author Share Posted January 23, 2011 Yes they are correct including capitalization. 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...
taietel Posted January 23, 2011 Share Posted January 23, 2011 I've tried with other programs and they work (the two snippets, with little changes)... Maybe the problem is somewhere else, in the other part of your script... Put some debug/ConsoleWrite to test. Things you should know first...In the beginning there was only ONE! And zero... Progs: Create PDF(TXT2PDF,IMG2PDF) 3D Bar Graph DeskGadget Menu INI Photo Mosaic 3D Text Link to comment Share on other sites More sharing options...
JohnOne Posted January 23, 2011 Share Posted January 23, 2011 (edited) Consider this code when running mac.exe. $d_PID = Run(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.exe") If Not $d_PID Then MsgBox(0,"error","Run Failed"); program never ran Exit EndIf If Not IniWrite(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "PID", "mac.exe", $d_PID) Then MsgBox(0,"error","IniWrite Failed");Iniwritr failed Exit EndIf and consider this as beginning of script. $d_PID = Int(IniRead(@ProgramFilesDir & "\MyAreaCard Merchant\Mac.ini", "PID", "mac.exe", "0") If Not $d_PID Then MsgBox(0,"error","Invalid PID") Exit EndIf If Not ProcessExists($d_PID) Then MsgBox(0,"error","wierd") Exit Else ProcessClose($d_PID) EndFunc I'm uncertain If PID will work because its a double returned from run function, but I suspect it will be ok. Worth a shot for debugging if nothing else. Edited January 23, 2011 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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