Is it Possible to Unhide a Hidden Window?

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
User avatar
jpuziano
Automation Wizard
Posts: 1085
Joined: Sat Oct 30, 2004 12:00 am

Is it Possible to Unhide a Hidden Window?

Post by jpuziano » Thu Mar 02, 2006 8:15 pm

Hi Support,

The Run command allows us to start up IE and specify a window mode of "hidden" like this:

Let>RP_WINDOWMODE=0
Run Program>C:\Program Files\Internet Explorer\IEXPLORE.EXE


1) Once it is running, is there any way to change its mode back to "normal" for a time then back to "hidden"?

2) Is there a way to grab the window handle of this particular hidden IE window even if there are 5 other IE windows already open with the same title?

mtettmar wrote:We do intend to add a function to IEAuto.DLL to HIDE the IE window altogether. IE offers a property to make it visible or not, so we can easily expose that method and hide it.
That feature would be great, any news on when it might be added to IEAuto.DLL?

Thanks
jpuziano

Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post - :-)

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

Post by Marcus Tettmar » Mon Mar 27, 2006 8:04 am

Sorry, only just seen this post.

1) Yes - you would need to know the window's handle. Then you can use the SetWindowPos API function with the SWP_SHOWWINDOW flag (64). You could use FindWindow to find the window handle based on the window title. As you know, there was a SetWindowPos example in this post:
http://www.mjtnet.com/forum/viewtopic.php?t=2688

2) As long as each IE window had different window titles you could use the FindWindow API function. I.e. if you know the window title of this new hidden IE window you can use FindWindow with the title to find the handle. In most cases you will know the window title as the window title is based on the title of the page you are launching. So that will be known in advance.

Use FindWindow like this:

LibFunc>user32,FindWindowA,hwnd,0,window_title
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Mar 20, 2008 9:05 pm

I was reminded of this thread this morning.
jpuziano wrote:1) Once it is running, is there any way to change its mode back to "normal" for a time...?
After a little experimenting I discovered that you can "unhide" a hidden window simply by setting focus to it. You could also use the SetWindowPos API function as described by Marcus. As Marcus mentioned, generally, if you started a window running you know the name of the window and if you know its name you can set focus to it.
jpuziano wrote:1) ... then back to "hidden"?
I also discovered a way to use the SetWindowPos API function to put a window into the "hidden" condition. First you need to get the window's handle wihich can be done as Marcus described using the FindWindowA API function. Or, any version of Macro Scheduler since version 7.3 can use GetWindowHandle>. Next you use the SetWindowPos API function with SWP_HIDEWINDOW to put the window back into the "hidden" condition.

Here's a sample script to demonstrate. When this script has finished running, you'll need to open Task Manager and kill the open yet invisible notepad session. Note that notepad is not visible on the screen, it does not show up in the taskbar and is not in the ALT+Tab list. It is running but hidden.

Hope that somebody finds this information useful.
Dick

Code: Select all

Let>RP_WINDOWMODE=0
Run>notepad.exe

mdl>Press ok to make notepad visible

//setfocus makes an invisible window, visible.
SetFocus>notepad*
GetWindowHandle>notepad*,winhandle

mdl>Press ok to make notepad invisible again

Let>HWND_TOPMOST=-1
Let>HWND_NOTOPMOST=-2
Let>HWND_BOTTOM=1
Let>SWP_NOSIZE=1
Let>SWP_NOMOVE=2
Let>SWP_NOACTIVATE=16
Let>SWP_SHOWWINDOW=64
Let>SWP_HIDEWINDOW=128

Let>Flags={%SWP_HIDEWINDOW% Or %SWP_NOACTIVATE% Or %SWP_NOSIZE% Or %SWP_NOMOVE%}
LibFunc>User32,SetWindowPos,swpr,winhandle,HWND_BOTTOM,0,0,0,0,Flags

//For some reason the window still shows up in ALT+Tab until
//you set focus to another window,  then its gone.
//Setting focus to the desktop should be safe.

SetFocus>Program Manager*

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