Jump to content

How To Detect If Windows Explorer Window Is Currently Active Window


Recommended Posts

maybe

; get Active Window  (Title)(Text)
; Author - SmOke_N & Valuater

Sleep(5000); set active window for testing

$MyText = WinGetText(FindActiveWindow())
$MyTitle = WinGetTitle(FindActiveWindow())
MsgBox(0, $MyTitle, $MyText)

Func FindActiveWindow()
    Local $HidOpt = Opt("WinDetectHiddenText", 1);0=don't detect, 1=do detect
    Local $w_WinList = WinList()
    For $i = 1 to $w_WinList[0][0]
      If $w_WinList[$i][0] <> "" AND BitAnd(WinGetState($w_WinList[$i][1]), 2) _
          And BitAnd(WinGetState($w_WinList[$i][1]), 8) Then Return $w_WinList[$i][0]
      Next
    Opt("WinDetectHiddenText", $HidOpt)
EndFunc


; and.................

$iPID = WinGetProcess ( $MyTitle, $MyText)

#include <Process.au3>
$name = _ProcessGetName ( $iPID )

MsgBox(0, $MyTitle, $name)

8)

NEWHeader1.png

Link to comment
Share on other sites

Since Windows Explorer dynamically changes it's title depending on which folder it's in, i can't use the regular WinActive() function to detect it. is there another way?

Here is the short answer:

AutoItSetOption("WinTitleMatchMode", 4)

While 1
    If WinActive("classname=ExploreWClass") _
        Or WinActive("classname=CabinetWClass") Then
        ToolTip("Explorer Window is Active")
    Else
        ToolTip("")
    EndIf
    Sleep(88)
WEnd

Here is the (very) long answer:

I wrote that code while Valuater was posting... but I wanted to read the help file on WinTitleMatchMode option 4 and classname. I did not understand what I read, so I did not make the post. Also, I originally used a MsgBox in the code and it made things a bit messy attempting to determine when the test window was active... yet another reason not to post any code.

I chased some other rabbits (translation - I had a class to go to). When I got back to this, I used a ToolTip and convinced myself that the code works for the various explorer views that I can bring up using the classic view for XP SP2.

Now dwaynek, if you don't mind - I'm going to hijack your thread and ask my own question of those in the forum. The "AutoIt Window Info" shows various values for ClassNameNN within an explorer window and one value for Class. Can someone explain the difference between those two terms and maybe tell me what section of the help file was supposed to convey that I could use the value labeled "Class" like this "classname=ExploreWClass"? Sorry if the question is unclear - the topic is unclear for me.

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Depending on your flow, another option would be to get the HWND of the explorer window when you CAN identify it (like when it is created) and then use the HWND with WinActive.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

  • Moderators

If there was a search done: "Windows Explorer" you would have found this: http://www.autoitscript.com/forum/index.ph...ndpost&p=164448

I took the same approach as plato did... but at that time did not know about CabinetWClass.

@plato... I would assume that one is the "Windows Class" and the other is the "Control Class", of course I'd love to see the real answer myself :think:

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.

Link to comment
Share on other sites

If there was a search done: "Windows Explorer" you would have found this: http://www.autoitscript.com/forum/index.ph...ndpost&p=164448

I took the same approach as plato did... but at that time did not know about CabinetWClass.

@plato... I would assume that one is the "Windows Class" and the other is the "Control Class", of course I'd love to see the real answer myself :think:

Funny, I found that post while composing my post. (I searched for CabinetWClass.) I referenced it (in a very wordy paragraph) in my reply but took it out to make that post shorter. I had wondered if others had found other values for "Class" using other views of explorer:

CabinetWClass = right click on "my computer" and select open

ExploreWClass = right click on "my computer" and select explore

Make a folder on the desktop.

Double click = CabinetWClass

Make the folders show like a classic two pane view and it is still a CabinetWClass

(So, whatever class you were born to......)

I know that it should not be much of a leap to go from the label "Class:" under the section named:

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

to the instructions in the help file under Window Titles and Text (Advanced):

Mode 4

Advanced mode.

In this mode special sequences are used in the title parameter so that window classnames and handles can be used. The text parameter remains the same.

The special sequences must contain no whitespace. They are:

"classname=CLASSNAME"

"active"

.....

but sadly, I never made that leap (small step) until today... even worse, I've looked at this more than once. Oh well, enough with the confessions of stupidity (for today).

On the one hand, I can only hope that this discussion helps someone else...

On the other hand, I hope that no one else is that dense...

On the third hand (okay, I cannot tie that to "Click and Clack's" - "On the third half of our show...")

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

  • 2 years later...

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...