Jump to content

Get width control when GUI is maximized


 Share

Recommended Posts

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GUICtrlOnHover.au3>
#include <WinAPI.au3>
#include <GuiListView.au3>


#Region ### START Koda GUI section ### Form=c:\users\user\desktop\Автоключ\form1.kxf

$hGUI = GUICreate('Электронный заказ. ООО "ИК Автоключ"', 950, 765, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX))
$idUpdatePrice = GUICtrlCreateLabel("Обновить прайс", 830, 5, 100, Default, $SS_RIGHT)
GUICtrlSetFont(-1, Default)
_GUICtrl_OnHoverRegister(-1, "_Style_1", "_Style_1_1")
GUICtrlSetResizing(-1, 4 + 768)

$idTab = GUICtrlCreateTab(10, 10, 930, 700)
GUICtrlSetResizing(-1, 102)

GUICtrlCreateTabItem("Каталог товаров")

GUICtrlCreateLabel('', 20, 40, 180, 180, $SS_BLACKRECT)
GUICtrlSetResizing(-1, 802)

GUICtrlCreateLabel("Сумма заказа:", 20, 235, 180, Default, $SS_CENTER)
GUICtrlSetFont(-1, 10, 700, 0, "Verdana")
GUICtrlSetResizing(-1, 802)

$idTotal = GUICtrlCreateLabel("250000.00 руб.", 20, 255, 180, Default, $SS_CENTER)
GUICtrlSetFont(-1, 14, 700, 0, "Verdana")
GUICtrlSetColor(-1, $COLOR_GREEN)
GUICtrlSetResizing(-1, 802)

$idSaveOrder = GUICtrlCreateLabel("Сохранить заказ", 20, 290, 180, Default, $SS_RIGHT)

GUICtrlSetFont(-1, Default)
_GUICtrl_OnHoverRegister(-1, "_Style_2", "_Style_2_1")
GUICtrlSetResizing(-1, 802)


GUICtrlCreateLabel("Фильтр по наименованию / коду:", 20, 350, 180)
GUICtrlSetResizing(-1, 768 + 64 + 2)
$idSearchText = GUICtrlCreateInput("", 20, 370, 155, 23)
GUICtrlSetResizing(-1, 768 + 64 + 2)
$idSearchGo = GUICtrlCreateButton("Х", 180, 370, 23, 23)
GUICtrlSetResizing(-1, 768 + 64 + 2)

$idCatalog = GUICtrlCreateListView("Код|Наименование товара|Производитель|Цена", 210, 40, 720, 353)
GUICtrlSetResizing(-1, 102)
_GUICtrlListView_SetColumnWidth($idCatalog, 0, 50)
_GUICtrlListView_SetColumnWidth($idCatalog, 1, 495)
_GUICtrlListView_SetColumnWidth($idCatalog, 2, 100)
_GUICtrlListView_SetColumnWidth($idCatalog, 3, 70)
$idOrder = GUICtrlCreateListView("", 20, 400, 910, 300)
GUICtrlSetResizing(-1, 576 + 2 + 4)
$idStatusbar = _GUICtrlStatusBar_Create($hGUI)


GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

$tRect = _WinAPI_GetWindowRect($hGUI)
;MsgBox(0,'',DllStructGetData($tRect, "Right")-DllStructGetData($tRect, "Left"))

GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; Monitors resizing of the GUI


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

    EndSwitch

WEnd

Func _Style_1()
    ;GUICtrlSetBkColor($idUpdatePrice, 0xbac3e0)
    GUICtrlSetFont($idUpdatePrice, Default, Default, 4)
    GUICtrlSetCursor($idUpdatePrice, 0)
EndFunc   ;==>_Style_1

Func _Style_1_1()
    ;GUICtrlSetBkColor($idUpdatePrice, -1)
    GUICtrlSetFont($idUpdatePrice, Default, Default, Default)
    GUICtrlSetCursor($idUpdatePrice, -1)
EndFunc   ;==>_Style_1_1

Func _Style_2()
    ;GUICtrlSetBkColor($idUpdatePrice, 0xbac3e0)
    GUICtrlSetFont($idSaveOrder, Default, Default, 4)
    GUICtrlSetCursor($idSaveOrder, 0)
EndFunc   ;==>_Style_2

Func _Style_2_1()
    ;GUICtrlSetBkColor($idUpdatePrice, -1)
    GUICtrlSetFont($idSaveOrder, Default, Default, Default)
    GUICtrlSetCursor($idSaveOrder, -1)
EndFunc   ;==>_Style_2_1



Func _WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam) ; used to limit the minimum size of the GUI
    #forceref $hWnd, $Msg, $wParam, $lParam
    If $hWnd = $hGUI Then
        Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
        DllStructSetData($tagMaxinfo, 7, 964) ; min width
        DllStructSetData($tagMaxinfo, 8, 800) ; min height

        ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)
        _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)

        Return $GUI_RUNDEFMSG
    EndIf
    _GUICtrlListView_SetColumnWidth($idCatalog, 1, 700)

EndFunc   ;==>_WM_GETMINMAXINFO


Func MY_WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    _GUICtrlStatusBar_Resize($idStatusbar)
    ;ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)
    _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_SIZE

