marcdr Posted January 25, 2006 Posted January 25, 2006 Hi All, i'm new to using window handles to get the windows for my scripts. I have been using the title of the window in my scripts so far but I want to run more scripts at the same time. The problem is that I want to have 3 windows of the same program open. Below is what I have been using to get the window handle, but the last 7 characters change everytime a new program window is opened. How can I get the window handle if the class name keep changing?? Thanks in advance Marc if WinExists("Classname=Afx:400000:8:10011:0:186038f") Then $SiebMain=WinGetHandle("Classname=Afx:400000:8:10011:0:186038f") Else msgbox(0, "", "Siebel Window not found") EndIf
Moderators SmOke_N Posted January 25, 2006 Moderators Posted January 25, 2006 Opt('WinTitleMatchMode', 4) if WinExists("Classname=Afx:400000:8:10011:0:") Then $SiebMain=WinGetHandle("Classname=Afx:400000:8:10011:0:") Else msgbox(0, "", "Siebel Window not found") EndIf Did you try that? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
marcdr Posted January 25, 2006 Author Posted January 25, 2006 Yes I tried that and it still doesn't work, the Opt("Wintitlematchmode", 4) is further up in my code.
Moderators SmOke_N Posted January 25, 2006 Moderators Posted January 25, 2006 Yes I tried that and it still doesn't work, the Opt("Wintitlematchmode", 4) is further up in my code.Errr... Yeh, I figured you might have WinTitleMatchMode, 4 --- Because you were using classname= ... but your saying it doesn't work if you trim the last 7? I don't see that being possible unless you have multiple windows with the same type of class. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
marcdr Posted January 25, 2006 Author Posted January 25, 2006 Errr... Yeh, I figured you might have WinTitleMatchMode, 4 --- Because you were using classname= ... but your saying it doesn't work if you trim the last 7? I don't see that being possible unless you have multiple windows with the same type of class.The windows are from the same class. I want 3 instances of the same program open at the same time. Is there any way to get a unique identifier for each of the windows as the titles are the same but the class name keeps changing.
Moderators SmOke_N Posted January 25, 2006 Moderators Posted January 25, 2006 If the window has something in each title that is common (which is what I think I'm understanding) you might be able to use this. #include <array.au3> Opt('WinTitleMatchMode', 2) $WinHandles = GetWinHandles('Some Part Of the Title That is always present') _ArrayDisplay($WinHandles, 'Win Unique Window Handles') Func GetWinHandles($t_TITLE) Local $WIN = WinList() Local $MakeList = '' For $i = 1 to $WIN[0][0] If StringInStr($WIN[$i][0], $t_TITLE) And $WIN[$i][0] <> "" And StringInStr($MakeList, Chr(01) & $WIN[$i][1]) = 0 And WinVisible($WIN[$i][1]) Then $MakeList = $MakeList & $WIN[$i][1] & Chr(01) EndIf Next Return StringSplit(StringTrimRight($MakeList, 1), Chr(01)) EndFunc ;==>GetWinHandles Func WinVisible($HWND) If BitAnd(WinGetState($HWND), 2) Then Return 1 EndIf Return 0 EndFunc ;==>WinVisible Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Helge Posted January 25, 2006 Posted January 25, 2006 ..I want 3 instances of the same program open at the same time...Check out my brand new UDF called http://www.autoitscript.com/fileman/users/Helge/udfs.htm.It's nothing fancy, but it will hopefully help you.
marcdr Posted January 26, 2006 Author Posted January 26, 2006 Check out my brand new UDF called http://www.autoitscript.com/fileman/users/Helge/udfs.htm.It's nothing fancy, but it will hopefully help you.Thanks for the link to the code. It still doesn't get around my problem of the window titles being the same, unless i'm using it wrong. The title of the window I want 3 instances of has the same title every time it is opened. I thought I could use the window handles to get different windows.
Helge Posted January 26, 2006 Posted January 26, 2006 Quick code to show you basically how to do it.. $pid1 = Run() $pid2 = Run() $pid3 = Run() $hwnd1 = _ProcessGetHWnd($pid1) $hwnd2 = _ProcessGetHWnd($pid2) $hwnd3 = _ProcessGetHWnd($pid3)
marcdr Posted January 26, 2006 Author Posted January 26, 2006 Quick code to show you basically how to do it.. $pid1 = Run() $pid2 = Run() $pid3 = Run() $hwnd1 = _ProcessGetHWnd($pid1) $hwnd2 = _ProcessGetHWnd($pid2) $hwnd3 = _ProcessGetHWnd($pid3) Thanks for the help. I've sort of managed to get it working. Marc
Moderators SmOke_N Posted January 26, 2006 Moderators Posted January 26, 2006 Thanks for the help. I've sort of managed to get it working.MarcSince you were the one that started the thread, can you post what you did to get it working so others that run into the same situation, and find this thread through the illustrious search feature may find an answer they are looking for?Congrats, on finding a solution. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
marcdr Posted January 31, 2006 Author Posted January 31, 2006 I managed to get around my problem by using Helge's ProcessGetHWnd code. I didn't want 1 script to run the same program 3 times. I wanted 3 scripts to run 1 instance each of the same program and do different things. So I used Helge's code to get the window handle for each instance of the program. $File='C:\sea\.......';program you want to run $iPid=run($File) WinWait("Siebel-CHEP CRM R4.1", "") If Not WinActive("Siebel-CHEP CRM R4.1", "") Then WinActivate("Siebel-CHEP CRM R4.1", "") WinWaitActive("Siebel-CHEP CRM R4.1", "") Send("xxxxxxx{TAB}xxxxxxxx{ENTER}") sleep(1000) $Title="Siebel-CHEP CRM R4.1 - My Teams Activities" winwait($Title, "") $HWND = _ProcessGetHWnd($iPid) winactivate($HWND, "") ;************************** ;change position to TDM WinWait($HWND, "") If Not WinActive($HWND, "") Then WinActivate($HWND, "") WinWaitActive($HWND, "") Send("{ALTDOWN}eg{ALTUP}") $handle = WinGetHandle("Change Postition") WinWait($handle, "") If Not WinActive($handle, "") Then WinActivate($handle, "") WinWaitActive($handle, "") Send("{DOWN}{DOWN}{ENTER}") I used the $HWND everytime I wanted to access the main window of each instance of the program. I used $handle for windows within the main window, eg 'save as'
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