Jump to content

Recommended Posts

Posted

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!

Posted

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

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

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

 

Posted (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 :thumbsup: .

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...