Jump to content

GetParentHandle()


AznSai
 Share

Recommended Posts

Simple function to recieve the handle of the parent window of a child window (That was a bit confusing) :P

Func GetParentHandle($ChildHwnd)
    Local $ParentLong = DllCall("user32.dll","long","GetWindowLong","hwnd",$ChildHwnd,"int",-8)
    If $ParentLong[0] = 0 Then SetError(1)
    Local $ParentHwnd = String($ParentLong[0])
    Return HWnd($ParentHwnd)
EndFunc

And an example:

Dim $ChildhWnd = WinGetHandle("Child Window Text")
Dim $ParenthWnd = GetParentHandle($ChildhWnd)
If @error <> 0 Then Exit
WinSetState($ParenthWnd,"",@SW_MINIMIZE)

Sorry if this has been done before ;)

Edited by AznSai
Link to comment
Share on other sites

Func GetParentHandle($ChildHwnd)
    Local $ParentLong = DllCall("user32.dll","long","GetWindowLong","hwnd",$ChildHwnd,"int",-8)
    If @ERROR <> 0 OR $ParentLong[0] = 0 Then 
        SetError(1)
        Return 0
    EndIf
    Return HWnd($ParentLong[0])
EndFunc

works a bit better IMO.

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

Func GetParentHandle($ChildHwnd)
    Local $ParentLong = DllCall("user32.dll","long","GetWindowLong","hwnd",$ChildHwnd,"int",-8)
    If @ERROR <> 0 OR $ParentLong[0] = 0 Then 
        SetError(1)
        Return 0
    EndIf
    Return HWnd($ParentLong[0])
EndFunc

works a bit better IMO.

Thanks for that, it's the only way I'll learn :">
Link to comment
Share on other sites

Return HWnd($ParentLong[0])

Oddly, I got an error that HWnd was not found, until I re-re-installed Scite and the re-installed the Scite update to beta 75.

Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

my attempt

Func _WinGetParent( $WGP_hwnd )
   $ret = DLLCall( "User32.dll", "hwnd", "GetParent", "hwnd", $WGP_hwnd)
   Return $ret[0]
EndFunc
Your's might be able to do what mine does in less code, but my code looks better :P

Lol im just a sore loser... ;)

Link to comment
Share on other sites

Func _WinSetParent($OldHwnd, $NewHwnd)
$ret = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $OldHwnd, "hwnd", $NewHwnd)
If @error <> 0 then
SetError(1)
Return 0
ElseIf isHwnd($ret[0])  Then 
Return $ret[0]
Else
SetError(1)
Return 0
EndIf
EndFunc


Func _WinGetParent( $WGP_hwnd )
$ret = DLLCall( "User32.dll", "hwnd", "GetParent", "hwnd", $WGP_hwnd)
If @error <> 0 then
SetError(1)
Return 0
ElseIf isHwnd($ret[0])  Then 
Return $ret[0]
Else
SetError(1)
Return 0
EndIf
EndFunc

i like both of em

@ w0oter :is that better?

Edited by WSCPorts
http://www.myclanhosting.com/defiasVisit Join and contribute to a soon to be leader in Custumized tools development in [C# .Net 1.1 ~ 2.0/C/C++/MFC/AutoIt3/Masm32]
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...