Jump to content

Checking if a control has been resized


Recommended Posts

  • Moderators

philw,

You could register the WM_SIZE message:

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

Global $fResized = False

; When window is resized, run this function
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

; Create GUI
$hGUI = GUICreate("Test", 500, 500, -1, -1, $WS_SIZEBOX)

$hLabel = GUICtrlCreateLabel("", 10, 10, 100, 100)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Show if resized
    If $fResized = True Then
        GUICtrlSetData($hLabel, "Resized")
        $fResized = False
        ; Clear the label every 2 secs
        AdlibRegister("Wipe", 2000)     ; If you run Beta
        ;AdlibEnable("Wipe", 2000)      ; If you run 3.3.0.0
    EndIf

WEnd

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    If $Hwnd = WinGetHandle($hGUI) Then $fResized = True
    Return $GUI_RUNDEFMSG
EndFunc

Func Wipe()
    GUICtrlSetData($hLabel, "")
        AdlibUnRegister("Wipe")     ; If you run Beta
        ;AdlibDisable()             ; If you run 3.3.0.0
EndFunc

The label is cleared 2 secs after the resizing - if you resize too frequently you can get out of synch. :) But it will give you the idea.

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 Melba23, but doesn't that method only work if the window is resized? I want to check if a control within the window (for example an edit control) is resized. I suppose I could set up a function which is called on mousedown or mouseup, and then check if the control is still the same size... but this seems a bit over the top.

Edited by philw
Link to comment
Share on other sites

  • Moderators

philw,

I assumed that as a control is just another window, the same message would be sent - but it seems not. Sorry about that - I will have another think.

M23

Edit:

Best I can do - there does not appear to be a control resize message:

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

; Create GUI
$hGUI = GUICreate("Test", 500, 500)

$hLabel = GUICtrlCreateLabel("", 10, 10, 100, 100)

$hEdit = GUICtrlCreateEdit("", 10, 200, 200, 200, $WS_SIZEBOX)

GUISetState()

$aStartSize = ControlGetPos($hGUI, "", $hEdit)

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    $aSize = ControlGetPos($hGUI, "", $hEdit)
    If $aSize[2] <> $aStartSize[2] Or $aSize[3] <> $aStartSize[3] Then
        $aStartSize[2] = $aSize[2]
        $aStartSize[3] = $aSize[3]
        GUICtrlSetData($hLabel, "Resized")
        AdlibRegister("Wipe", 2000)
    EndIf

WEnd

Func Wipe()
    GUICtrlSetData($hLabel, "")
        AdlibUnRegister("Wipe")
EndFunc

But no doubt someone out there will come along with a better solution in a while :)

M23

Edited by Melba23

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 your help on this one! I thought it might be necessary to improvise. It's odd that there seems to be no control resize message, but such is life!

Edited by philw
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...