Jump to content

Easy way to maintain minumum window size?


mrider
 Share

Recommended Posts

Greetings all,

I'm looking for a way to make sure that a window which I've created will never get smaller than a certain minimum size. I've put together something that works, but I'm wondering if there's an easier/more efficient way. Also, the code as presented has a weird quirk: I can resize the window down so that it has zero height, and it will remain that way (precisely like a Macintosh window that has been "shaded"). For some reason $GUI_EVENT_RESIZED doesn't register in that event.

So - 1) Is there a better/easier/more efficient way to do this? 2) Any ideas about how to catch the window "shading" bug/quirk?

My code

#include <GUIConstants.au3>
Opt( "GUIOnEventMode", 1 )
Dim $winStyle = BitOr( $WS_POPUP, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX, $WS_THICKFRAME )
Dim $title = "Resizable window test"
Dim $window = GUICreate( $title, 400, 400, -1, -1, $winStyle )
GUISetState()
GUISetOnEvent( $GUI_EVENT_CLOSE, "Quit" )
GUISetOnEvent( $GUI_EVENT_RESIZED, "ResizeHandler" )

Dim $minWidth = 200
Dim $minHeight = 200

While( 1 )
    Sleep( 1000 )
WEnd

Func Quit()
    Exit
EndFunc

Func ResizeHandler()
    Local $pos = WinGetPos( $title )
    MsgBox( 0, "DEBUG", $pos[3] )
    If @error == 1 Then
        MsgBox( 16, "Problem", "Unable to find window" )
        Exit
    EndIf
    If $pos[2] < $minWidth Then
        WinMove( $title, "", $pos[0], $pos[1], $minWidth, $pos[3] )
        Return
    EndIf
    If $pos[3] < $minHeight Then
        WinMove( $title, "", $pos[0], $pos[1], $pos[2], $minHeight )
        Return
    EndIf
EndFunc
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Here is one I use to set MaxWidth. You might be able to use it as a template. NOTE:$Gw is the GUI width and is declared globaly early in the script.

;===============================================================================
; Function Name:   _GuiMaxWidth()
; Description:   Set the maximum width of a GUI window
; Syntax:   _GuiMaxSize([$szMax]
; Parameter(s):   $szMax = The maximum allowable size for the window (Normally @DesktopWidth -5) Default is 1019 (1024-5)
; Requirement(s):   
; Return Value(s):   
; Author(s):   GEOSoft
; Modification(s):   
; Note(s):   
;===============================================================================

Func _GuiMaxWidth($szMax = 1019)
    If $Gw > $szMax Then
        $Gw = $szMax
        $yPos = -1
    EndIf
EndFunc  ;<==> _GuiMaxWidth()

As you can see $szMax is optional and I use 1019 which is 1024 - 5

If you are setting max height you will probably want to set it to @DeskTopHeight - 25 to allow for the taskbar.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Sorry for my ignorance, but I'm not sure how I would incorporate that into what I'm doing. It looks like your method is a way to dynamically set the same values that can be found in my script in "$minWidth" and "$minHeight". Is that correct? If so, I may want to set the values for minimums dynamically at some point, but I'm more concerned with how to detect window size changes, and how to manipulate the window size in code.

Basically, I'm wondering about this part:

Func ResizeHandler()
    Local $pos = WinGetPos( $title )
  ; MsgBox( 0, "DEBUG", $pos[3] )
    If @error == 1 Then
        MsgBox( 16, "Problem", "Unable to find window" )
        Exit
    EndIf
    If $pos[2] < $minWidth Then
        WinMove( $title, "", $pos[0], $pos[1], $minWidth, $pos[3] )
        Return
    EndIf
    If $pos[3] < $minHeight Then
        WinMove( $title, "", $pos[0], $pos[1], $pos[2], $minHeight )
        Return
    EndIf
EndFunc
Edited by mrider

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Greetings all,

I'm looking for a way to make sure that a window which I've created will never get smaller than a certain minimum size. I've put together something that works, but I'm wondering if there's an easier/more efficient way. Also, the code as presented has a weird quirk: I can resize the window down so that it has zero height, and it will remain that way (precisely like a Macintosh window that has been "shaded"). For some reason $GUI_EVENT_RESIZED doesn't register in that event.

So - 1) Is there a better/easier/more efficient way to do this? 2) Any ideas about how to catch the window "shading" bug/quirk?

My code

#include <GUIConstants.au3>
Opt( "GUIOnEventMode", 1 )
Dim $winStyle = BitOr( $WS_POPUP, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SYSMENU, $WS_MINIMIZEBOX, $WS_THICKFRAME )
Dim $title = "Resizable window test"
Dim $window = GUICreate( $title, 400, 400, -1, -1, $winStyle )
GUISetState()
GUISetOnEvent( $GUI_EVENT_CLOSE, "Quit" )
GUISetOnEvent( $GUI_EVENT_RESIZED, "ResizeHandler" )

Dim $minWidth = 200
Dim $minHeight = 200

While( 1 )
    Sleep( 1000 )
WEnd

Func Quit()
    Exit
EndFunc

Func ResizeHandler()
    Local $pos = WinGetPos( $title )
    MsgBox( 0, "DEBUG", $pos[3] )
    If @error == 1 Then
        MsgBox( 16, "Problem", "Unable to find window" )
        Exit
    EndIf
    If $pos[2] < $minWidth Then
        WinMove( $title, "", $pos[0], $pos[1], $minWidth, $pos[3] )
        Return
    EndIf
    If $pos[3] < $minHeight Then
        WinMove( $title, "", $pos[0], $pos[1], $pos[2], $minHeight )
        Return
    EndIf
EndFunc

Instead of

GUISetOnEvent( $GUI_EVENT_RESIZED, "ResizeHandler" )

try this

Const $WM_EXITSIZEMOVE = 0x0232

GUISetOnEvent( $WM_EXITSIZEMOVE, "ResizeHandler" )

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

martin and Zedna:

Thanks for the replies. I'll give them a shot and see how things work out. Sorry I didn't reply sooner, I was out of town over the weekend.

Thanks!!

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

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