Jump to content

SetParent: Not repainting the window properly


Recommended Posts

I was experimenting with a wrapper for the function SetParent (from user32.dll) and i found a small problem with it. It doesn't seem to repaint the child window properly if the window is moved off of the parent. Heres an example i used with Notepad.

#include <GUIConstants.au3>
Run("notepad.exe")
WinWait("Untitled - Notepad")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 691, 515, 193, 123)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
DLLCall("user32.dll", "str", "SetParent", "hwnd", WinGetHandle("Untitled - Notepad"), "hwnd", WinGetHandle("AForm1"))
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

It sets Notepad as the child, but if i move the notepad window off of the Parent GUI, and move it back, here's what happens:

Posted Image

Anyone know whats going on?

Link to comment
Share on other sites

  • 3 weeks later...

I tried your code and I it really doesn't work properly. I don't know why, but since I also need the SetParent function, so I've played with it a little bit. The following code seems to work, but I do not think if this is the correct way to do it. I only added the line WinActivate($Form1) after the DLLCall.

#include <GUIConstants.au3>
Run("notepad.exe")
WinWait("Untitled - Notepad")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 691, 515, 193, 123)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
DLLCall("user32.dll", "str", "SetParent", "hwnd", WinGetHandle("Untitled - Notepad"), "hwnd", WinGetHandle("AForm1"))
WinActivate($Form1)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
Edited by Noob
Link to comment
Share on other sites

  • 4 weeks later...

I was experimenting with a wrapper for the function SetParent (from user32.dll) and i found a small problem with it. It doesn't seem to repaint the child window properly if the window is moved off of the parent. Heres an example i used with Notepad.

Senton-Bomb, don't know if you're still looking for a solution to this, but I did some testing with the code that lod3n posted here: http://www.autoitscript.com/forum/index.ph...st&p=365233 and the following solves the problem for me -

#include <GUIConstants.au3>
Run("notepad.exe")
WinWait("Untitled - Notepad")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("AForm1", 691, 515, 193, 123)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
DLLCall("user32.dll", "str", "SetParent", "hwnd", WinGetHandle("Untitled - Notepad"), "hwnd", WinGetHandle("AForm1"))


$guiStyle = BitOR($WS_BORDER, $WS_CAPTION, $WS_CLIPCHILDREN, $WS_CLIPSIBLINGS, $WS_DLGFRAME, $WS_GROUP, $WS_MAXIMIZE, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_TABSTOP, $WS_THICKFRAME, $WS_VISIBLE) ; 0x17CF0100
$guiStyleEx = $WS_EX_WINDOWEDGE ; 0x00000100

_SetStyle($Form1,$guiStyle,$guiStyleEx)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func _SetStyle($hwnd,$style,$exstyle)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -16, "long", $style)
    DllCall("user32.dll", "long", "SetWindowLong", "hwnd", $hwnd, "int", -20, "long", $exstyle)
EndFunc
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...