Jump to content

resize controls bar


argumentum
 Share

Recommended Posts

I need help with resizing controls. The following shows what I have in mind but no expertise to implement.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 466, 467, -1, -1, BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX,$WS_THICKFRAME,$WS_TABSTOP))
Global $Edit1 = GUICtrlCreateEdit("", 8, 8, 449, 193)
GUICtrlSetData($Edit1, "Edit1")
GUICtrlSetResizing($Edit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
Global $Edit2 = GUICtrlCreateEdit("", 8, 224, 449, 217)
GUICtrlSetData($Edit2, "Edit2")
GUICtrlSetResizing($Edit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
Global $LabelAsDivider = GUICtrlCreateLabel("", 8, 208, 444, 9, $SS_BLACKFRAME)
GUICtrlSetResizing($LabelAsDivider, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
GUICtrlSetCursor ($LabelAsDivider, 11)
Global $g_hStatus = _GUICtrlStatusBar_Create($Form1)
_GUICtrlStatusBar_SetMinHeight($g_hStatus, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUICtrlSetState($LabelAsDivider,$GUI_FOCUS) ; the control that would resize the other 2 GUICtrlEdit
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

Local $aCursorInfo
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_PRIMARYDOWN
            $aCursorInfo = GUIGetCursorInfo($Form1)
            If UBound($aCursorInfo) = 5 Then
                If $aCursorInfo[4] = $LabelAsDivider Then
                    fResizeEditCtrls() ; this I need help with, or the whole concept
                EndIf
            EndIf

        Case $GUI_EVENT_CLOSE
            GUIDelete($Form1)
            Exit

    EndSwitch
WEnd

Func fResizeEditCtrls()
    ; help me with this
EndFunc

; Resize the status bar when GUI size changes
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    _GUICtrlStatusBar_Resize($g_hStatus)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

any and all guidance greatly thankful for.

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

In this example the status bar is removed. When the controls are resized in this manner, it's troublesome to handle the status bar.

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt( "MustDeclareVars", 1 )

Global Const $iTitlebarHeight = _WinAPI_GetSystemMetrics( 31 ) ; 31 = $SM_CYSIZE
Global Const $iBorderHeight   = _WinAPI_GetSystemMetrics( 33 ) ; 33 = $SM_CYSIZEFRAME

Global $hForm1, $idEdit1, $idEdit2, $hGuiAsDivider, $iMinHeight = 0, $fResize = False

Example()


Func Example()                                                                                                 ; Reduce flicker
  $hForm1 = GUICreate( "Form1", 470, 490, -1, -1, BitOR( $GUI_SS_DEFAULT_GUI, $WS_OVERLAPPEDWINDOW, $WS_TABSTOP, $WS_CLIPCHILDREN ) )

  $idEdit1 = GUICtrlCreateEdit( "Edit1", 10,  10, 450, 200 )
  $idEdit2 = GUICtrlCreateEdit( "Edit2", 10, 240, 450, 240 )
  GUICtrlSetResizing($idEdit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
  GUICtrlSetResizing($idEdit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)

  ; Use a child window to reduce flicker
  $hGuiAsDivider = GUICreate( "", 452, 10, 4, 214, $WS_POPUP, $WS_EX_MDICHILD, $hForm1 )
  Local $idLabelAsDivider = GUICtrlCreateLabel("", 0, 0, 452, 10, $SS_ETCHEDFRAME)
  GUICtrlSetCursor( $idLabelAsDivider, 11 )
  GUISetState( @SW_SHOWNOACTIVATE, $hGuiAsDivider )
  GUISwitch( $hForm1 )

  GUIRegisterMsg( $WM_SIZE, "WM_SIZE" )
  GUIRegisterMsg( $WM_GETMINMAXINFO, "WM_GETMINMAXINFO" )

  GUISetState(@SW_SHOW)

  While 1
    Switch GUIGetMsg()
      Case $idLabelAsDivider
        ResizeEditCtrls()

      Case $GUI_EVENT_RESIZED
        Local $aPos = ControlGetPos( $hForm1, "", $idEdit1 )
        WinMove( $hGuiAsDivider, "", Default, WinGetPos( $hForm1 )[1] + $iTitlebarHeight + $iBorderHeight + $aPos[3] + 20 + ( $fResize = True ) * 2, $aPos[2] )
        ControlMove( $hForm1, "", $idEdit2, default, $aPos[3] + 40 )
        $fResize = False

      Case $GUI_EVENT_CLOSE
        ExitLoop

    EndSwitch
  WEnd

  ; Cleanup
  GUIDelete($hForm1)
  Exit
EndFunc

Func ResizeEditCtrls()
  Local $aInfo = GUIGetCursorInfo( $hForm1 ), $y0 = $aInfo[1], $yPrev = $aInfo[1], $dy
  Local $aPos = WinGetPos( $hGuiAsDivider ), $aPos1 = ControlGetPos( $hForm1, "", $idEdit1 ), $aPos2 = ControlGetPos( $hForm1, "", $idEdit2 )
  GUICtrlSetResizing($idEdit1, $GUI_DOCKALL )
  GUICtrlSetResizing($idEdit2, $GUI_DOCKALL )
  Do
    If $aInfo[1] <> $yPrev Then
      $dy = $aInfo[1] - $y0
      If $aPos1[3] + $dy > 100 And $aPos2[3] - $dy > 100 Then
        WinMove( $hGuiAsDivider, "", Default, $aPos[1] + $dy )
        ControlMove( $hForm1, "", $idEdit1, Default, Default, $aPos1[2], $aPos1[3] + $dy )
        ControlMove( $hForm1, "", $idEdit2, Default, $aPos2[1] + $dy, $aPos2[2], $aPos2[3] - $dy )
      EndIf
      $yPrev = $aInfo[1]
    EndIf
    $aInfo = GUIGetCursorInfo( $hForm1 )
  Until $aInfo[2] = 0
  GUICtrlSetResizing($idEdit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
  GUICtrlSetResizing($idEdit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
  $iMinHeight = 0
EndFunc

Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam, $lParam
  Local $aPos = ControlGetPos( $hForm1, "", $idEdit1 )
  If $aPos[3] <= 100 Then $iMinHeight = WinGetPos( $hForm1 )[3]
  WinMove( $hGuiAsDivider, "", Default, WinGetPos( $hForm1 )[1] + $iTitlebarHeight + $iBorderHeight + $aPos[3] + 20, $aPos[2] )
  Return $GUI_RUNDEFMSG
EndFunc

Func WM_GETMINMAXINFO( $hWnd, $iMsg, $wParam, $lParam )
  Local $tMINMAXINFO = DllStructCreate( "int;int;int;int;int;int;int;int;int;int", $lParam )
  DllStructSetData( $tMINMAXINFO, 8, $iMinHeight ) ; Min GUI height
EndFunc

 

Link to comment
Share on other sites

@LarsJ , thanks for the answer. The code fails when is maximized and gets worse after restore. If there is flicker, then, it flickers. :)

Edit: I've added to "Case $GUI_EVENT_RESIZED" , ", $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE" and is no fix. :(

Edited by argumentum

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

Link to comment
Share on other sites

I have not added code for any of these cases. Just normal resize. I'll take a closer look tomorrow.

https://www.autoitscript.com/forum/topic/142015-scite-clone-autoit-scite-impostor/ does a good job of it ( not perfect but functional ) but I don't understand it. The sample code I paste, is an example, but I'm gonna be using the SciLexer.dll in the end and not the Edit controls. For the example, I figure that any control would do, without having to paste a lot of code, just for the notion of resizing.

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

Mr. argumentum, I've added code to handle maximize, minimize and restore:

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Opt( "MustDeclareVars", 1 )

Global Const $iTitlebarHeight = _WinAPI_GetSystemMetrics( 31 ) ; 31 = $SM_CYSIZE
Global Const $iBorderHeight   = _WinAPI_GetSystemMetrics( 33 ) ; 33 = $SM_CYSIZEFRAME

Global $hForm1, $idEdit1, $idEdit2, $hGuiAsDivider, $iMinHeight = 0

Example()


Func Example()                                                                                                 ; Reduce flicker
  $hForm1 = GUICreate( "Form1", 470, 490, -1, -1, BitOR( $GUI_SS_DEFAULT_GUI, $WS_OVERLAPPEDWINDOW, $WS_TABSTOP, $WS_CLIPCHILDREN ) )

  $idEdit1 = GUICtrlCreateEdit( "Edit1", 10,  10, 450, 200 )
  $idEdit2 = GUICtrlCreateEdit( "Edit2", 10, 240, 450, 240 )
  GUICtrlSetResizing($idEdit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
  GUICtrlSetResizing($idEdit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)

  ; Use a child window to reduce flicker
  $hGuiAsDivider = GUICreate( "", 452, 10, 4, 214, $WS_POPUP, $WS_EX_MDICHILD, $hForm1 )
  Local $idLabelAsDivider = GUICtrlCreateLabel("", 0, 0, 452, 10, $SS_ETCHEDFRAME)
  GUICtrlSetCursor( $idLabelAsDivider, 11 )
  GUISetState( @SW_SHOWNOACTIVATE, $hGuiAsDivider )
  GUISwitch( $hForm1 )

  GUIRegisterMsg( $WM_SIZE, "WM_SIZE" )
  GUIRegisterMsg( $WM_GETMINMAXINFO, "WM_GETMINMAXINFO" )

  GUISetState(@SW_SHOW)

  While 1
    Switch GUIGetMsg()
      Case $idLabelAsDivider
        ResizeEditCtrls()

      Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESIZED
        Local $aPos1 = ControlGetPos( $hForm1, "", $idEdit1 )
        WinMove( $hGuiAsDivider, "", Default, WinGetPos( $hForm1 )[1] + $iTitlebarHeight + $iBorderHeight + $aPos1[3] + 20 + 2, $aPos1[2] )
        ControlMove( $hForm1, "", $idEdit2, default, $aPos1[3] + 40 )

      Case $GUI_EVENT_RESTORE
        Local $aPos1 = ControlGetPos( $hForm1, "", $idEdit1 )
        If $aPos1[3] < 100 Then
          GUICtrlSetResizing($idEdit1, $GUI_DOCKALL )
          GUICtrlSetResizing($idEdit2, $GUI_DOCKALL )
          ControlMove( $hForm1, "", $idEdit1, Default, Default, $aPos1[2], 100 )
          ControlMove( $hForm1, "", $idEdit2, Default, 100 + 40, $aPos1[2], WinGetClientSize( $hForm1 )[1] - 100 - 40 - 10 )
          GUICtrlSetResizing($idEdit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
          GUICtrlSetResizing($idEdit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
        EndIf
        WinMove( $hGuiAsDivider, "", Default, WinGetPos( $hForm1 )[1] + $iTitlebarHeight + $iBorderHeight + $aPos1[3] + 20 + 2, $aPos1[2] )

      Case $GUI_EVENT_CLOSE
        ExitLoop

    EndSwitch
  WEnd

  ; Cleanup
  GUIDelete($hForm1)
  Exit
EndFunc

Func ResizeEditCtrls()
  Local $aInfo = GUIGetCursorInfo( $hForm1 ), $y0 = $aInfo[1], $yPrev = $aInfo[1], $dy
  Local $aPos = WinGetPos( $hGuiAsDivider ), $aPos1 = ControlGetPos( $hForm1, "", $idEdit1 ), $aPos2 = ControlGetPos( $hForm1, "", $idEdit2 )
  GUICtrlSetResizing($idEdit1, $GUI_DOCKALL )
  GUICtrlSetResizing($idEdit2, $GUI_DOCKALL )
  Do
    If $aInfo[1] <> $yPrev Then
      $dy = $aInfo[1] - $y0
      If $aPos1[3] + $dy > 100 And $aPos2[3] - $dy > 100 Then
        WinMove( $hGuiAsDivider, "", Default, $aPos[1] + $dy )
        ControlMove( $hForm1, "", $idEdit1, Default, Default, $aPos1[2], $aPos1[3] + $dy )
        ControlMove( $hForm1, "", $idEdit2, Default, $aPos2[1] + $dy, $aPos2[2], $aPos2[3] - $dy )
      EndIf
      $yPrev = $aInfo[1]
    EndIf
    $aInfo = GUIGetCursorInfo( $hForm1 )
  Until $aInfo[2] = 0
  GUICtrlSetResizing($idEdit1, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM)
  GUICtrlSetResizing($idEdit2, $GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKBOTTOM+$GUI_DOCKHEIGHT)
  $iMinHeight = 0
EndFunc

; Resize the status bar when GUI size changes
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam, $lParam
  Local $aPos = ControlGetPos( $hForm1, "", $idEdit1 )
  If $aPos[3] <= 100 Then $iMinHeight = WinGetPos( $hForm1 )[3]
  WinMove( $hGuiAsDivider, "", Default, WinGetPos( $hForm1 )[1] + $iTitlebarHeight + $iBorderHeight + $aPos[3] + 20, $aPos[2] )
  Return $GUI_RUNDEFMSG
EndFunc

Func WM_GETMINMAXINFO( $hWnd, $iMsg, $wParam, $lParam )
  Local $tMINMAXINFO = DllStructCreate( "int;int;int;int;int;int;int;int;int;int", $lParam )
  DllStructSetData( $tMINMAXINFO, 8, $iMinHeight ) ; Min GUI height
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...