Jump to content
Sign in to follow this  
BoonPek

Window resizing and GUIRegisterMsg()

Recommended Posts

BoonPek

Hello there!

Currently, I use this from Melba23 to prevent my AutoIt GUI from being resized too small, and it works extremely well!

#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

Problem with this, though, is that it doesn't seem to work with external, non AutoIt-created GUIs. To compensate for this, I created a simple script that loops continuously and checks that the window size is large enough. If not, it would resize the window accordingly:

Global $p_ID, $hWnd, $hSize
 
$p_ID = Run('Notepad.exe')
 
$hWnd = WinWait('[CLASS:Notepad]', '', 5)
 
While WinGetProcess($hWnd) <> $p_ID
    $hWnd = WinList("[CLASS:Notepad]")
 
    For $i = 1 To $hWnd[0][0]
        If WinGetProcess($hWnd[$i][0]) = $p_ID Then
            $hWnd = $hWnd[$i][1]
            ExitLoop
        EndIf
    Next
WEnd
 
While WinExists($hWnd)
    $hSize = WinGetPos($hWnd)
 
    If $hSize[2] < 800 Then WinMove($hWnd, '', $hSize[0], $hSize[1], 800, $hSize[3])
    If $hSize[3] < 600 Then WinMove($hWnd, '', $hSize[0], $hSize[1], $hSize[2], 600)
WEnd

Cheap, I know, but I am unable to find any other alternatives.

Thanks for any input, guys!

Edited by BoonPek

Share this post


Link to post
Share on other sites
guinness

I think your second solution is a good workaround.

#include <WinAPIEx.au3> ; Search the Examples forum.

Global $aArray, $hHandle, $iPID

$iPID = Run('Notepad.exe')
$aArray = _WinAPI_EnumProcessWindows($iPID)
If @error Then
    Exit
EndIf
$hHandle = $aArray[1][0]

While 1
    If ProcessExists($iPID) = 0 Then
        ExitLoop
    EndIf

    $aArray = WinGetPos($hHandle)
    If $aArray[2] < 800 Then
        WinMove($hHandle, '', $aArray[0], $aArray[1], 800, $aArray[3])
    EndIf
    If $aArray[3] < 600 Then
        WinMove($hHandle, '', $aArray[0], $aArray[1], $aArray[2], 600)
    EndIf
    Sleep(100) ; Reduce CPU.
WEnd

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
BoonPek

I think your second solution is a good workaround.

#include <WinAPIEx.au3> ; Search the Examples forum.
 
Global $aArray, $hHandle, $iPID
 
$iPID = Run('Notepad.exe')
$aArray = _WinAPI_EnumProcessWindows($iPID)
If @error Then
    Exit
EndIf
$hHandle = $aArray[1][0]
 
While 1
    If ProcessExists($iPID) = 0 Then
        ExitLoop
    EndIf
 
    $aArray = WinGetPos($hHandle)
    If $aArray[2] < 800 Then
        WinMove($hHandle, '', $aArray[0], $aArray[1], 800, $aArray[3])
    EndIf
    If $aArray[3] < 600 Then
        WinMove($hHandle, '', $aArray[0], $aArray[1], $aArray[2], 600)
    EndIf
    Sleep(100) ; Reduce CPU.
WEnd

Yes, I guess so. Problem is, though, I'd like my users to be unable to resize these windows - but here the potential for resizing still exists. Adding the sleep(100), whilst decreasing CPU load for slower PCs, makes the GUI less fancy :graduated:

Thanks for your input though! I'm looking forwards to those by others ;)


Share this post


Link to post
Share on other sites
guinness

Just delete the sleep. The two while functions weren't really needed in your example :graduated:


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
BoonPek

Thanks for your assistance. I'm going to assume that there's no other alternative to accomplish the OP other than what I specified? :oops:

Anyways, onto another issue here xD

In GUICtrlCreateInput, you could set the maximum of characters allowed for entry by using GUICtrlSetLimit($handle, maxvalue). Is this possible for a GUICtrlCreateCombobox? Once again, I'd prefer a native function. Thank you :D

Edit: Fixed: _GUICtrlComboBox_LimitText()

Edited by BoonPek

Share this post


Link to post
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
Sign in to follow this  

×