Sign in to follow this  
Followers 0
Starbug

(No Issue)WS_THICKFRAME & child windows

5 posts in this topic

#1 ·  Posted (edited)

Hi,

I was trying to track down a (possibly related) bug and i came across this issue.

When using WS_THICKFRAME and setting a parent HWND, the return from _WinAPI_GetParent() does not return the parent HWND.

Function returns 0x00000000 (Same return value as checking a parent window)

Refer to the below code. Any GUI Create with WS_THICKFRAME causes the 'null' return value. Im not sure if the fault lies with the window style or the WinAPI call

Global Const $GUI_EVENT_CLOSE = -3
Global Const $WS_SIZEBOX = 0x00040000
Global Const $WS_THICKFRAME = 0x00040000
Global Const $WS_EX_TOOLWINDOW = 0x00000080
#include <WinAPI.au3>
Opt("GUIOnEventMode", 1)

$GUI_Main = GUICreate("$GUI_Main" , 790, 20, 1, 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetState(@SW_SHOW)

$GUI_Child1 = GUICreate("$GUI_Child1", 188, 387, 10, 80, Default, Default, $GUI_Main)
GUISetState(@SW_SHOW)

$GUI_Child2 = GUICreate("$GUI_Child2", 188, 387,210, 80, Default, $WS_EX_TOOLWINDOW, $GUI_Main)
GUISetState(@SW_SHOW)

$GUI_Child3 = GUICreate("$GUI_Child3", 188, 387, 610, 80, $WS_THICKFRAME, Default, $GUI_Main)
GUISetState(@SW_SHOW)

$GUI_Child4 = GUICreate("$GUI_Child4", 188, 387, 810, 80, $WS_THICKFRAME, $WS_EX_TOOLWINDOW, $GUI_Main)
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    $hwnd = _WinAPI_GetParent(WinActive("[ACTIVE]"))
    ConsoleWrite("> " & $hwnd & @CR & "> @error = " & @error & @CR)
    If WinActive("[ACTIVE]") == $GUI_Main Then
        ConsoleWrite("! ParentWindow" & @CR)
    ElseIf $hwnd == $GUI_Main Then
        ConsoleWrite("! ChildWindow" & @CR)
    Else
        ConsoleWrite("! UnrelatedWindow" & @CR)
    EndIf
WEnd

Func Form1Close()
    Exit
EndFunc

Child windows 1 & 2 work as expected, Child windows 3 & 4 are not.

Tested on 2x WinXP PC's here. same result.

If this is confirmed as a fault, ill 'Trac' it

===

My other possibly related bug is that sometimes when clicking the program from window taskbar, it will bring the last child that had focus to the front but is not bringing up the rest of the children or the parent window. This is then resulting in 1 child on-top and the other children still hidden behind the previously active window.

To work around this, i need to click the app to minimize it, then click again to restore it

(The above code does not replicate this issue, so its prob unrelated)

Edited by Starbug

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You are clearing other default bits because you set the style incorrectly (in particular, $WS_CHILD). You have to use BitOr() with the default value:

BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME)

I couldn't make sense of your display method, so I changed it to a ToolTip():

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt("GUIOnEventMode", 1)

$GUI_Main = GUICreate("$GUI_Main", 790, 20, 1, 1)
ConsoleWrite("$GUI_Main = " & $GUI_Main & @LF)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetState(@SW_SHOW)

$GUI_Child1 = GUICreate("$GUI_Child1", 188, 387, 10, 80, Default, Default, $GUI_Main)
ConsoleWrite("$GUI_Child1 = " & $GUI_Child1 & @LF)
GUISetState(@SW_SHOW)

$GUI_Child2 = GUICreate("$GUI_Child2", 188, 387, 210, 80, Default, $WS_EX_TOOLWINDOW, $GUI_Main)
ConsoleWrite("$GUI_Child2 = " & $GUI_Child2 & @LF)
GUISetState(@SW_SHOW)

$GUI_Child3 = GUICreate("$GUI_Child3", 188, 387, 610, 80, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME), Default, $GUI_Main)
ConsoleWrite("$GUI_Child3 = " & $GUI_Child3 & @LF)
GUISetState(@SW_SHOW)

$GUI_Child4 = GUICreate("$GUI_Child4", 188, 387, 810, 80, BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME), $WS_EX_TOOLWINDOW, $GUI_Main)
ConsoleWrite("$GUI_Child4 = " & $GUI_Child4 & @LF)
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
    $hWnd = WinGetHandle("[ACTIVE]")
    $sTitle = WinGetTitle($hWnd, "")
    $hParent = _WinAPI_GetParent($hWnd)
    ToolTip("$hWnd (Active) = " & $hWnd & @LF & _
            "$sTitle = " & $sTitle & @LF & _
            "$hParent = " & $hParent)
WEnd

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanx.

There were things i didn't want from default.

I have adjusted it to BitOR($WS_CHILD, $WS_CAPTION, $WS_POPUP, $WS_THICKFRAME, $WS_CLIPSIBLINGS, $WS_SYSMENU) -- No minimise/Maximise

Anyway, the window i actually wanted was $GUI_Child4. I was only after a re-sizable tool window.

When replacing the $GUI_SS_DEFAULT_GUI with what i want from above, I'm still seeing some 'incorrect' behavior.

When dragging Child2 over Child1, then clicking in the client area, it behaves as expected.

When dragging Child4 over Child3, then the 'Rear' GUI is not being brought to the top when clicking in the client area (Vice Versa also).

When clicking the title bar, it works as expected, like Child2/Child1

Basically, clicking the client area of Child3 and 4 does not bring the full area to the top.

Any ideas?

Share this post


Link to post
Share on other sites

From MSDN - http://msdn.microsoft.com/en-us/library/ms908192.aspx

WS_CHILD Creates a child window. This style cannot be used with the WS_POPUP style.

I suspected that might have something to do with it, When i removed $WS_POPUP, now the window is not even being drawn....

Replaced it with $WS_VISIBLE and still get nothing..

Removed $WS_THICKFRAME and its still not showing..

Share this post


Link to post
Share on other sites

OK, i get it.

Bit of education on my behalf.

"For a window with WS_CHILD, GetParent() returns the parent window. For a window with WS_POPUP, GetParent() returns the owner window, and it can be drawn anywhere on the screen, not just within the parent's client area."

Child window can olny be drawned in the parents client area.

In the example above, if i increase the size of the main GUI, i can then see again the child windows.

So, what im after is multiple windows (with main GUI only housing the menu) and the rest can be placed anywhere. Program only has 1 button in the Taskbar.

So, ditching the $WS_CHILD has issue resolved.

'OWNER' hwnd is returned correctly.

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