Jump to content

GUICreate and WinGetClientSize mismatch


Gianni
 Share

Recommended Posts

when you create a gui, "the size specified is the size of the client area of the window"
however I am noticing that setting the Style and/or the ExStyle parameters, will break that assert.

trying to set styles after the default GUI has been created will let match the client's area dimensions,
but will introduce some other side  effects (GUI beheading) while moving or resizing it

Is there some way to avoid such "scary clown prank" effect and allowing to  set the size of the client area of the window regardless and  although the Style and ExStyle parameters?

thanks for any help

#include <WindowsConstants.au3>

; crerating a default gui will work ok
Local $hGui = GUICreate("Example", 200, 200, 50, 50)
Local $aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'No Styles', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)
GUIDelete($hGui)

; by setting also the Style and the ExStyle parameters will arise a mismatch
$hGui = GUICreate("Example", 200, 200, 50, 50, $WS_THICKFRAME, $WS_EX_TOOLWINDOW)
$aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'Setting Styles', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)
GUIDelete($hGui)

; setting styles after the default GUI has been created will match the client's area dimensions,
; but will introduce some other side  effects
$hGui = GUICreate("Example", 200, 200, 50, 50)
GUISetStyle($WS_THICKFRAME, $WS_EX_TOOLWINDOW, $hGui)
$aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'Setting Styles after', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF & ".... try to move & resize the gui")

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

thanks @pixelsearch, in this way it seems to work better :)

p.s.
... it would be interesting a function that allows you to set the size of the "client area of the window" at will ... something like _WinSetClientSize () leaving the styles as they are

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

ok @Chimp, you've got it

#include <WindowsConstants.au3>

Global $hGui, $aClientSize, $aWinPos

$hGui = GUICreate("Example", 200, 200, 50, 50, $WS_THICKFRAME, $WS_EX_TOOLWINDOW)
_WinSetClientSize($hGui, Default, 200, 200)
$aClientSize = WinGetClientSize($hGui)

GUISetState()
MsgBox(0, 'Setting Styles', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)
GUIDelete($hGui)

Func _WinSetClientSize($sTitle, $sText, $iWidth, $iHeigth, $iLeft = Default, $iTop = Default)
    Local $hWin = WinGetHandle($sTitle, $sText)
    If @error Then Return SetError(1, 0, $hWin)
    Local $aClientSize = WinGetClientSize($hWin)
    Local $aWinPos = WinGetPos($hWin)
    Local $iBorder = Int(($aWinPos[2] - $aClientSize[0]) / 2)
    Local $iBar = $aWinPos[3] - $aClientSize[1] - $iBorder
    If $iLeft = "" Or $iLeft = Default Then $iLeft = $aWinPos[0]
    If $iTop = "" Or $iTop = Default Then $iTop = $aWinPos[1]
    ConsoleWrite('$iBorder = ' & $iBorder & @CRLF)
    ConsoleWrite('$iBar = ' & $iBar & @CRLF)
    WinMove($hWin, "", $iLeft, $iTop, $iWidth + ($iBorder * 2), $iHeigth + $iBorder + $iBar, 0)
    Return $hWin
EndFunc   ;==>_WinSetClientSize

:D

Edited by argumentum
better code

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

By luck I created a function for that just yesterday 😎...

Edit: Changed function name to _WinSetClientSize(), good idea!

#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

; crerating a default gui will work ok
Local $hGui = GUICreate("Example", 200, 200, 50, 50)
Local $aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'No Styles', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)
GUIDelete($hGui)

; by setting also the Style and the ExStyle parameters will arise a mismatch
$hGui = GUICreate("Example", 200, 200, 50, 50, $WS_THICKFRAME, $WS_EX_TOOLWINDOW)
$aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'Setting Styles', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)

_WinSetClientSize($hGui, 200, 200)
$aClientSize = WinGetClientSize($hGui)
MsgBox(0, 'Use _WinSetClientSize()', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF)


GUIDelete($hGui)

; setting styles after the default GUI has been created will match the client's area dimensions,
; but will introduce some other side  effects
$hGui = GUICreate("Example", 200, 200, 50, 50)
GUISetStyle($WS_THICKFRAME, $WS_EX_TOOLWINDOW, $hGui)
$aClientSize = WinGetClientSize($hGui)
GUISetState()
MsgBox(0, 'Setting Styles after', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1] & @CRLF & ".... try to move & resize the gui")

Func _WinSetClientSize($hWnd, $iW, $iH)
    Local $aWinPos = WinGetPos($hWnd)
    Local $sRect = DllStructCreate("int;int;int;int;")
    DllStructSetData($sRect, 3, $iW)
    DllStructSetData($sRect, 4, $iH)
    _WinAPI_AdjustWindowRectEx($sRect, _WinAPI_GetWindowLong($hWnd, $GWL_STYLE), _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE))
    ; ConsoleWrite(DllStructGetData($sRect, 1) & "x" & DllStructGetData($sRect, 2) & @TAB & DllStructGetData($sRect, 3) & "x" & DllStructGetData($sRect, 4) & @CRLF)
    WinMove($hWnd, "", $aWinPos[0], $aWinPos[1], $aWinPos[2] + (DllStructGetData($sRect, 3) - $aWinPos[2]) - DllStructGetData($sRect, 1), $aWinPos[3] + (DllStructGetData($sRect, 4) - $aWinPos[3]) - DllStructGetData($sRect, 2))
EndFunc   ;==>_WinSetClientSize

 

Edited by KaFu
Link to comment
Share on other sites

9 hours ago, Chimp said:

Is there some way to avoid such "scary clown prank" effect...

Welcome back Chimp :)
Guess I only solved the "scary clown prank" effect with my previous post. Look at what I discovered now : results are not the same when WinGetClientSize() is placed before... or after GUISetState()

#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>

$hGui = GUICreate("Example 1", 200, 200, 50, 50)
GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME), $WS_EX_TOOLWINDOW, $hGui)
$aClientSize = WinGetClientSize($hGui) ; <====== Before GUISetState()
GUISetState()
MsgBox($MB_TOPMOST, 'Before GUISetState (1)', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1]) ; 200 x 200 on my computer
GUIDelete($hGui)

$hGui = GUICreate("Example 2", 200, 200, 50, 50)
GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME), $WS_EX_TOOLWINDOW, $hGui)
GUISetState()
$aClientSize = WinGetClientSize($hGui) ;  ; <====== After GUISetState()
MsgBox($MB_TOPMOST, 'After GUISetState (2)', "Width of window's client area : " & $aClientSize[0] & @CRLF & _
        "Height of window's client area: " & $aClientSize[1]) ; 198 x 207 on my computer
GUIDelete($hGui)

Something else : here is a script that could be useful in many cases (all credits go to trancexx in this link) because it allows to easily display all styles & extended styles involved in a Gui. I just added a few lines to make it runnable, also the client area size as it concerns this thread :

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>

Example()

;============================================
Func Example()

    Local $hGui = GUICreate("Example 1", 200, 200, 50, 50)
    GUISetStyle($WS_THICKFRAME, $WS_EX_TOOLWINDOW, $hGui)
    GUISetState()
    ShowAllStyles($hGui)
    GUIDelete($hGui)

    Local $hGui = GUICreate("Example 2", 200, 200, 50, 50)
    GUISetStyle(BitOR($GUI_SS_DEFAULT_GUI, $WS_THICKFRAME), $WS_EX_TOOLWINDOW, $hGui)
    GUISetState()
    ShowAllStyles($hGui)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($hGUI)
                Exit
        EndSwitch
    WEnd

EndFunc   ;==>Example

;===============================================
Func ShowAllStyles($hWnd)

    Local $sTitle = WinGetTitle($hWnd)
    Local $iStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
    Local $iExStyle = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
    Local $aClientSize = WinGetClientSize($hWnd)

    MsgBox($MB_TOPMOST, "Handle : " & $hWnd & "  /  Width = " & $aClientSize[0]  & "  /  Height = " & $aClientSize[1], _
        "Title : " & $sTitle  & @CRLF & @CRLF & _
        "Style = " & Hex($iStyle) & " : " & GetStyleString($iStyle) & @CRLF & @CRLF & _
        "ExStyle = " & Hex($iExStyle) & " : " & GetExStyleString($iExStyle) & @CRLF)

EndFunc   ;==>GetAllStyles

