GetWindowPos returning same value after window minimised

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
dafe
Junior Coder
Posts: 23
Joined: Sun Apr 06, 2008 4:21 am

GetWindowPos returning same value after window minimised

Post by dafe » Fri Jun 13, 2008 3:38 am

Apologies if this has been answered elsewhere, i've done some fairly extensive searching but wasn't able to find anything that resembled the issue i'm experiencing.

To give you some background, i'm attempting to run several instances of a program (10 to be exact). Once opened, each open session begins it's own automatic process and is then minimised to the system tray, once it has completed it's process it then automatically closes itself. In order to capture when each program closes, i'm monitoring window handles instead of window titles (as they all have the same title).

So i've set

Code: Select all

Set>WIN_USEHANDLE=1
after which the first program is called

Code: Select all

ExecuteFile>Program1
WaitReady>0
Wait>delay
Once opened i grab the handle and the x, y coords

Code: Select all

GetActiveWindow>Program1,x1,y1
Now in order to avoid confusion, and to make sure i am correctly grabbing the handle of each program window which opens, i want the macro to check to see if the first window is minimised before the next window opens. I want to make absolutely sure that i'm not accidentally grabbing a handle from the wrong program, so i only want to allow one to be on screen at any time. As mentioned above, i will be branching to a different action once the macro has determined that a certain program handle has closed.

The way i decided to do this was to use the x,y coords pulled from GetActiveWindow and verify it against GetWindowPos.... so -

Code: Select all

Label>Program1Open
Wait>delay
GetWindowPos>%Program1%,x1a,y1a
If>{(%x1% = %x1a%) AND (%y1% = %y1a%)}
	Goto>Program1open
Else
	Goto>Program2
Endif
the way i envisaged this in working would be that if the co-ordinates pulled from GetActiveWindow match the co-ordinates from GetWindowPos then obviously the window is still in the exact same position and to continue looping until the window was minimised to the systray.

The problem i'm running into though is that once the window is minimised to systray, GetWindowPos still returns the same co-ordinates as when the program was initially opened.

Am i doing something wrong? Or is there a simpler way for me to figure out when the first window has minimised so that the script can proceeed onto launching the 2nd then the 3rd program etc. etc.

Any suggestions or pointers appreciated.


Cheers
--

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Jun 13, 2008 7:13 am

The reason for this is answered in the following statement: There is no such thing as minimising to the system tray.

To expand on that: The system tray is just somewhere programmers can put icons. That's it. It has no responsibility or functionality regarding window behaviour.

Many apps give the impression of being "minimised to the task bar" like this: when you click the minimize icon the window is hidden. You get it back by clicking on the system tray icon. The app overrides the onMinimize event by hiding the window.

So that should answer your question. The X,Y coordinates are the same because the window hasn't moved. It's still where it was when you pressed the minimise button. It just became invisible. But it's still at the same place.

Perhaps you can now see a solution to your problem - instead of checking to see if the window is minimised, check whether it is visible or not:

Code: Select all

LibFunc>user32,IsWindowVisible,nVis,WindowHandle
If>nVis=1
 //window is visible
Else
 //Window is not visible
Endif
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

dafe
Junior Coder
Posts: 23
Joined: Sun Apr 06, 2008 4:21 am

Post by dafe » Fri Jun 13, 2008 7:54 am

Excellent, thanks for the explanation! i certainly wasn't aware that that's how the systray functioned.

It didn't even click for me to check for visibility, thanks for the suggestion, i'll go and give that a shot right now.

cheers!

edit: worked like a charm.
--

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts