PDA

View Full Version : How to do a function ONLY if a window is open...need help...



Protocol
10-19-2004, 09:29 AM
Hey guys,

I've been attempting to do a specific function only if a specific window is the TOP Z-order.

In other words, only if Internet Explorer is the TOP-most (active window), do XYZ.

So far I can do it if it's running, but I can't find out if it's the active window:

AllWindows = Window.EnumerateTitles();
Ignore = "Internet Explorer";
for CurrentHandle, title in AllWindows do
TitleSearch = String.Find(title, Ignore, 1, false);
if (TitleSearch ~= -1) then
Window.Minimize(CurrentHandle);
end
end

Any ideas guys?

Protocol

Protocol
10-20-2004, 08:25 AM
:huh
:huh
:huh

Josué Alba
10-20-2004, 08:30 AM
well you can search the froum or go to:
http://www.indigorose.com/forums/showthread.php?t=8475&highlight=close+window

Protocol
10-20-2004, 08:44 AM
Thanks Jos,

But that's just the problem. I've found a lot of posts as well as a great example in the help file in regards to finding out if a window is open, but nothing in regards to wether or not the window is the ACTIVE window (the highest Z-order).

This is important to make sure I don't close or in any way alter an active window if the user is currently looking at it.

Any ideas as to how to find out what the active window is?

Thanks again...


Protocol

Josué Alba
10-20-2004, 09:29 AM
Ohoho, sorry I need to read carefullier.
but I think corey made an example using Z-order but I couldn't found it. I'll have it at home. so if you cannot found it tell me and I'll send it to you.

Protocol
10-20-2004, 01:29 PM
That's be great...thanks Jos!

:D

Worm
10-20-2004, 02:18 PM
ActiveWindowHandle = String.ToNumber(DLL.CallFunction(_SystemFolder.."\\User32.dll", "GetForegroundWindow", "", DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL))

Protocol
10-20-2004, 05:22 PM
Can it be said enough?

Worm...You...Are...The...Man. :yes

:D

Thank you both!

Protocol

Protocol
10-20-2004, 07:44 PM
Have I got it wrong:

TopWindow = DLL.CallFunction(_SystemFolder.."\\User32.dll", "GetForegroundWindow", "", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
Dialog.Message("Notice", TopWindow, MB_OK, MB_ICONINFORMATION, MB_DEFBUTTON1);

This just pops up a 6-digit number. A seemingly random one at that. =(

So how would I get it to respond from that data? What I want to do is:

If Internet Explorer is the TOP window, do nothing...but if it's NOT the TOP window...do something. :huh

Thanks for your help... =|

Protocol

Josué Alba
10-20-2004, 09:32 PM
Well I think the 6 numbers are the window handler. The bad news are that I have never been good enoght with that. sorry pal

SUF6NEWBIE
10-20-2004, 10:20 PM
The return 'integer' from the dll call is the actual 'window handle'

you can then control the window with any of the available actions
relating to Windows (consult the help docs- examples) in this regard.

eG: Window.Close(ActiveWindowHandle);

..just check this action syntax and other options etc

you just need to refer to the returned window handle in the action to perform

Protocol
10-21-2004, 12:57 PM
Thanks for the suggestions and the code guys... :)

The only problem is that I still need to recognize the currently TOP window. From what I've tested, these windows handles don't say which is the TOP window. They may help in deciding which window was opened first, but not the currently active one.

Again, what I'm trying to do is:

1) Look at which window is the active window.

2) Either get the name of that window such as "Internet Explorer" (or even better) get the program name that runs that window (in case it's a pop-up that isn't called "Internet Explorer", but is still using Internet Explorer to view it).

3) If the name of the window or name of the program running the window is on a given "ignore list", then do nothing. Otherwise, if it's not on the "ignore list", then do something.

But so far all I can do (using the help file example as well as some of my own) is have it find out if a window is open or not. Even though it works like a charm, it doesn't really help with what I'm doing.

Worm's little code works, but it seems to only return the window handle (in code form). It doesn't tell me the active window (at least from what I can tell). And if it can, I would need it to do so across the board (meaning that it would have to work of a general number, and not the number assigned by the computer).

This is because I would need to distribute a program that does XYZ on a window if it's currently the active one and I need a value to work on. I can't program code to say shut down handle number 15366 if that number is session specific (a number randomly assigned by the Windows session.

For insatance, 15366 might be the active window, but if I close it and reopen it it will show up as another number such as 19494 even though it's the same exact window such as Google's homepage shown in Internet Explorer.

This is the quandry I'm in. There's a great function in the actions list to SET the Z-Order of active windows, but nothing to GET the Z-Order of the active windows.

Again, I appreciate your help...any suggestions?

Protocol

:huh

SUF6NEWBIE
10-21-2004, 01:14 PM
Possibility...have a look at the Enumerate.Proccesses action

BRETT created a handy bit of script on proccess name targeting..
Its in the SUF7 Script examples section..may help you out.
once a 'handle' is known could use the returned table to 'match-id-filter'
the proccess name with that known 'handle' and go from there..

Worm
10-21-2004, 01:31 PM
Maybe this will help you along.

Protocol
10-21-2004, 01:40 PM
You did it!

Woohoo!

...

Woohoo!

Thanks for everyone's help. I appreciate it. Additionally, Worm...your a savior...as always. :)

Let me know if I can return the favor...

Protocol

Intrigued
10-21-2004, 01:47 PM
(Basketball) This term will be changing: "All net!" to "all Worm"... I just know it!

:yes

SUF6NEWBIE
10-21-2004, 02:16 PM
who's da man !!!!!!!

Protocol
10-24-2004, 03:13 PM
*whistling the SHAFT theme*

"...WORM...can ya dig it?"

lol