Sign in to follow this  
Followers 0
Noviceatthis

Hiding windows by use of their handle

3 posts in this topic

Hello all

Basically what I would like to do is hide all windows of a particular process by using their handles

This is what I have so far:

#include <WinAPIProc.au3>
#include <Array.au3>

$processname = "vlc.exe"

If Not ProcessExists($processname) Then
    Exit
EndIf

$Data = ProcessList($processname)
global $numberofInstances = $Data[0][0]


Global $PID[$numberofInstances + 1]
Global $hWndArray

For $i = 1 To $numberofInstances
    $PID[$i] = $Data[$i][1] 

    $hWndArray = _WinAPI_EnumProcessWindows($PID[$i]) 

    $hWnd = $hWndArray[1][0] 

    $Hide = WinSetState($hWnd, "", @SW_HIDE)
Next

sleep (5000)


For $i = 1 To $numberofInstances
    $PID[$i] = $Data[$i][1] 

    $hWndArray = _WinAPI_EnumProcessWindows($PID[$i], false) 

    $hWnd = $hWndArray[1][0] 

    WinSetState($hWnd, '', @SW_SHOW)
Next

So all the windows of the process do become hidden, its getting them back that's the problem, in the example I used above, VLC does come back, but in a really weird form. When I tried it with MS Word, the window simply did not return. I was wondering whether there was a solution to this

Thanks in Advance

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

The first function only returns an array of visible windows...usually only 1 or 2 at a time.  Generally, for any process, there are MANY handles, and mostly NOT visible.  So it's easy to hide, but you would need to loop through the array and make all visible...or maybe only those where wingetpos is within bounds of your monitor, and over certain width/height....I'll leave that to you, but this will brute force it:

For $i = 1 To $numberofInstances
    $PID[$i] = $Data[$i][1] 

    $hWndArray = _WinAPI_EnumProcessWindows($PID[$i], false) 

    For $i = 1 to UBound($hWndArray)-1
        WinSetState($hWndArray[$i][1], '', @SW_SHOW)
    Next
Next

Very cool function though...I always got ALL window handles, and looped through to see if those windows were of the same process...much easier to have this do it for you!

Note: I would suggest looping through the "visible" array also, just in case there is ever more than one window.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Thanks jdelaney

I'll have a play around with this

Share this post


Link to post
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
Sign in to follow this  
Followers 0