; ===============================================
Func GetStyleString($iStyle)

    Local $sStyle
    If BitAND($iStyle, 0x80880000) = 0x80880000 Then ; $WS_POPUPWINDOW
        $sStyle &= " WS_POPUPWINDOW |"
        $iStyle -= 0x80880000
    EndIf
    If BitAND($iStyle, 0x00CF0000) = 0x00CF0000 Then ; $WS_OVERLAPPEDWINDOW
        $sStyle &= " WS_OVERLAPPEDWINDOW |"
        $iStyle -= 0x00CF0000
    EndIf
    If BitAND($iStyle, 0x00C00000) = 0x00C00000 Then ; $WS_CAPTION
        $sStyle &= " WS_CAPTION |"
        $iStyle -= 0x00C00000
    EndIf
    If BitAND($iStyle, 0x00000048) = 0x00000048 Then ; $DS_SHELLFONT
        $sStyle &= " DS_SHELLFONT |"
        $iStyle -= 0x00000048
    EndIf
    If BitAND($iStyle, 0x80000000) Then $sStyle &= " WS_POPUP |" ; $WS_POPUP
    If BitAND($iStyle, 0x40000000) Then $sStyle &= " WS_CHILD/WS_CHILDWINDOW |" ; $WS_CHILD
    If BitAND($iStyle, 0x20000000) Then $sStyle &= " WS_MINIMIZE/WS_ICONIC |" ; $WS_MINIMIZE
    If BitAND($iStyle, 0x10000000) Then $sStyle &= " WS_VISIBLE |" ; $WS_VISIBLE
    If BitAND($iStyle, 0x08000000) Then $sStyle &= " WS_DISABLED |" ; $WS_DISABLED
    If BitAND($iStyle, 0x04000000) Then $sStyle &= " WS_CLIPSIBLINGS |" ; $WS_CLIPSIBLINGS
    If BitAND($iStyle, 0x02000000) Then $sStyle &= " WS_CLIPCHILDREN |" ; $WS_CLIPCHILDREN
    If BitAND($iStyle, 0x01000000) Then $sStyle &= " WS_MAXIMIZE |" ; $WS_MAXIMIZE
    If BitAND($iStyle, 0x00800000) Then $sStyle &= " WS_BORDER |" ; $WS_BORDER
    If BitAND($iStyle, 0x00400000) Then $sStyle &= " WS_DLGFRAME |" ; $WS_DLGFRAME
    If BitAND($iStyle, 0x00200000) Then $sStyle &= " WS_VSCROLL |" ; $WS_VSCROLL
    If BitAND($iStyle, 0x00100000) Then $sStyle &= " WS_HSCROLL |" ; $WS_HSCROLL
    If BitAND($iStyle, 0x00080000) Then $sStyle &= " WS_SYSMENU |" ; $WS_SYSMENU
    If BitAND($iStyle, 0x00040000) Then $sStyle &= " WS_SIZEBOX/WS_THICKFRAME |" ; $WS_SIZEBOX
    If BitAND($iStyle, 0x00020000) Then $sStyle &= " WS_MINIMIZEBOX |" ; $WS_MINIMIZEBOX
    If BitAND($iStyle, 0x00010000) Then $sStyle &= " WS_MAXIMIZEBOX |" ; $WS_MAXIMIZEBOX
    If BitAND($iStyle, 0x00008000) Then $sStyle &= " DS_WINDOWSUI |" ; $DS_WINDOWSUI
    If BitAND($iStyle, 0x00004000) Then $sStyle &= " 0x00004000 |" ; UNKNOWN STYLE
    If BitAND($iStyle, 0x00002000) Then $sStyle &= " DS_CONTEXTHELP |" ; $DS_CONTEXTHELP
    If BitAND($iStyle, 0x00001000) Then $sStyle &= " 0x00001000 |" ; UNKNOWN STYLE
    If BitAND($iStyle, 0x00000800) Then $sStyle &= " 0x00000800 |" ; UNKNOWN STYLE
    If BitAND($iStyle, 0x00000400) Then $sStyle &= " DS_CONTROL |" ; $DS_CONTROL
    If BitAND($iStyle, 0x00000200) Then $sStyle &= " DS_SETFOREGROUND |" ; $DS_SETFOREGROUND
    If BitAND($iStyle, 0x00000100) Then $sStyle &= " DS_NOIDLEMSG |" ; $DS_NOIDLEMSG
    If BitAND($iStyle, 0x00000080) Then $sStyle &= " DS_MODALFRAME |" ; $DS_MODALFRAME
    If BitAND($iStyle, 0x00000040) Then $sStyle &= " DS_SETFONT |" ; $DS_SETFONT
    If BitAND($iStyle, 0x00000020) Then $sStyle &= " DS_LOCALEDIT |" ; $DS_LOCALEDIT
    If BitAND($iStyle, 0x00000010) Then $sStyle &= " DS_NOFAILCREATE |" ; $DS_NOFAILCREATE
    If BitAND($iStyle, 0x00000008) Then $sStyle &= " DS_FIXEDSYS |" ; $DS_FIXEDSYS
    If BitAND($iStyle, 0x00000004) Then $sStyle &= " DS_3DLOOK |" ; $DS_3DLOOK
    If BitAND($iStyle, 0x00000002) Then $sStyle &= " DS_SYSMODAL |" ; $DS_SYSMODAL
    If BitAND($iStyle, 0x00000001) Then $sStyle &= " DS_ABSALIGN |" ; $DS_ABSALIGN
    Return StringTrimRight($sStyle, 1)

EndFunc   ;==>GetStyleString

