pixelsearch Posted January 4, 2021 Share Posted January 4, 2021 (edited) Hi everybody I was curious to write a little script that could automatically resize a child window ($WS_CHILD) when the parent window is resized, without using at all the "disabled label" trick found in many posts. Here is the result, which seems to work fine with only 4 ratios needed. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Local $iParentW = 500, $iParentH = 400, $iParentX = 100, $iParentY = 50 Local $iChildW = 200, $iChildH = 100, $iChildX = 250, $iChildY = 150 $nRatioW = $iChildW / $iParentW $nRatioH = $iChildH / $iParentH $nRatioX = $iChildX / $iParentW $nRatioY = $iChildY / $iParentH $hGUI1 = GUICreate("Resize parent -> resize child", $iParentW, $iParentH, $iParentX, $iParentY, _ BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX), $WS_EX_COMPOSITED) ; avoid flicker $hGUI2 = GUICreate("", $iChildW, $iChildH, $iChildX, $iChildY, $WS_CHILD, -1, $hGUI1) Local $idLabel = GUICtrlCreateLabel("Label in child window", 0, 0, $iChildW, $iChildH, _ BitOr($SS_CENTERIMAGE, $SS_CENTER)) GUICtrlSetBkColor(-1, 0xFFA060) ; orange ; GUICtrlSetResizing(-1, 1) ; 1 = $GUI_DOCKAUTO (no need, it's default resizing for label control) GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState(@SW_SHOW, $hGUI1) GUISetState(@SW_SHOW, $hGUI2) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete($hGUI1) GUIDelete($hGUI2) ;========================================== Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam If $hWnd = $hGUI1 Then Local $iParentNewCliW = BitAND($lParam, 0xFFFF) ; low word Local $iParentNewCliH = BitShift($lParam, 16) ; high word WinMove($hGUI2, "", $iParentNewCliW * $nRatioX, $iParentNewCliH * $nRatioY, _ $iParentNewCliW * $nRatioW, $iParentNewCliH * $nRatioH) ; WinMove will use Int coords EndIf Return $GUI_RUNDEFMSG EndFunc Could you guys please confirm this point : There's a $WS_EX_COMPOSITED extended style applied to the parent window, which should prevent flickering of the child window during the resizing process. Melba23 confirmed this behavior in this link (though he wrote that it worked "sometimes") but he wrote this 10 years ago and several versions of Windows were released since then. So the question is : when you run this script with, then without this extended style, does the child window flicker when the $WS_EX_COMPOSITED extended style is not present ? Thanks for testing. Edit 1/5/2020 : minor change, 4 variables $iRatio... better declared as $nRatio... (they're not always integers) Edited January 5, 2021 by pixelsearch Link to comment Share on other sites More sharing options...
MaximusCZ Posted January 5, 2021 Share Posted January 5, 2021 Win 7 Pro version 6.1 (build 7601: SP1) Label is not blinking if $WS_EX_COMPOSITED is set. Label is blinking if $WS_EX_COMPOSITED is not set. pixelsearch 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 5, 2021 Share Posted January 5, 2021 @pixelsearch Microsoft Windows 10 Pro, 10.0.18362 build 18362 No flickering with and without $WS_EX_COMPOSITED pixelsearch 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
pixelsearch Posted January 5, 2021 Author Share Posted January 5, 2021 Guys, many thanks for the test So it's a good idea to always keep $WS_EX_COMPOSITED in case the user's OS is Win7 (or maybe Win8) and it shouldn't hurt if his OS is Win10, very interesting ! This 1st step being done, I can now move to the 2nd step and post another script here... when it will be ready FrancescoDiMuro 1 Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted January 5, 2021 Share Posted January 5, 2021 @pixelsearch As you know, it's always a pleasure to help you Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now