Jump to content

Get current window class


Recommended Posts

I think this may have a short answer but can't seem to land on it. How to you get the current window's class?

WinGetClassList doesn't work. What I want to do, is get the class of the active window and then close all windows of that class. The below works, but I think is sloppy, there has to be a better way.

Thanks in advance for help with this simple question.

func closegroup()

If WinActive("[CLASS:ExploreWClass]") Then $classed="[CLASS:ExploreWClass]"

If WinActive("[CLASS:CabinetWClass]") Then $classed="[CLASS:CabinetWClass]"

If WinActive("[CLASS:AcrobatSDIWindow]") Then $classed="[CLASS:AcrobatSDIWindow]"

If WinActive("[CLASS:IEFrame]") Then $classed="[CLASS:IEFrame]"

If WinActive("[CLASS:XLMAIN]") Then $classed="[CLASS:XLMAIN]"

local $var = WinList($classed)

For $i = 0 to $var[0][0]

WinClose($classed, "")

sleep(400)

Next

EndFunc

This could end up being a really long list and even then you will miss some.

Link to comment
Share on other sites

I think this may have a short answer but can't seem to land on it. How to you get the current window's class?

WinGetClassList doesn't work. What I want to do, is get the class of the active window and then close all windows of that class. The below works, but I think is sloppy, there has to be a better way.

Thanks in advance for help with this simple question.

func closegroup()

If WinActive("[CLASS:ExploreWClass]") Then $classed="[CLASS:ExploreWClass]"

If WinActive("[CLASS:CabinetWClass]") Then $classed="[CLASS:CabinetWClass]"

If WinActive("[CLASS:AcrobatSDIWindow]") Then $classed="[CLASS:AcrobatSDIWindow]"

If WinActive("[CLASS:IEFrame]") Then $classed="[CLASS:IEFrame]"

If WinActive("[CLASS:XLMAIN]") Then $classed="[CLASS:XLMAIN]"

local $var = WinList($classed)

For $i = 0 to $var[0][0]

WinClose($classed, "")

sleep(400)

Next

EndFunc

This could end up being a really long list and even then you will miss some.

Another way could be:

#include <WinAPI.au3>

$hwnd= WinGetHandle("[active]")
MsgBox(4096, "Get ClassName", "ClassName of " & $hwnd & ": " & _WinAPI_GetClassName($hwnd))
Link to comment
Share on other sites

Thanks for the fast replies! I knew there was a simple solution but couldn't find it. The below is my final script

func closegroup()

$hwnd= WinGetHandle("[active]")

$classed = _WinAPI_GetClassName($hwnd)

local $var = WinList("[CLASS:"&$classed&"]")

For $i = 0 to $var[0][0]

WinClose("[CLASS:"&$classed&"]", "")

sleep(400)

Next

EndFunc

Link to comment
Share on other sites

  • 2 years later...

Sorry I make comment here late.

Just tell who haven't known.

I've just known the available tool to define class of windows, button and other properties. It's Au3Info, default as "C:Program FilesAutoIt3Au3Info.exe"

Drag and drop Finder Tool into object we need to know, we will have the answer.

Posted Image

Link to comment
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
 Share

  • Recently Browsing   0 members

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