itsmeagain_ Posted April 20, 2013 Posted April 20, 2013 The AutoIt Window Info tools shows at the top "Basic Window Info" and gives us the title and class of the currently active window.I want to do just that, get the title and class (that the info tool also shows) of the currently active window. To clarify, I marked the strings that I'm after in this screenshot:It's simple to get the title:Local $wintitle = WinGetTitle("[ACTIVE]")But how do I get the class?Cheers!
water Posted April 20, 2013 Posted April 20, 2013 Why would you need to retrieve the class of a window at runtime? My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
johnmcloud Posted April 20, 2013 Posted April 20, 2013 #include <WinAPI.au3> $hwnd = WinGetHandle("[ACTIVE]") MsgBox(0, 0, "Title is: " & WinGetTitle($hwnd) & @CRLF & "Class is: " & _WinAPI_GetClassName($hwnd))
water Posted April 20, 2013 Posted April 20, 2013 BTW: Looks like you use an older version of AutoIt. Don't know which one but when using the latest (3.3.8.1) you get a lot of bugs removed and best help on the forum because most of the users here use the latest version. My UDFs and Tutorials: Reveal hidden contents UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
itsmeagain_ Posted April 20, 2013 Author Posted April 20, 2013 (edited) On 4/20/2013 at 11:50 AM, 'johnmcloud said: #include <WinAPI.au3> $hwnd = WinGetHandle("[ACTIVE]") MsgBox(0, 0, "Title is: " & WinGetTitle($hwnd) & @CRLF & "Class is: " & _WinAPI_GetClassName($hwnd)) Thanks! Works like a charm, I knew this would be easy for an AutoIt veteran . On 4/20/2013 at 11:53 AM, 'water said: BTW: Looks like you use an older version of AutoIt. Don't know which one but when using the latest (3.3.8.1) you get a lot of bugs removed and best help on the forum because most of the users here use the latest version. Thanks, but I just took the screenshot from the docs and added the red arrow, I downloaded the latest version from the AutoIt homepage . But what I want to for those that are curious: I want to change screens (either PC monitor or TV) based on whether a certain application (XBMC) is active. Because XBMC is a full screen app the Window Info tool showed only 2 ways to identify whether XBMC is active or not, namely the active window title being "XBMC" and the class "XBMC". If I based my script on just the window title the script would change between monitor / TV when I have a folder called XBMC open in windows explorer for example, that's why I want the class as an extra check. Anyways, this is my final script, if you have any remarks I would love to hear them (and I assume there are quite some ways to make it shorter and cleaner) #include Local $wintitle, $winclass, $lastcheck = "ACTIVE" While 1 $hwnd = WinGetHandle("[ACTIVE]") $wintitle = WinGetTitle($hwnd) $winclass = _WinAPI_GetClassName($hwnd) If $wintitle = "XBMC" AND $winclass = "XBMC" AND $lastcheck = "NOTACTIVE" Then ; XBMC is active now, but wasn't at last check, change output to TV! ShellExecute("DisplaySwitch.exe", "/internal", "C:\Windows\System32\") ElseIf $wintitle <> "XBMC" OR $winclass <> "XBMC" AND $lastcheck = "ACTIVE" Then ; XBMC not active now, but was at last check, change output to PC! ShellExecute("DisplaySwitch.exe", "/external", "C:\Windows\System32\") Endif If $wintitle = "XBMC" AND $winclass = "XBMC" Then $lastcheck = "ACTIVE" Else $lastcheck = "NOTACTIVE" Endif Sleep(250) WEnd. EDIT: I totally went in another direction with this (because I couldn't get the right resolution as XBMC outputs to the wrong monitor on startup, so nevermind. Thanks for the help though! Edited April 20, 2013 by itsmeagain_
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