Moderators big_daddy Posted January 7, 2008 Moderators Posted January 7, 2008 I may be missing something completely obvious, but I've worked on this for 3 days now and it has the best of me. All I want to do is use the remaining client area of the GUI to create/resize my ListView, but the numbers I'm getting back are confusing me. Can a GUI expert explain to me what is happening here. Environment: Win XP SP2 AutoIt v3.2.10.0 I have commented the following code. expandcollapse popup#include <WinAPI.au3> #include <GuiStatusBar.au3> #include <GUIConstantsEx.au3> Global $iWidth = 600 Global $iHeight = 400 Global $iStatusMinHeight = 35 Opt("GUIOnEventMode", True) $GUI = GUICreate("Test", $iWidth, $iHeight) ; If we remove $WS_SIZEBOX the 2 pixels mentioned below are not an issue. GUISetStyle(BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SIZEBOX, $WS_POPUP, $WS_SYSMENU)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ; This shows the client area as expected. (600x400) $aPos = WinGetClientSize($GUI) ConsoleWrite("Client Area Before Menu" & @CR & "Width:" & $aPos[0] & @CR & "Height:" & $aPos[1] & @CR & @CR) $File = GUICtrlCreateMenu("File") $Exit = GUICtrlCreateMenuItem("Exit", $File) GUICtrlSetOnEvent(-1, "_Exit") ; This shows the client area after the menu is added. (598x378) Where did the extra 2 pixels go? $aPos = WinGetClientSize($GUI) $iWidth = $aPos[0] $iHeight = $aPos[1] ConsoleWrite("Client Area After Menu" & @CR & "Width:" & $iWidth & @CR & "Height:" & $iHeight & @CR & @CR) ; This explains where 20 pixels went, but there are still 2 unexplained. $iMenuHeight = _WinAPI_GetSystemMetrics($SM_CYMENU) ConsoleWrite("Actual Menu Height: " & $iMenuHeight & @CR) Dim $aText[3] = ["Left Justified", @TAB & "Centered", @TAB & @TAB & "Right Justified"] Dim $aParts[3] = [100, 175, -1] $hStatusBar = _GUICtrlStatusBar_Create($GUI, $aParts, $aText) ; Here we set the minimum height of a status bar. (35) _GUICtrlStatusBar_SetMinHeight($hStatusBar, $iStatusMinHeight) ; I would expect this to return at least 35 which was set above. $iStatusHeight = _GUICtrlStatusBar_GetHeight($hStatusBar) ConsoleWrite("Actual StatusBar Height: " & $iStatusHeight & @CR) ; Unless my logic is off this should give me the correct size for my ListView. $iListViewWidth = $iWidth $iListViewHeight = $iHeight - $iStatusHeight $sHeaders = "Items|SubItems 1|SubItems 2" $hListView = _GUICtrlListView_Create($GUI, $sHeaders, 0, 0, $iListViewWidth, $iListViewHeight) ; Set the column widths to give horizontal scroll bars. _GUICtrlListView_SetColumnWidth($hListView, 0, 200) _GUICtrlListView_SetColumnWidth($hListView, 1, 200) _GUICtrlListView_SetColumnWidth($hListView, 2, 200) ; Add some items so we have vertical scroll bars. Dim $aItems[51][1] For $iI = 0 To UBound($aItems) - 1 $aItems[$iI][0] = "Item " & $iI Next _GUICtrlListView_AddArray($hListView, $aItems) GUISetState(@SW_SHOW) While 1 Sleep(100) WEnd Func _Exit() Exit EndFunc ;==>_Exit
Siao Posted January 7, 2008 Posted January 7, 2008 (edited) Window - resizeable border is wider than normal border, by 1 pixel usually. You can get these from GetSystemMetrics too. With that said, I don't know why this would change the client size of GUI after creating a menu. StatusBar - SetMinHeight vs GetHeight. MSDN says about MinHeight - "The minimum height is the sum of wParam and twice the width, in pixels, of the vertical border of the status window." GetHeight UDF does the math for you, subtracting vert border twice. Edited January 7, 2008 by Siao "be smart, drink your wine"
ReFran Posted January 8, 2008 Posted January 8, 2008 (edited) Hi, I'm not sure if that fits to that what you want. I started yesterday to set up a resizable GUI. Finally I want to have: ---------------------- | Tree- |Tab1|Tab2| | view |------------ | | | Listview | |--------| | | Edit | | --------------------- Should be resizeable horizontal between Treeview and Edit and vertical between treeview/Edit and Tabs/Listview. To get a start up I took the GUI from AutoITExplorer example from Holger and shorten it. So at time I have - basicly - treeview and listview horizontal resizable. Perhabs it helps you, perhaps someone have have a better example (if it fits to that what you want.) Best regards, Reinhard expandcollapse popup;;;;; GUI-Resizable with treeview and listview;;;;;;;; ;;;; from AutoItexplorer examble by Holger (at least if I remember right);;;;;; #include <GUIConstants.au3> #include <GUITreeView.au3> #Include <GuiListView.au3> $hGui = GUICreate("AutoIt3-Explorer V1.1a;-)", 762, 578, -1, -1, BitOr($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) $nFileMenu = GUICtrlCreateMenu("&File") $editMenu = GUICtrlCreateMenu("&Edit") $nViewMenu = GUICtrlCreateMenu("&View") $nViewItem1 = GUICtrlCreateMenuItem("Icons", $nViewMenu, -1, 1) $nViewItem2 = GUICtrlCreateMenuItem("Report", $nViewMenu, -1, 1) GUICtrlCreateLabel("", 0, 0, 800, 2, BitOr($SS_SUNKEN, $SS_BLACKRECT)) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT) $nTreeView = GUICtrlCreateTreeView(0, 25, 310, 513, -1, $WS_EX_CLIENTEDGE) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) $nListView = GUICtrlCreateListView("Name|Size|Type|Changed|No.",314, 25, 447, 513) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) $nSplitter = GUICtrlCreateLabel("", 310, 29, 4, 509) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW, $hGui) $curpressed = 0 $splitx1 = 48 $splitx2 = 52 $savex = 310 $pressed = 0 While 1 $nMsg = GUIGetMsg() $arInfo = GUIGetCursorInfo() If $pressed = 1 And $arInfo[2] = 0 Then $pressed = 0 If $pressed = 1 And $arInfo[2] = 1 Then $arPos = WinGetPos($hGui) If $arInfo[0] > 100 And $arInfo[0] < $arPos[2] - 100 Then If $arInfo[0] <> $savex Then ControlMove($hGui, "", $nSplitter, $arInfo[0] - 2, 29) ControlMove($hGui, "", $nTreeView, 0, 25, $arInfo[0] - 2) ControlMove($hGui, "", $nListView, $arInfo[0] + 2, 25, $arPos[2] - $arInfo[0] - 10) $savex = $arInfo[0] EndIf EndIf EndIf Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $nSplitter $cinfo = GUIGetCursorInfo() If $cinfo[2] = 1 Then $pressed = 1 EndSwitch WEnd Edited January 8, 2008 by ReFran
ReFran Posted January 8, 2008 Posted January 8, 2008 (edited) Hi, is there somewhere a resize event? I got it so far, whith some problems for the Editbox. The high of the editbox has to set more flexible if the box is vertical moved, I think no problem. But if the total Gui will be resized in high I have to calculate the top new (somewhat 20pts. under treeview). How can I detect that general changement? Best regards, Reinhard expandcollapse popup;;;;; GUI-Resizable with treeview and listview;;;;;;;; ;;;; from AutoItexplorer examble by Holger (at least if I remember right);;;;;; #include <GUIConstants.au3> #include <GUITreeView.au3> #Include <GuiListView.au3> $hGui = GUICreate("GUI _ Resize", 762, 578, -1, -1, BitOr($WS_SIZEBOX, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU)) $nFileMenu = GUICtrlCreateMenu("&File") $editMenu = GUICtrlCreateMenu("&Edit") $nViewMenu = GUICtrlCreateMenu("&View") $nViewItem1 = GUICtrlCreateMenuItem("Icons", $nViewMenu, -1, 1) $nViewItem2 = GUICtrlCreateMenuItem("Report", $nViewMenu, -1, 1) GUICtrlCreateLabel("", 0, 0, 800, 2, BitOr($SS_SUNKEN, $SS_BLACKRECT)) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT) $TreeView = GUICtrlCreateTreeView(0, 25, 310-100, 330, -1, $WS_EX_CLIENTEDGE) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) $TVitem1 = GUICtrlCreateTreeViewitem("General", $treeview) GUICtrlSetColor(-1, 0x0000C0) $TVitem2 = GUICtrlCreateTreeViewitem("Display", $treeview) GUICtrlSetColor(-1, 0x0000C0) $TVitem3 = GUICtrlCreateTreeViewitem("About", $tvItem2) $myedit=GUICtrlCreateEdit ("First line"& @CRLF, 0,376,310-100,160,-1) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) $hSplitter = GUICtrlCreateLabel("---------------------",1, 360, 310-100, 15) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH) $nListView = GUICtrlCreateListView("Name|Size|Type|Changed|No.",314-100, 25, 447+100, 513) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM) GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) $vSplitter = GUICtrlCreateLabel("", 310-100, 29, 4, 509) GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKWIDTH) GUISetState(@SW_SHOW, $hGui) $savex = 310-100 $pressed = 0 $vPressed = 0 While 1 $nMsg = GUIGetMsg() $arInfo = GUIGetCursorInfo() If $pressed = 1 And $arInfo[2] = 0 Then $pressed = 0 If $pressed = 1 And $arInfo[2] = 1 Then $arPos = WinGetPos($hGui) If $arInfo[0] > 100 And $arInfo[0] < $arPos[2] - 100 Then If $arInfo[0] <> $savex Then ControlMove($hGui, "", $vSplitter, $arInfo[0] - 2, 29) ControlMove($hGui, "", $TreeView, 0, 25, $arInfo[0] - 2) ControlMove($hGui, "", $myedit, 0, 376, $arInfo[0] - 2) ControlMove($hGui, "", $nListView, $arInfo[0] + 2, 25, $arPos[2] - $arInfo[0] - 10) $savex = $arInfo[0] EndIf EndIf EndIf Switch $nMsg Case $GUI_EVENT_CLOSE ExitLoop Case $vSplitter $cinfo = GUIGetCursorInfo() If $cinfo[2] = 1 Then $pressed = 1 Case $hSplitter $hinfo = GUIGetCursorInfo() If $hinfo[2] = 1 Then $vPressed = 1 ;msgbox(0,"","is preseed on "&$hInfo[4]) VertResize($hInfo) endif EndSwitch WEnd func VertResize($hInfo) $fixInfo = $hInfo while $hInfo[2] = 1 $arInfo = GUIGetCursorInfo() ;ControlMove ( "title", "text", controlID, x, y [, width [, height]] ) ControlMove($hGui, "", $hSplitter, 1,$arInfo[1] - 2) ;ControlMove($hGui, "", $TreeView, 0, 25, $arInfo[0] - 2) ;ControlMove($hGui, "", $myedit, 0, 376, $arInfo[0] - 2) $hInfo=$ArInfo WEnd ControlMove($hGui, "", $TreeView, 0,25,310-100, $arInfo[1] - 25) ControlMove($hGui, "", $myedit, 0, $arInfo[1] +20,310-100,160-($arInfo[1]-$FixInfo[1])) endfunc Edited January 8, 2008 by ReFran
Moderators big_daddy Posted January 12, 2008 Author Moderators Posted January 12, 2008 Window - resizeable border is wider than normal border, by 1 pixel usually. You can get these from GetSystemMetrics too. With that said, I don't know why this would change the client size of GUI after creating a menu.Thanks, this explains the 2 pixels.StatusBar - SetMinHeight vs GetHeight.MSDN says about MinHeight - "The minimum height is the sum of wParam and twice the width, in pixels, of the vertical border of the status window." GetHeight UDF does the math for you, subtracting vert border twice.GetHeight doesn't return the correct value for me. The window info tool does return the correct height however.---@ReFran - I can't use GUICtrlSetResizing because I'm using the UDF version of the ListView Control.---Anyone else have a solution that can make this resizing situation dynamic?
Siao Posted January 12, 2008 Posted January 12, 2008 (edited) Just add this to your code: GUIRegisterMsg($WM_SIZE, "On_WM_SIZE") ; ; Func On_WM_SIZE() Local $aSBarPos _GUICtrlStatusBar_Resize($hStatusBar) $aSBarPos = ControlGetPos($GUI, "", $hStatusBar) ControlMove($GUI, "", $hListView, 0, 0, $aSBarPos[2], $aSBarPos[1]) Return $GUI_RUNDEFMSG EndFunc Edited January 12, 2008 by Siao "be smart, drink your wine"
Moderators big_daddy Posted January 12, 2008 Author Moderators Posted January 12, 2008 Just add this to your code:I was trying to make it harder than it actually was. That seems to have done the trick, thanks!
dabus Posted August 5, 2008 Posted August 5, 2008 Hi there, I got a similar problem: In the main part of the script, I place some pics on the GUI to have a light theme. This works as expected. After some thoughts, I got rid of the fixed windowsize and use GuiCtrlSetResize to move the pics as desired. Cool and slick. I also wanted to avoid my gui to be to small or too big. So I used the great example Siao gave and added some WinMove-functions. This works for itself, but the movement seems not to be recogniced by GuiCtrlSetResize. Is it possible to give GuiCtrlSetResize a signal to start updating the theme? Or will I have to have a list of pics and move them around "manually"? Any ideas? .. GuiCreate('Bla', 200, 200) GuiCtrlCreatePic('SomePic.bmp', 180, 0, 20, 20, $WS_DISABLED); upper right corner GUICtrlSetResizing(-1, 4+32+256+512) .. .. Func _WM_ON_SIZE() $Pos = WinGetPos($sGui) If $Pos[2]< 750 Then WinMove($sGui, "", $Pos[0], $Pos[1], 750, $Pos[3]) If $ExtGui And $Pos[3]< 450 Then WinMove($sGui, "", $Pos[0], $Pos[1], $Pos[2], 450) If Not $ExtGui And $Pos[3]< 175 Then WinMove($sGui, "", $Pos[0], $Pos[1], $Pos[2], 175) If $Pos[2]> 1600 Then WinMove($sGui, "", $Pos[0], $Pos[1], 1600, $Pos[3]) If $Pos[3]> 1200 Then WinMove($sGui, "", $Pos[0], $Pos[1], $Pos[2], 1200) Return $GUI_RUNDEFMSG EndFunc
Zedna Posted August 5, 2008 Posted August 5, 2008 I also wanted to avoid my gui to be to small or too big.Look here http://www.autoitscript.com/forum/index.ph...st&p=328186 Resources UDF ResourcesEx UDF AutoIt Forum Search
dabus Posted August 5, 2008 Posted August 5, 2008 (edited) I just managed to do it by myself. All I needed to do was to use another global var and I'm set. .. If $WinResized Then $WinResized=False $Pos = WinGetPos($sGui) If $Pos[2]< 750 Then _GuiMove($sGui, "", $Pos[0], $Pos[1], 750, $Pos[3]) EndIf Func _GuiMove($a, $b, $c, $d, $e, $f) WinMove($a, $b, $c, $d, $e, $f) $WinResized = True EndFunc Func _WM_ON_SIZE() ConsoleWrite('-'&$WinResized&@CRLF) $WinResized=True Return $GUI_RUNDEFMSG EndFunc -- Edit -- @Zedna: Thank you. That's much better. Edited August 5, 2008 by dabus
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