Sign in to follow this  
Followers 0
itsmeagain_

Get the Window's class

5 posts in this topic

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:

Posted Image

It's simple to get the title:

Local $wintitle = WinGetTitle("[ACTIVE]")

But how do I get the class?

Cheers!

Share this post


Link to post
Share on other sites



Why would you need to retrieve the class of a window at runtime?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

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:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

#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 :thumbsup: .

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 by itsmeagain_

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0