Jump to content

How to implement a right-side resize handle?


qwert
 Share

Recommended Posts

I have a $WS_POPUP GUI that is normally fixed size.  But, occasionally, it contains text that would be easier to view if the right side (only) of the GUI could be extended.

As a test of GUI resizing, I've used $WS_SIZEBOX, but that adds an unwanted frame.

Is there a simple way to define a "handle" along the right side that can be used to extend the GUI horizontally.  (The vertical dimension should always remain fixed.)

Thanks in advance for any suggestions.

 

BTW, I have looked at the wiki and noted the full method for detecting mouse position and responding. What I'm seeking is effectively a button along the side that would control the right-side width, only.

Quote

Wiki: "To resize a GUI without borders, we have to fool Windows into thinking that the borders actually exist."

 

Edited by qwert
Link to comment
Share on other sites

  • Moderators

qwert,

How about this?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

HotKeySet("{ESC}", "On_Exit")

; Set distance from edge of window where resizing is possible
Global Const $iMargin = 4

; Create GUI
$hGUI = GUICreate("Y", 100, 100, -1, -1, $WS_POPUP)
GUISetBkColor(0xFF0000)
GUISetState()

; Register message handlers
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize
GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change

While 1
    Sleep(10)
WEnd

; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _GetBorder()
    If $iCursorType > 0 Then ; Cursor is set to resizing style
        $iResizeType = 0xF000 + $iCursorType
        _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0)
    EndIf
EndFunc   ;==>_WM_LBUTTONDOWN

; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID
    If _GetBorder() = 2 Then
        $iCursorID = 13
    EndIf
    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor

; Determines if mouse cursor over a border
Func _GetBorder()
    Local $aCurInfo = GUIGetCursorInfo()
    Local $aWinPos = WinGetPos($hGUI)
    Local $iSide = 0
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    Return $iSide
EndFunc   ;==>_GetBorder

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

Or you might like to look at my GUIExtender UDF, the link is on my sig.

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 solution. It's concise! Although I've used some of the elements in various scripts, I don't recall seeing them in such a compact example. It helps when they're demonstrated in such clear ways.

But I do have one remaining issue: can you suggest how to limit the resize action to a minimum of 100 pixels? (the initial GUI size)

Or, to put it another way: is there a setting that can be made for the GUI that's easier than the method that creates a structure?

( GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO") ; For GUI size limits )

 

 

 

 

Edited by qwert
Link to comment
Share on other sites

  • Moderators

qwert,

In my opinion the WM_GETMINMAXINFO is by far the best - why do you consider it so complicated? It takes only 7 lines:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <SendMessage.au3>

HotKeySet("{ESC}", "On_Exit")

Global $iMinX = 100                                                                       ; Line 1

; Set distance from edge of window where resizing is possible
Global Const $iMargin = 4

; Create GUI
$hGUI = GUICreate("Y", $iMinX, 100, -1, -1, $WS_POPUP)
GUISetBkColor(0xFF0000)
GUISetState()

; Register message handlers
GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") ; For resize
GUIRegisterMsg($WM_MOUSEMOVE, "_SetCursor") ; For cursor type change
GUIRegisterMsg($WM_GETMINMAXINFO, "_WM_GETMINMAXINFO")                                     ; Line 2

While 1
    Sleep(10)
WEnd

; Check cursor type and resize/drag window as required
Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    Local $iCursorType = _GetBorder()
    If $iCursorType > 0 Then ; Cursor is set to resizing style
        $iResizeType = 0xF000 + $iCursorType
        _SendMessage($hGUI, $WM_SYSCOMMAND, $iResizeType, 0)
    EndIf
EndFunc   ;==>_WM_LBUTTONDOWN

; Set cursor to correct resizing form if mouse is over a border
Func _SetCursor()
    Local $iCursorID
    If _GetBorder() = 2 Then
        $iCursorID = 13
    EndIf
    GUISetCursor($iCursorID, 1)
EndFunc   ;==>_SetCursor

; Determines if mouse cursor over a border
Func _GetBorder()
    Local $aCurInfo = GUIGetCursorInfo()
    Local $aWinPos = WinGetPos($hGUI)
    Local $iSide = 0
    If $aCurInfo[0] < $iMargin Then $iSide = 1
    If $aCurInfo[0] > $aWinPos[2] - $iMargin Then $iSide = 2
    Return $iSide
EndFunc   ;==>_GetBorder

Func _WM_GETMINMAXINFO($hwnd, $iMsg, $wParam, $lParam)                                    ; Line 3
    $tagMaxinfo = DllStructCreate("int;int;int;int;int;int;int;int;int;int", $lParam)     ; Line 4
    DllStructSetData($tagMaxinfo, 7, $iMinX) ; min X                                      ; Line 5
    Return 0                                                                              ; Line 6
EndFunc   ;==>WM_GETMINMAXINFO                                                            ; Line 7

Func On_Exit()
    Exit
EndFunc   ;==>On_Exit

M23

Edited by Melba23
Added line counters

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

True, it's not that complicated. But I seem to recall that a normal window (that's sizable) has some minimum size. So I thought there might be a way to let the operating system handle it. I'm always seeking 'simple'.

Thanks very much for your help.

 

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