J03Z Posted April 6, 2010 Share Posted April 6, 2010 (edited) Okay, so basically I have a program that runs programs, and such. Well when I add internet explorer to the list of programs I want to run everything is fine until it gets to the WinMove () part in the Run function, all the other programs run fine and move back to the saved position in the cords.ini and when I use WinMove () by it's self with internet explorer it works fine as well. Code : expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include <file.au3> #include <process.au3> Opt("GUIOnEventMode", 1) Opt("WinTitleMatchMode", 2) $file = GUICreate("Desktop Automator v1.0", 544, 281, 352, 137) GUISetBkColor(0xC0C0C0) GUISetOnEvent($GUI_EVENT_CLOSE, "_EXIT") $FileMenu = GUICtrlCreateMenu("File") $Exit = GUICtrlCreateMenuItem("Exit", $FileMenu) GUICtrlSetOnEvent($Exit, "_EXit") $View = GUICtrlCreateMenu("View") $About = GUICtrlCreateMenu("About") $prgView = GUICtrlCreateList("", 136, 21, 385, 136) GUICtrlCreateGroup("", 8, 16, 121, 236) $btn_open = GUICtrlCreateButton("Add Program", 16, 32, 105, 20, $WS_GROUP) GUICtrlSetOnEvent(-1, "_OPEN") $btn_delete = GUICtrlCreateButton("Delete Program", 16, 61, 105, 20, $WS_GROUP) GUICtrlSetOnEvent(-1, "_DEL") $Label2 = GUICtrlCreateLabel("Status : ", 24, 88, 43, 17) $lb_Status = GUICtrlCreateLabel("UnSaved", 72, 88, 49, 17) $freeInput = GUICtrlCreateInput("", 24, 136, 89, 21) $btn_SendEnter = GUICtrlCreateButton("Send < Enter >", 18, 224, 97, 20, $WS_GROUP) $btn_Send = GUICtrlCreateButton("Send", 48, 114, 33, 17, $WS_GROUP) $Group3 = GUICtrlCreateGroup("", 16, 104, 105, 65) GUICtrlCreateGroup("", -99, -99, 1, 1) $btn_SendTab = GUICtrlCreateButton("Send < Tab >", 18, 198, 97, 20, $WS_GROUP) $btn_Pause = GUICtrlCreateButton("Send < Pause >", 18, 172, 97, 20, $WS_GROUP) GUICtrlSetOnevent(-1, "_SendPause") GUICtrlCreateGroup("", -99, -99, 1, 1) $btn_Save = GUICtrlCreateButton("Save Settings", 148, 182, 105, 20, $WS_GROUP) GUICtrlSetOnEvent(-1, "_SAVE") $btn_Run = GUICtrlCreateButton("Run Programs", 148, 204, 105, 20, $WS_GROUP) GUICtrlSetOnEvent(-1, "_RUN") $btn_SaveWin = GUICtrlCreateButton("Save Win Cords", 148, 228, 105, 20, $WS_GROUP) GUICtrlSetOnEvent(-1, "_SaveWinCords") $Group1 = GUICtrlCreateGroup("", 136, 172, 137, 81) GUICtrlCreateGroup("", -99, -99, 1, 1) $timeInput = GUICtrlCreateInput("", 314, 210, 41, 21) $TimeLable = GUICtrlCreateLabel("Time Between Apps", 293, 192, 99, 17) $pwdConfirm = GUICtrlCreateInput("", 416, 228, 105, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) $pwdInput = GUICtrlCreateInput("", 416, 185, 105, 21, BitOR($ES_PASSWORD, $ES_AUTOHSCROLL)) $Label4 = GUICtrlCreateLabel("Password ", 440, 166, 59, 17, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman") $Label5 = GUICtrlCreateLabel("Confirm", 442, 210, 50, 17, $SS_CENTER) GUICtrlSetFont(-1, 10, 800, 0, "Times New Roman") $Group2 = GUICtrlCreateGroup("", 283, 180, 121, 65) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) Global $array[1] Global $win[1] Global $results[1] Global $iniFileName = @SCRIPTDIR & "\Cords.ini" Global $file = @ScriptDir & "\data.txt" Global $SaveToggle = 0 GuiCtrlSetData($TimeInput, "5") If FileExists ($File) Then For $A = 1 To _FileCountLines($file) GUICtrlSetData($prgView, FileReadLine($file, $A)) _ArrayAdd($array, FileReadLine($file, $A)) _ArrayAdd($win, -1) Next EndIf While 1 Sleep(100) WEnd ;-----------------------------------------OPEN------------------------- Func _Open() $fileOpen = FileOpenDialog("Save Dialog", @ProgramFilesDir, "(*.exe)") ; what ever is opened.. shoot it out to the end of the array. If @error = 0 Then _ArrayAdd($array, $fileOpen) _ArrayAdd($win, -1) For $A = 1 To (UBound($array) - 1) GUICtrlSetData($prgView, $array[$A]) Next EndIf EndFunc ;==>_Open Func _DEL() If FileExists ($File) = 0 Then MsgBox (16, 'Error','Data.txt does not exist.') Return @Error EndIf If GUICtrlRead($prgView) == "" Then Return 0 $SaveToggle = 0 $arrayfind = _ArraySearch($array, GUICtrlRead($prgView)) ConsoleWrite($arrayfind & @CRLF) _ArrayDelete($array, $arrayfind) _Refresh() EndFunc ;==>_DEL Func _RUN() If FileExists ($File) = 0 Then MsgBox (16, 'Error','Data.txt does not exist.') Return @Error EndIf For $A = 1 To (uBound($array) -1) If FileExists ($array[$A]) Then $exeName = _GetExeName ($array[$A]) ShellExecute ($array[$A]) ProcessWait ($exeName, 1000) Sleep (500) _ArrayInsert ($win, $a, WinGetTitle ('[ACTIVE]')) $x = IniRead ('Cords.ini', $win[$A], 'x', -1) $y = IniRead ('Cords.ini', $win[$A], 'y', -1) $w = IniRead ('Cords.ini', $win[$A], 'w', -1) $h = IniRead ('Cords.ini', $win[$A], 'h', -1) If $x <> -1 And $y <> -1 And $w <> -1 And $h <> -1 Then $move = WinMove ($win[$A], '', $x, $y, $w, $h) ;MsgBox (0, 'Debug', $move) EndIf $delay = GUICtrlRead ($timeInput) If $delay > 0 Then $delay = $delay * 1000 Else $delay = 5000 EndIf Sleep ($delay) EndIf Next EndFunc Func _Refresh() If FileExists ($File) = 0 Then MsgBox (16, 'Error','Data.txt does not exist.') Return @Error EndIf GUICtrlSetData($prgView, "") For $A = 1 To (UBound($array) - 1) GUICtrlSetData($prgView, $array[$A]) Next EndFunc ;==>_Refresh Func _SaveWinCords() If FileExists ($File) = 0 Then MsgBox (16, 'Error','Data.txt does not exist.') Return @Error EndIf For $A = 1 To (uBound($array) -1) If $win[$A] <> -1 Then If WinExists ($win[$A]) Then $pos = WinGetPos ($win[$A]) IniWrite ('Cords.ini', $win[$A], 'x', $pos[0]) IniWrite ('Cords.ini', $win[$A], 'y', $pos[1]) IniWrite ('Cords.ini', $win[$A], 'w', $pos[2]) IniWrite ('Cords.ini', $win[$A], 'h', $pos[3]) Else $win[$A] = -1 EndIf EndIf Next EndFunc ;--------------------------------------------SaveWin---------------------------------- Func _GetExeName ($Data) $Split = StringSplit ($Data, '\') Return $Split[$Split[0]] EndFunc ;--------------------------------------------SAV------------------------------------- ; saves all info that is stored in arrays to file... if the file already exist.. delete it and start over. Func _Save() $SaveToggle = 1 If FileExists($file) Then FileDelete($file) For $A = 1 To (UBound($array) - 1) FileWriteLine($file, $array[$A]) Next EndFunc ;==>_Save Func _SendPause() EndFunc Func _Exit() ;if the save button is not clicked.. then do the following. If $SaveToggle = 0 Then For $A = 1 To _FileCountLines($file) If FileReadLine($file, $A) <> $array[$A] Or _FileCountLines($file) <> (UBound($array) - 1) Then $exitAnswer = MsgBox(51, "Desktop Automator", "Do you want to save these settings?") If $exitAnswer = 2 Then Return 0 ElseIf $exitAnswer = 6 Then _Save() Exit ElseIf $exitAnswer = 7 Then Exit EndIf EndIf Next Exit ; saved button is pushed... exiting... ElseIf $SaveToggle = 1 Then Exit EndIf EndFunc Data.txt C:\Program Files\Internet Explorer\iexplore.exe C:\Windows\System32\calc.exe C:\Program Files\Windows Media Player\wmplayer.exe After you select "Run Programs" move the windows around, save the cords and then move them to another spot and close em. (So windows auto-save doesn't effect the results.) Thanks for any help in advance! - Joe Edit:* When I do a debug and check out the return value of WinMove () it returns the window handle which indicates a successful move. Edited April 6, 2010 by J03Z Link to comment Share on other sites More sharing options...
bo8ster Posted April 6, 2010 Share Posted April 6, 2010 I recommend putting Opt("MustDeclareVars", 1) at the top of ur script and trying to compile. Reson why: Line 14 - $file = GUICreate("Desktop Automator v1.0", 544, 281, 352, 137) Line 64 - Global $file = @ScriptDir & "\data.txt" Line 69 - If FileExists ($File) Then What is file? File is no the same as file. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
GEOSoft Posted April 6, 2010 Share Posted April 6, 2010 Would probably be just as well if he learned to use representive names for variables as well as in $Frm_Main = GUICreate("Desktop Automator v1.0", 544, 281, 352, 137) and $Btn_Go = GUICtrlCreateButton("Proceed",........) That makes finding the correct variable much easier later instead of getting 500 lines further into the code and asking yourself "What was the name of that button?" George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 6, 2010 Share Posted April 6, 2010 (edited) What is file? File is no the same as file. What are you talking about? AutoIt is NOT case sensitive. $abc = "1" _mSgbOX($aBc) $aBc = "2" _msgbox($Abc) _MSGBOX($abC) Func _msgbox($sText) MsgBox(0, "", $steXT) EndFunc In fact, when you compile a script everything get's uppercased! (or at least used to, don't know what happens nowadays) Edited April 6, 2010 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
bo8ster Posted April 6, 2010 Share Posted April 6, 2010 What are you talking about? AutoIt is NOT case sensitive. $abc = "1" _mSgbOX($aBc) $aBc = "2" _msgbox($Abc) _MSGBOX($abC) Func _msgbox($sText) MsgBox(0, "", $steXT) EndFunc In fact, when you compile a script everything get's uppercased! (or at least used to, don't know what happens nowadays) I was not aware that AutoIt is not case sensitive, I am use to using languages that are so I always use the correct case. Just another example of how mixing case is confusing even when it is permitted. This does not excuse using $file for GUICreate function and a file path. GEOSoft hit the nail on the head there. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic] Link to comment Share on other sites More sharing options...
GEOSoft Posted April 6, 2010 Share Posted April 6, 2010 AutoIt has never been case sensitive as far back as I can remember and it's been known to mess people up before. The only reason for using consistant case sensitivity in functions and variables is "pretty code". It also doesn't care about leading or trailing blank spaces unless they are quoted in which case they are not leading or trailing anyway. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
z0mgItsJohn Posted April 6, 2010 Share Posted April 6, 2010 I took the liberty of completely re-writing the code, and changing the GUI to my likings lol. (Don't worry, I've been helping Joe with this for a few weeks, so he doesn't mind.) New Code : expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) Opt("WinTitleMatchMode", 2) $GUI = GUICreate ("Desktop Automator v1.0", 490, 235) GUISetBkColor (0xC0C0C0) GUISetOnEvent ($GUI_EVENT_CLOSE, "_Exit") $fMenu = GUICtrlCreateMenu ("File") GUICtrlCreateMenuItem ("Exit", $fMenu) GUICtrlSetOnEvent (-1, "_Exit") $vMenu = GUICtrlCreateMenu ("View") $aMenu = GUICtrlCreateMenu ("About") $List = GUICtrlCreateList ("", 101, 22, 385, 136) GUICtrlCreateGroup ("", 5, 0, 92, 157) GUICtrlCreateButton ("Add Program", 8, 9, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Add") GUICtrlCreateButton ("Delete Selected", 8, 30, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Del") GUICtrlCreateButton ("Save Changes", 8, 51, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Save") GUICtrlCreateButton ("Run Programs", 8, 72, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Run") GUICtrlCreateButton ("Save Win Cords", 8, 93, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_SaveCords") GUICtrlCreateLabel ("Save Status :", 101, 5, 100, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Status = GUICtrlCreateLabel ("Saved", 190, 5, 86, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateGroup ("", 101, 157, 385, 54) $Custom = GUICtrlCreateInput ('', 104, 166, 150, 20, 1) GUICtrlCreateButton ("Send", 256, 166, 34, 20, $WS_GROUP) GUICtrlCreateLabel ("Delay Between Apps :", 104, 189, 105, 20) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Delay = GUICtrlCreateInput (5, 213, 187, 41, 20, 1) GUICtrlCreateLabel ("Password :", 300, 168, 80, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Pw = GUICtrlCreateInput ("", 378, 166, 105, 20, BitOr ($ES_PASSWORD, 1)) $cPw = GUICtrlCreateInput ("", 378, 187, 105, 20, BitOr ($ES_PASSWORD, 1)) GUICtrlCreateLabel ("Confirm P :", 300, 189, 80, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState (@SW_SHOW) Global $Path[1], $Win[1] Global $Save = @ScriptDir & "\Saved.txt", $Cord = @ScriptDir & "\Cords.ini" If FileExists ($Save) Then For $A = 1 To _FileCountLines ($Save) GUICtrlSetData ($List, StringLower (FileReadLine ($Save, $A))) _ArrayAdd ($Path, FileReadLine ($Save, $A)) _ArrayAdd ($Win, -1) Next EndIf While 1 Sleep(150) WEnd Func _Add () $File = FileOpenDialog ("Save Dialog", @ProgramFilesDir, "(*.exe)") If @Error = 0 Then _ArrayAdd ($Path, $File) _ArrayAdd ($Win, -1) _Refresh () GUICtrlSetData ($Status, "Not Saved *") EndIf EndFunc ;==>_Add Func _Del () If GUICtrlRead ($List) = '' Then Return 0 _ArrayDelete ($Path, _ArraySearch ($Path, GUICtrlRead ($List))) _Refresh() GUICtrlSetData ($Status, "Not Saved *") EndFunc ;==>_Del Func _Run () For $A = 1 To UBound ($Path) - 1 If FileExists ($Path[$A]) Then ShellExecute ($Path[$A]) ProcessWait (_GetExeName ($Path[$A]), 1000) Sleep (500) _ArrayInsert ($Win, $A, WinGetTitle ("[ACTIVE]")) $X = IniRead ($Cord, $Win[$A], 'X', -1) $Y = IniRead ($Cord, $Win[$A], 'Y', -1) $W = IniRead ($Cord, $Win[$A], 'W', -1) $H = IniRead ($Cord, $Win[$A], 'H', -1) If $X <> -1 And $Y <> -1 And $W <> -1 And $H <> -1 Then WinMove ($Win[$A], '', $X, $Y, $W, $H) If UBound ($Path) - 1 <> 1 Then If GUICtrlRead ($Delay) > 0 Then Sleep (GUICtrlRead ($Delay) * 1000) Else Sleep (5000) EndIf EndIf EndIf Next EndFunc ;==>_Run Func _Refresh() GUICtrlSetData ($List, "") For $A = 1 To UBound ($Path) - 1 GUICtrlSetData ($List, StringLower ($Path[$A])) Next EndFunc ;==>_Refresh Func _SaveCords() For $A = 1 To UBound ($Path) -1 If $Win[$A] <> -1 Then If WinExists ($Win[$A]) Then $Pos = WinGetPos ($Win[$A]) IniWrite ($Cord, $Win[$A], "X", $Pos[0]) IniWrite ($Cord, $Win[$A], "Y", $Pos[1]) IniWrite ($Cord, $Win[$A], "W", $Pos[2]) IniWrite ($Cord, $Win[$A], "H", $Pos[3]) Else $Win[$A] = -1 EndIf EndIf Next EndFunc ;==>_SaveCords Func _GetExeName ($Data) $Split = StringSplit ($Data, '\') Return $Split[$Split[0]] EndFunc ;==>_GetExeName Func _Save () If FileExists ($Save) Then FileDelete ($Save) For $A = 1 To UBound ($Path) - 1 FileWriteLine ($Save, $Path[$A]) Next GUICtrlSetData ($Status, "Saved") Sleep (1000) EndFunc ;==>_Save Func _Exit () If GUICtrlRead ($Status) = "Not Saved *" Then If MsgBox (BitOr (4, 32), "Desktop Automator","Do you want to save your changes?") = 6 Then _Save () EndIf Exit EndFunc ;==>_Exit Also Data.txt has been re-named to Saved.txt. Saved.txt C:\Program Files\Internet Explorer\iexplore.exe C:\Windows\System32\calc.exe C:\Program Files\Windows Media Player\wmplayer.exe It's all in order and looks pretty, yet WinMove () still won't work on Internet Explorer even tho it returns the handle indicating a successful move. - John Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
J03Z Posted April 7, 2010 Author Share Posted April 7, 2010 Thanks Jon, for re-writing my code. The problem is still apparent . Any ides from anyone else ? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2010 Moderators Share Posted April 7, 2010 J03Z,Any ides from anyone else ?Yes. Have you actually looked at your Cords.ini file? When I run your code I do not get any coordinates saved for IE. And why? Because you are expecting the window to be called "Windows Internet Explorer" (at least that is what you have in the $Win array) while my IE window title includes the URL I am currently browsing plus a whole lot more. So you do not save the coordinates of the IE window and therefore have nothing to use as parameters for WinMove.How to remedy this? Save the Windows handle rather than the name. How to do this? You know the process name, so use ProcessList to get all the processes and search for yours - you now have a PID. Use WinList to get the windows. Then use WinGetProcess to retrieve the PID. When you find a match you have the window handle. Easy really! Have fun with that for a while - you know where we are if you run into problems. 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...
z0mgItsJohn Posted April 7, 2010 Share Posted April 7, 2010 (edited) WinGetTitle ("[ACTIVE]") should return the correct window name, and even if it is "Windows Internet Explorer" Opt ("WinTitleMatchMode", 2) should fix it assuming the window contains "Windows Internet Explorer" and saving the handle of the window would defeat the purpose because each time the window is ran it has an new handle correct? We want it so a user can place windows a certain way, and re-size them and be able to save that data and then re-load it next time. Also, where are we expecting the window to be named "Windows Internet Explorer" $Win[$A] is by default set to -1 and once the program is ran it waits for the process to exist, waits 500 milliseconds and then sets $Win[$A] to WinGetTitle ("[ACTIVE]") and then when the SaveCords function is called it saves the x, y, w, h from the windows if they exist. Making any since? - John Edit : We've also tried a different method of getting the window of the process using WinList () and that would always return something different for iexplorer.exe (Or w/e the process is for internet explorer.) Here's the code we used to get the window named based off of the process : If the window is visible and it's title is not ''. If the pid of the window is equal to the pid submitted to the function, return the name of that window. Func _ProcessGetWin ($PID) $List = WinList () For $A = 1 To $List[0][0] If BitAnd (WinGetState ($List[$A][0]), 2) And $List[$A][1] <> '' Then If WinGetProcess ($List[$A][0]) = $PID Then Return $List[$A][1] EndIf EndFunc Edited April 7, 2010 by John2010zz Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
GEOSoft Posted April 7, 2010 Share Posted April 7, 2010 J03Z,How to remedy this? Save the Windows handle rather than the name. Easy really! Have fun with that for a while - you know where we are if you run into problems. M23Or set WinTitleMatchModeOpt("WinTitleMatchMode", 2) and remember titles are case sensitive. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 8, 2010 Moderators Share Posted April 8, 2010 (edited) John2010zz You are correct, the handle idea was not a good one - put it down to tiredness! where are we expecting the window to be named "Windows Internet Explorer"Have you actually checked the contents of the $Win array? I can assure you it reads "Windows Internet Explorer" on my machine. The reason the window title is saved as that is because you are reading the title of the IE window too soon. I grant you that the initial window has that title - but this is before the preset home page is loaded, 500ms is too fast. By the time you want to reset the position, the title has changed to what ever IE displays for that home page - and so when you save the coordinates you cannot identify the window. You need to wait a bit longer before saving the title of the window. Try changing your _Run function to read like this: Func _Run () For $A = 1 To UBound ($Path) - 1 If FileExists ($Path[$A]) Then $InitialTitle = _GetExeName ($Path[$A]) ShellExecute ($Path[$A]) ProcessWait ($InitialTitle, 1000) Sleep(500) If $InitialTitle = "iexplore.exe" Then Sleep (2000) $Win[$A] = WinGetTitle ("[ACTIVE]") ; Set the actual element rather than inserting $X = IniRead ($Cord, $Win[$A], 'X', -1) $Y = IniRead ($Cord, $Win[$A], 'Y', -1) $W = IniRead ($Cord, $Win[$A], 'W', -1) $H = IniRead ($Cord, $Win[$A], 'H', -1) If $X <> -1 And $Y <> -1 And $W <> -1 And $H <> -1 Then WinMove ($Win[$A], '', $X, $Y, $W, $H) If UBound ($Path) - 1 <> 1 Then If GUICtrlRead ($Delay) > 0 Then Sleep (GUICtrlRead ($Delay) * 1000) Else Sleep (5000) EndIf EndIf EndIf Next EndFunc ;==>_Run Now if IE is the app started, it waits a few seconds before saving the window name - giving the home page time to load. You may be able to reduce this - perhaps by checking to see if the title is no longer "Windows Internet Explorer"! The WinMove command works fine with IE for me now - and with the other apps. How about you? M23 Edit: Clarity, I hope! Edited April 8, 2010 by Melba23  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...
J03Z Posted April 8, 2010 Author Share Posted April 8, 2010 John2010zz You are correct, the handle idea was not a good one - put it down to tiredness! Have you actually checked the contents of the $Win array? I can assure you it reads "Windows Internet Explorer" on my machine. The reason the window title is saved as that is because you are reading the title of the IE window too soon. I grant you that the initial window has that title - but this is before the preset home page is loaded, 500ms is too fast. By the time you want to reset the position, the title has changed to what ever IE displays for that home page - and so when you save the coordinates you cannot identify the window. You need to wait a bit longer before saving the title of the window. Try changing your _Run function to read like this: Func _Run () For $A = 1 To UBound ($Path) - 1 If FileExists ($Path[$A]) Then $InitialTitle = _GetExeName ($Path[$A]) ShellExecute ($Path[$A]) ProcessWait ($InitialTitle, 1000) Sleep(500) If $InitialTitle = "iexplore.exe" Then Sleep (2000) $Win[$A] = WinGetTitle ("[ACTIVE]") ; Set the actual element rather than inserting $X = IniRead ($Cord, $Win[$A], 'X', -1) $Y = IniRead ($Cord, $Win[$A], 'Y', -1) $W = IniRead ($Cord, $Win[$A], 'W', -1) $H = IniRead ($Cord, $Win[$A], 'H', -1) If $X <> -1 And $Y <> -1 And $W <> -1 And $H <> -1 Then WinMove ($Win[$A], '', $X, $Y, $W, $H) If UBound ($Path) - 1 <> 1 Then If GUICtrlRead ($Delay) > 0 Then Sleep (GUICtrlRead ($Delay) * 1000) Else Sleep (5000) EndIf EndIf EndIf Next EndFunc ;==>_Run Now if IE is the app started, it waits a few seconds before saving the window name - giving the home page time to load. You may be able to reduce this - perhaps by checking to see if the title is no longer "Windows Internet Explorer"! The WinMove command works fine with IE for me now - and with the other apps. How about you? M23 Edit: Clarity, I hope! This makes perfect since. I will try this when I make it home. Link to comment Share on other sites More sharing options...
z0mgItsJohn Posted April 9, 2010 Share Posted April 9, 2010 Ah I see what you mean.. sometimes it would return Homepage - Windows Internet Explorer, and others Windows Internet Explorer.. thanks for the help! Latest Projects :- New & Improved TCP Chat Link to comment Share on other sites More sharing options...
J03Z Posted April 19, 2010 Author Share Posted April 19, 2010 Melba23 I am using the code below and for some reason, it moved the internet explorer window to the correct cords 1 time.. and it never worked since. I am baffled by this, no code was changed, Today was my first day to make it to the forums because of my schedule. Im using win7. What other suggestions do you have. Any help pointing me even further into the right direction would be appreciated. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> #include <Process.au3> Opt("GUIOnEventMode", 1) Opt("WinTitleMatchMode", 2) $GUI = GUICreate ("Desktop Automator v1.0", 490, 235) GUISetBkColor (0xC0C0C0) GUISetOnEvent ($GUI_EVENT_CLOSE, "_Exit") $fMenu = GUICtrlCreateMenu ("File") GUICtrlCreateMenuItem ("Exit", $fMenu) GUICtrlSetOnEvent (-1, "_Exit") $vMenu = GUICtrlCreateMenu ("View") $aMenu = GUICtrlCreateMenu ("About") $List = GUICtrlCreateList ("", 101, 22, 385, 136) GUICtrlCreateGroup ("", 5, 0, 92, 157) GUICtrlCreateButton ("Add Program", 8, 9, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Add") GUICtrlCreateButton ("Delete Selected", 8, 30, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Del") GUICtrlCreateButton ("Save Changes", 8, 51, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Save") GUICtrlCreateButton ("Run Programs", 8, 72, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_Run") GUICtrlCreateButton ("Save Win Cords", 8, 93, 86, 20, $WS_GROUP) GUICtrlSetOnEvent (-1, "_SaveCords") GUICtrlCreateLabel ("Save Status :", 101, 5, 100, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Status = GUICtrlCreateLabel ("Saved", 190, 5, 86, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlCreateGroup ("", 101, 157, 385, 54) $Custom = GUICtrlCreateInput ('', 104, 166, 150, 20, 1) GUICtrlCreateButton ("Send", 256, 166, 34, 20, $WS_GROUP) GUICtrlCreateLabel ("Delay Between Apps :", 104, 189, 105, 20) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Delay = GUICtrlCreateInput (5, 213, 187, 41, 20, 1) GUICtrlCreateLabel ("Password :", 300, 168, 80, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) $Pw = GUICtrlCreateInput ("", 378, 166, 105, 20, BitOr ($ES_PASSWORD, 1)) $cPw = GUICtrlCreateInput ("", 378, 187, 105, 20, BitOr ($ES_PASSWORD, 1)) GUICtrlCreateLabel ("Confirm P :", 300, 189, 80, 17) GUICtrlSetFont (-1, 9, 600) GUICtrlSetBkColor (-1, $GUI_BKCOLOR_TRANSPARENT) GUISetState (@SW_SHOW) Global $Path[1], $Win[1] Global $Save = @ScriptDir & "\Saved.txt", $Cord = @ScriptDir & "\Cords.ini" If FileExists ($Save) Then For $A = 1 To _FileCountLines ($Save) GUICtrlSetData ($List, StringLower (FileReadLine ($Save, $A))) _ArrayAdd ($Path, FileReadLine ($Save, $A)) _ArrayAdd ($Win, -1) Next EndIf While 1 Sleep(150) WEnd Func _Add () $File = FileOpenDialog ("Save Dialog", @ProgramFilesDir, "(*.exe)") If @Error = 0 Then _ArrayAdd ($Path, $File) _ArrayAdd ($Win, -1) _Refresh () GUICtrlSetData ($Status, "Not Saved *") EndIf EndFunc ;==>_Add Func _Del () If GUICtrlRead ($List) = '' Then Return 0 _ArrayDelete ($Path, _ArraySearch ($Path, GUICtrlRead ($List))) _Refresh() GUICtrlSetData ($Status, "Not Saved *") EndFunc ;==>_Del Func _Run () For $A = 1 To UBound ($Path) - 1 If FileExists ($Path[$A]) Then $InitialTitle = _GetExeName ($Path[$A]) ShellExecute ($Path[$A]) ProcessWait ($InitialTitle, 1000) Sleep(500) If $InitialTitle = "iexplore.exe" Then Sleep (2000) $Win[$A] = WinGetTitle ("[ACTIVE]") ; Set the actual element rather than inserting $X = IniRead ($Cord, $Win[$A], 'X', -1) $Y = IniRead ($Cord, $Win[$A], 'Y', -1) $W = IniRead ($Cord, $Win[$A], 'W', -1) $H = IniRead ($Cord, $Win[$A], 'H', -1) If $X <> -1 And $Y <> -1 And $W <> -1 And $H <> -1 Then WinMove ($Win[$A], '', $X, $Y, $W, $H) If UBound ($Path) - 1 <> 1 Then If GUICtrlRead ($Delay) > 0 Then Sleep (GUICtrlRead ($Delay) * 1000) Else Sleep (5000) EndIf EndIf EndIf Next EndFunc ;==>_Run Func _Refresh() GUICtrlSetData ($List, "") For $A = 1 To UBound ($Path) - 1 GUICtrlSetData ($List, StringLower ($Path[$A])) Next EndFunc ;==>_Refresh Func _SaveCords() For $A = 1 To UBound ($Path) -1 If $Win[$A] <> -1 Then If WinExists ($Win[$A]) Then $Pos = WinGetPos ($Win[$A]) IniWrite ($Cord, $Win[$A], "X", $Pos[0]) IniWrite ($Cord, $Win[$A], "Y", $Pos[1]) IniWrite ($Cord, $Win[$A], "W", $Pos[2]) IniWrite ($Cord, $Win[$A], "H", $Pos[3]) Else $Win[$A] = -1 EndIf EndIf Next EndFunc ;==>_SaveCords Func _GetExeName ($Data) $Split = StringSplit ($Data, '\') Return $Split[$Split[0]] EndFunc ;==>_GetExeName Func _Save () If FileExists ($Save) Then FileDelete ($Save) For $A = 1 To UBound ($Path) - 1 FileWriteLine ($Save, $Path[$A]) Next GUICtrlSetData ($Status, "Saved") Sleep (1000) EndFunc ;==>_Save Func _Exit () If GUICtrlRead ($Status) = "Not Saved *" Then If MsgBox (BitOr (4, 32), "Desktop Automator","Do you want to save your changes?") = 6 Then _Save () EndIf Exit EndFunc ;==>_Exit 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