Jump to content

Stop a window from being resized to small


Recommended Posts

this is a quick mockup of one approach

GUISetOnEvent($GUI_EVENT_RESIZED, "_reSize", $myGUI)

Func _reSize()
    $minW = 500
    $minH = 200
    $myGuiInfo = WinGetPos($myGUI)
    If ($myGuiInfo[2] < $minW) Or ($myGuiInfo[3] < $minH) Then
        WinMove($myGUI, "", $myGuiInfo[0], $myGuiInfo[1], $minW, $minH)
    EndIf
EndFunc
Link to comment
Share on other sites

  • Moderators

IchBistTod,

Easy when you know how! :)

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

Global $GUIMINWID = 300, $GUIMINHT = 100 ; set your restrictions here
Global $GUIMAXWID = 800, $GUIMAXHT = 500

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

$hGUI = GUICreate("Test", 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

GUISetState()

$aPos = WinGetPos($hGUI)

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

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo,  7, $GUIMINWID) ; min X
    DllStructSetData($tagMaxinfo,  8, $GUIMINHT)  ; min Y
    DllStructSetData($tagMaxinfo,  9, $GUIMAXWID) ; max X
    DllStructSetData($tagMaxinfo, 10, $GUIMAXHT)  ; max Y
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

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

I tried something a little different but im curious Melba23

I did this from your code

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

Global $GUIMINWID = 516, $GUIMINHT = 538 ; set your restrictions here
Global $GUIMAXWID = 516, $GUIMAXHT = 538

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

$hGUI = GUICreate("Test", 500, 500, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

GUISetState()

$aPos = WinGetPos($hGUI)

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

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo,  7, $GUIMINWID) ; min X
    DllStructSetData($tagMaxinfo,  8, $GUIMINHT)  ; min Y
    DllStructSetData($tagMaxinfo,  9, $GUIMAXWID) ; max X
    DllStructSetData($tagMaxinfo, 10, $GUIMAXHT)  ; max Y
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

This bit

Global $GUIMINWID = 516, $GUIMINHT = 538 ; set your restrictions here

Global $GUIMAXWID = 516, $GUIMAXHT = 538

It was odd i had to do more then 500 on each to get it to lock the window so its moveable but it dosent change size when you touch it? can you explain why?

Or is there an easier way?

Chimaera

Edited by Chimaera
Link to comment
Share on other sites

  • Moderators

Chimaera,

When you create the GUI the size coordinates refer to the "client area" - the bit inside the borders. When you use the WM_GETMINMAXINFO struct, the coordinates refer to the whole GUI - including the borders. So you need to make the struct sizes slightly bigger that the initial GUI if you do not want a jump in size when you first try to resize. I hope this script makes it clearer - resise the "Test" GUI and you will see that it fits neatly inside the client area of the "Sizer" GUI: :P

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

Global $GUIMINWID = 200, $GUIMINHT = 200 ; set your restrictions here
Global $GUIMAXWID = 200, $GUIMAXHT = 200

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")

$hGUI = GUICreate("Test", 200, 200, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))

GUISetState()

$hGUI_2 = GUICreate("Sizer", 200, 200, 100, 100)

GUISetState()

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

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)
    DllStructSetData($tagMaxinfo,  7, $GUIMINWID) ; min X
    DllStructSetData($tagMaxinfo,  8, $GUIMINHT)  ; min Y
    DllStructSetData($tagMaxinfo,  9, $GUIMAXWID) ; max X
    DllStructSetData($tagMaxinfo, 10, $GUIMAXHT)  ; max Y
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

Does that explain it clearly enough? :)

As to making a GUI immoveable, you just need to intercept the $SC_MOVE message like this:

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

Const $SC_MOVE = 0xF010

$hGUI_Move  = GUICreate("Movable GUI", 500, 500, 100, 100)
GUISetState()

$hGUI_Static = GUICreate("Immovable GUI", 500, 500, 200, 200)
GUISetState()

GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
    If $hWnd = $hGUI_Static Then
        If BitAND($wParam, 0x0000FFF0) = $SC_MOVE Then Return False
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

All clear? :)

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

Aah thanks for the lesson o mighty one

This is what i wanted a simple Gui that cannot be streched but can be moved

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

Const $SC_MOVE = 0xF010

$hGUI_Move  = GUICreate("Movable GUI", 500, 500)
GUISetState()

While GUIGetMsg() <> $GUI_EVENT_CLOSE
WEnd

Many thanks Melba23

Link to comment
Share on other sites

  • Moderators

Chimaera,

o mighty one

Not at all - just been around a bit longer. :)

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

Thanks for the lesson M23. I wish I had learned this years ago. I've been using wingetpos() and winmove() in my ignorance. It's a truth that you never stop learning.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

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