When the GUI is maximized (_WM_GETMINMAXINFO), the _GUICtrlListView_SetColumnWidth function does not work. Can you explain why?

Link to comment
Share on other sites

Actions:

ConsoleWrite(WinGetPos(ControlGetHandle($hGUI, "", $idCatalog))[2] & @CRLF)
ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)

do not get the correct width of idCatalogobject when I maximized the GUI.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


$hGUI = GUICreate('---', 950, 765, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX))
$idCatalog = GUICtrlCreateListView("Code|Name|Mnf|Price", 210, 40, 720, 353)
GUICtrlSetResizing(-1, 102)
_GUICtrlListView_SetColumnWidth($idCatalog, 0, 50)
_GUICtrlListView_SetColumnWidth($idCatalog, 1, 495)
_GUICtrlListView_SetColumnWidth($idCatalog, 2, 100)
_GUICtrlListView_SetColumnWidth($idCatalog, 3, 70)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; Monitors resizing of the GUI


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

    EndSwitch
WEnd


Func _WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam) ; used to limit the minimum size of the GUI
    #forceref $hWnd, $Msg, $wParam, $lParam
    If $hWnd = $hGUI Then
        Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
        DllStructSetData($tagMaxinfo, 7, 964) ; min width
        DllStructSetData($tagMaxinfo, 8, 800) ; min height

        ConsoleWrite(WinGetPos(ControlGetHandle($hGUI, "", $idCatalog))[2] & @CRLF)
        ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)
        _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)

        Return $GUI_RUNDEFMSG
    EndIf
EndFunc   ;==>_WM_GETMINMAXINFO


Func MY_WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_SIZE

 

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>


$hGUI = GUICreate('---', 950, 765, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX))
$idCatalog = GUICtrlCreateListView("Code|Name|Mnf|Price", 210, 40, 720, 353)
GUICtrlSetResizing(-1, 102)
_GUICtrlListView_SetColumnWidth($idCatalog, 0, 50)
_GUICtrlListView_SetColumnWidth($idCatalog, 1, 495)
_GUICtrlListView_SetColumnWidth($idCatalog, 2, 100)
_GUICtrlListView_SetColumnWidth($idCatalog, 3, 70)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

;~ GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
;~ GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; Monitors resizing of the GUI


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
        Case $GUI_EVENT_RESIZED, $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
            SetColumnWidth()

    EndSwitch
WEnd

Func SetColumnWidth()
        ConsoleWrite(WinGetPos(ControlGetHandle($hGUI, "", $idCatalog))[2] & @CRLF)
        ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)
        _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)
EndFunc

;~ Func _WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam) ; used to limit the minimum size of the GUI
;~     #forceref $hWnd, $Msg, $wParam, $lParam
;~     If $hWnd = $hGUI Then
;~         Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
;~         DllStructSetData($tagMaxinfo, 7, 964) ; min width
;~         DllStructSetData($tagMaxinfo, 8, 800) ; min height

;~      SetColumnWidth()

;~         Return $GUI_RUNDEFMSG
;~     EndIf
;~ EndFunc   ;==>_WM_GETMINMAXINFO


;~ Func MY_WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
;~     SetColumnWidth()
;~     Return $GUI_RUNDEFMSG
;~ EndFunc   ;==>MY_WM_SIZE

 

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

  • Moderators

AMSPeople,

Please stick to just the one thread.

And you need to allow the resizing event to return before resetting the column width:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Global $bSized = False

$hGUI = GUICreate('---', 950, 765, Default, Default, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX))
$idCatalog = GUICtrlCreateListView("Code|Name|Mnf|Price", 210, 40, 720, 353)
GUICtrlSetResizing(-1, 102)
_GUICtrlListView_SetColumnWidth($idCatalog, 0, 50)
_GUICtrlListView_SetColumnWidth($idCatalog, 1, 495)
_GUICtrlListView_SetColumnWidth($idCatalog, 2, 100)
_GUICtrlListView_SetColumnWidth($idCatalog, 3, 70)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; Monitors resizing of the GUI


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

    EndSwitch

    If $bSized Then
        _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)
        $bSized = False
    EndIf
WEnd


Func _WM_GETMINMAXINFO($hWnd, $Msg, $wParam, $lParam) ; used to limit the minimum size of the GUI
    #forceref $hWnd, $Msg, $wParam, $lParam
    If $hWnd = $hGUI Then
        Local $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
        DllStructSetData($tagMaxinfo, 7, 964) ; min width
        DllStructSetData($tagMaxinfo, 8, 800) ; min height

        ConsoleWrite(WinGetPos(ControlGetHandle($hGUI, "", $idCatalog))[2] & @CRLF)
        ConsoleWrite(ControlGetPos($hGUI, '', $idCatalog)[2] & @CRLF)
        _GUICtrlListView_SetColumnWidth($idCatalog, 1, ControlGetPos($hGUI, '', $idCatalog)[2] - 230)

        Return $GUI_RUNDEFMSG
    EndIf
EndFunc   ;==>_WM_GETMINMAXINFO


Func MY_WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    $bSized = True
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_SIZE

M23

Edit: Or as argumentum has done above, use the built-in events - the methodology is the same.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...