Jump to content

win parent


Recommended Posts

Hi,

I've a problem:

I have to get all the windows of a process and minimize all of them

I can simply get all the windows of a process using

Func hwndsof($pid)
    Local $returns[1]
    $list=WinList()
    For $i=1 to $list[0][0]
        If WinGetProcess($list[$i][1])=$pid Then 
            ReDim $returns[ubound($returns)+1]
            $returns[ubound($returns)-1]=$list[$i][1]
        EndIf
    Next
    $returns[0]=UBound($returns)
    Return $returns
EndFunc

and it does work

but I don't want to minimize the child windows, too!!!!

... and winlist() retrives childs too!

How I can ceck if a window is a child and retrive the handle of its parent?

Tanks

Link to comment
Share on other sites

  • Moderators

Maybe you could iterate just a tad more. By default: Opt("WinSearchChildren") = 0 (for top level windows only).

Keep in mind that controls are also child windows.

So, are you saying, "If this window has a parent window, don't minimize it?"

If so, look on the forum for GetParent api usage. And just make a conditional statement after you verify WinGetProcess().

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

I've tried to use

_WinAPI_GetParent($handle)

But it discovers more than a window

for example

#Include <WinAPI.au3>
#Include <Array.au3>
$list=hwndsof(WinGetProcess("[ACTIVE]"))
_ArrayDisplay($list)
Func hwndsof($pid)
    Local $returns[1][3]
    $list=WinList()
    For $i=1 to $list[0][0]
        If WinGetProcess($list[$i][1])=$pid Then 
            ReDim $returns[ubound($returns)+1][3]
            $returns[ubound($returns)-1][0]=$list[$i][1]
            $e=_WinAPI_GetParent($list[$i][1])
            $returns[ubound($returns)-1][1]=$e
            $returns[ubound($returns)-1][2]=wingettitle($e)
        EndIf
    Next
    $returns[0][0]=UBound($returns)
    Return $returns
EndFunc

displays more than a window

I can see something like "Default IME"....

I only want all the top-level windows related to a process.....

Link to comment
Share on other sites

  • Moderators

#Include <WinAPI.au3>
#Include <Array.au3>

Global $a_list = _Process_GetTopLevelWins(WinGetProcess("[ACTIVE]"))
_ArrayDisplay($a_list)

Func _Process_GetTopLevelWins($i_pid, $f_visible_only = True)
    Local $i_opt = Opt("WinSearchChildren", 0)
    
    Local $a_wl = WinList()
    Local $a_ret[UBound($a_wl)][2], $i_add = 0
    
    For $i = 1 To $a_wl[0][0]
        If WinGetProcess($a_wl[$i][1]) = $i_pid And _
            _WinAPI_GetParent($a_wl[$i][1]) = 0 Then
            
            If $f_visible_only And _
                BitAND(WinGetState($a_wl[$i][1]), 2) = 0 Then ContinueLoop
                
            $i_add += 1
            $a_ret[$i_add][0] = $a_wl[$i][0]
            $a_ret[$i_add][1] = $a_wl[$i][1]
        EndIf
    Next
    Opt("WinSearchChildren", $i_opt)
    
    If $i_add = 0 Then Return SetError(1, 0, 0) ; No matches
    
    ReDim $a_ret[$i_add + 1][2]
    $a_ret[0][0] = $i_add
    Return $a_ret
EndFunc
You were using it as a conditional statement as I said.

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

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