Jump to content

Resize window


Chorda
 Share

Recommended Posts

Hi,

There are about 9 posts about window resizing here but none that actually answers my question.

I have a simple window with basically just a few labels in it. Those labels are pulled from an .ini file, and so their width will change depending on the values inside the .ini file.

I would like to have the window resize itself upon starting to just encompass those labels. I couldn't find a common style value $WS_xxxxx or the GUICtrlSetResizing (which apparently just locks things), or WinMove(). Well, of course, I could just keep track of all the widths and heights and add them up or something. But I would imagine that there must be a command to resize.

Any idea?

Thanks

Edited by Chorda
Link to comment
Share on other sites

I am retrieving the sizes of the Labels in a loop and I am keeping the biggest one:

CODE
$pos = ControlGetPos($MenuWindow, "", $AppLabel)

If $pos[2] > $MaxLabelWidth Then $MaxLabelWidth = $pos[2]

And then at the end, I resize the window with the biggest width:

CODE
WinMove($MenuWindow, "", Default, Default, $MaxLabelWidth)

I like WinMove() because I can use the Default keyword instead of values for the positions.

So in terms of resizing while keeping the window in the center of the screen, that works, but, I am also using the following code to resize the Labels based on the font (thanks ResNullius for the code):

CODE
Func _Control_SetWidth2Text($hWin, $sWinText, $hCtrl, $iPad = 0)

;author: ResNullius, based on PaulIA/GaryFrost (listview udf)

Local $hWnd, $hDC, $hFont, $iMax, $tSize, $sText, $aCtrlPos, $ctrlX, $ctrlY, $ctrlW, $ctrlH

If Not IsHWnd($hCtrl) Then

$hWnd = ControlGetHandle($hWin, $sWinText, $hCtrl)

Else

$hWnd = $hCtrl

EndIf

If IsHWnd($hWnd) Then

$hFont = _SendMessage($hWnd, $WM_GETFONT)

$hDC = _WinAPI_GetDC($hWnd)

_WinAPI_SelectObject($hDC, $hFont)

$sText = ControlGetText($hWin, $sWinText, $hCtrl)

$tSize = _WinAPI_GetTextExtentPoint32($hDC, $sText & " ")

If DllStructGetData($tSize, "X") > $iMax Then

$iMax = DllStructGetData($tSize, "X") + $iPad

$aCtrlPos = ControlGetPos($hWin, $sWinText, $hCtrl)

$ctrlX = $aCtrlPos[0]

$ctrlY = $aCtrlPos[1]

$ctrlW = $aCtrlPos[2]

$ctrlH = $aCtrlPos[3]

ControlMove($hWin, $sWinText, $hCtrl, $ctrlX, $ctrlY, $iMax, $ctrlH)

EndIf

_WinAPI_SelectObject($hDC, $hFont)

_WinAPI_ReleaseDC($hWnd, $hDC)

EndIf

EndFunc;==>_Control_SetWidth2Text

But the problem is that as soon as I include the WinMove() function, it apparently resizes my Labels back to their original smaller sizes, and my texts get trunckated. I tried to Lock the Labels, but they still revert to a smaller size.

Link to comment
Share on other sites

Well, if you use ControlMove, AutoIt doesn't save the new size and pos. Use GUICtrlSetPos instead,

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 10 months later...

can anyone help me?

ı need resize windows but ı dont understand how can ı do.

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

$Form1 = GUICreate("Resize", 342, 152, 385, 313)

$Input1 = GUICtrlCreateInput("window name", 32, 56, 121, 21)

$Combo1 = GUICtrlCreateCombo("100", 176, 56, 145, 25)

GUICtrlSetData(-1, "100|90|80|70|60|50|40|30|20|10")

$Button1 = GUICtrlCreateButton("Resize", 176, 96, 147, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

I need help with "if pressed to button , read combo and resize

Link to comment
Share on other sites

  • Moderators

Jeyka ,

You need to capture the button press via GUIGetMsg(). Take a look at this:

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("Resize", 340, 150)

$Input1 = GUICtrlCreateInput("window name", 30, 60, 120, 20)
$Combo1 = GUICtrlCreateCombo("", 175, 60, 145, 25)
GUICtrlSetData(-1, "400|450|500|550|600|650")
$Button1 = GUICtrlCreateButton("Resize", 175, 100, 150, 25)

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $New_Width = GUICtrlRead($Combo1)
            WinMove($Form1, "", Default, Default, $New_Width, 150)
    EndSwitch
WEnd

Ask if anything is unclear.

M23

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

can anyone help me?

ı need resize windows but ı dont understand how can ı do.

#include <ButtonConstants.au3>

#include <ComboConstants.au3>

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <WindowsConstants.au3>

$Form1 = GUICreate("Resize", 342, 152, 385, 313)

$Input1 = GUICtrlCreateInput("window name", 32, 56, 121, 21)

$Combo1 = GUICtrlCreateCombo("100", 176, 56, 145, 25)

GUICtrlSetData(-1, "100|90|80|70|60|50|40|30|20|10")

$Button1 = GUICtrlCreateButton("Resize", 176, 96, 147, 25, $WS_GROUP)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

EndSwitch

WEnd

I need help with "if pressed to button , read combo and resize

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
Dim $hWnd[3]
$hGUI = GUICreate("Resize", 342, 152, 385, 313)
$hWnd[0] = GUICtrlCreateInput("window name", 32, 56, 121, 21)
$hWnd[1] = GUICtrlCreateCombo("100", 176, 56, 145, 25)
GUICtrlSetData(-1, "100|90|80|70|60|50|40|30|20|10")
$hWnd[2] = GUICtrlCreateButton("Resize", 176, 96, 147, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
WindowsResize($hWnd,$hGUI,70)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd

Func WindowsResize($hWnd_Array,$hGUI,$percent)
For $i = 0 To UBound($hWnd_Array) - 1 Step 1
$pos = ControlGetPos($hGUI, "", $hWnd_Array[$i])
$L = $pos[0]
$W = Int(($pos[1] / 100) * $percent)
$L += Int(($pos[1] - $W ) / 2)
$T = $pos[1]
$H = Int(($pos[3] / 100) * $percent)
$T += Int(($pos[3] - $H ) / 2)
GUICtrlSetPos($hWnd_Array[$i], $L, $T , $W , $H)
Next
$pos = WinGetPos($hGUI)
$L = $pos[0]
$W = Int(($pos[1] / 100) * $percent)
$L += Int(($pos[1] - $W ) / 2)
$T = $pos[1]
$H = Int(($pos[3] / 100) * $percent)
$T += Int(($pos[3] - $H ) / 2)
_WinAPI_SetWindowPos($hGUI, 0, $L, $T , $W , $H, 0)
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...