; ===============================================
Func GetExStyleString($iExStyle)

    Local $sExStyle
    If BitAND($iExStyle, 0x00000300) = 0x00000300 Then ; $WS_EX_OVERLAPPEDWINDOW
        $sExStyle &= " WS_EX_OVERLAPPEDWINDOW |"
        $iExStyle -= 0x00000300
    EndIf
    If BitAND($iExStyle, 0x00000188) = 0x00000188 Then ; $WS_EX_PALETTEWINDOW
        $sExStyle &= " WS_EX_PALETTEWINDOW |"
        $iExStyle -= 0x00000188
    EndIf
    If BitAND($iExStyle, 0x08000000) Then $sExStyle &= " WS_EX_NOACTIVATE |" ; $WS_EX_NOACTIVATE
    If BitAND($iExStyle, 0x04000000) Then $sExStyle &= " 0x04000000 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x02000000) Then $sExStyle &= " WS_EX_COMPOSITED |" ; $WS_EX_COMPOSITED
    If BitAND($iExStyle, 0x01000000) Then $sExStyle &= " 0x01000000 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00800000) Then $sExStyle &= " 0x00800000 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00400000) Then $sExStyle &= " WS_EX_LAYOUTRTL |" ; $WS_EX_LAYOUTRTL
    If BitAND($iExStyle, 0x00200000) Then $sExStyle &= " 0x00200000 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00100000) Then $sExStyle &= " WS_EX_NOINHERITLAYOUT |" ; $WS_EX_NOINHERITLAYOUT
    If BitAND($iExStyle, 0x00080000) Then $sExStyle &= " WS_EX_LAYERED |" ; $WS_EX_LAYERED
    If BitAND($iExStyle, 0x00040000) Then $sExStyle &= " WS_EX_APPWINDOW |" ; $WS_EX_APPWINDOW
    If BitAND($iExStyle, 0x00020000) Then $sExStyle &= " WS_EX_STATICEDGE |" ; $WS_EX_STATICEDGE
    If BitAND($iExStyle, 0x00010000) Then $sExStyle &= " WS_EX_CONTROLPARENT |" ; $WS_EX_CONTROLPARENT
    If BitAND($iExStyle, 0x00008000) Then $sExStyle &= " 0x00008000 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00004000) Then $sExStyle &= " WS_EX_LEFTSCROLLBAR |" ; $WS_EX_LEFTSCROLLBAR
    If BitAND($iExStyle, 0x00002000) Then $sExStyle &= " WS_EX_RTLREADING |" ; $WS_EX_RTLREADING
    If BitAND($iExStyle, 0x00001000) Then $sExStyle &= " WS_EX_RIGHT |" ; $WS_EX_RIGHT
    If BitAND($iExStyle, 0x00000800) Then $sExStyle &= " 0x00000800 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00000400) Then $sExStyle &= " WS_EX_CONTEXTHELP |" ; $WS_EX_CONTEXTHELP
    If BitAND($iExStyle, 0x00000200) Then $sExStyle &= " WS_EX_CLIENTEDGE |" ; $WS_EX_CLIENTEDGE
    If BitAND($iExStyle, 0x00000100) Then $sExStyle &= " WS_EX_WINDOWEDGE |" ; $WS_EX_WINDOWEDGE
    If BitAND($iExStyle, 0x00000080) Then $sExStyle &= " WS_EX_TOOLWINDOW |" ; $WS_EX_TOOLWINDOW
    If BitAND($iExStyle, 0x00000040) Then $sExStyle &= " WS_EX_MDICHILD |" ; $WS_EX_MDICHILD
    If BitAND($iExStyle, 0x00000020) Then $sExStyle &= " WS_EX_TRANSPARENT |" ; $WS_EX_TRANSPARENT
    If BitAND($iExStyle, 0x00000010) Then $sExStyle &= " WS_EX_ACCEPTFILES |" ; $WS_EX_ACCEPTFILES
    If BitAND($iExStyle, 0x00000008) Then $sExStyle &= " WS_EX_TOPMOST |" ; $WS_EX_TOPMOST
    If BitAND($iExStyle, 0x00000004) Then $sExStyle &= " WS_EX_NOPARENTNOTIFY |" ; $WS_EX_NOPARENTNOTIFY
    If BitAND($iExStyle, 0x00000002) Then $sExStyle &= " 0x00000002 |" ; UNKNOWN EXSTYLE
    If BitAND($iExStyle, 0x00000001) Then $sExStyle &= " WS_EX_DLGMODALFRAME |" ; $WS_EX_DLGMODALFRAME
    Return StringTrimRight($sExStyle, 1)

EndFunc   ;==>GetExStyleString

 

Edited by pixelsearch
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...