Jump to content

[Solved] GUIRegisterMsg Conflicts


Recommended Posts

I'm making a little chat client, and I'm using Melbas GUIFrame ().

I want it, so that when I re-size the window (with min/max sizes) it re-sizes the input and history boxes to match the new window size. That's working fine with re-sizing the whole GUI (using GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")), but when I try to move the frame separator bar, the history box (since it's made with _GUICtrlRichEdit instead of GUICtrlEdit) doesn't update until after you're finished moving the separator.

Using the other GUIRegisterMsg, the history edit re-sizes instantly as you move the separator bar, but the other controls in the window don't change at all.

Using both at once causes only the second one to work.

Is there a way to have both things happen (re-size edits on window and separator bar re-size)?

#include <GUIRichEdit.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <GUIEdit.Au3>
#include "GUIFrame.au3"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $GUIMINWID = 300, $GUIMINHT = 100 ;Min window sizes
Local $GUIMAXWID = @DesktopWidth, $GUIMAXHT = @DesktopHeight ;Max window sizes

$hGUI = GUICreate('MEOW', 500, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState(@SW_SHOW)

$iFrames = _GUIFrame_Create($hGUI, 0, 200) ;Creation of the two GUI frames
_GUIFrame_ResizeSet(0, 1) ;Required for proper resizing
_GUIFrame_ResizeReg() ;Required for proper resizing
_GUIFrame_SetMin($iFrames, 150, 200, True) ;Set frame min size
_GUIFrame_Switch($iFrames, 2) ;Switch to second frame to create controls

$History = _GUICtrlRichEdit_Create(_GUIFrame_Switch($iFrames, 2), 'adsfadsfasdf', 2, 2, 263, 255)
$Input = GUICtrlCreateEdit('', 2, 272, 293, 20, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_BORDER), $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
GUICtrlSetResizing(-1, 582) ;Resizing parameters


GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
;~ GUIRegisterMsg($WM_SIZE, "WM_SIZE")


$SepPos = _GUIFrame_GetSepPos($iFrames) ;Get the seperator bars current position

While 1
    Sleep(10)

    If $SepPos <> _GUIFrame_GetSepPos($iFrames) Then History_Resize()

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($History)
            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
    History_Resize()
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

Func WM_SIZE($hwnd, $iMsg, $wParam, $lParam)
    History_Resize()
EndFunc   ;==>WM_SIZE

Func History_Resize()
    $SepPos = _GUIFrame_GetSepPos($iFrames)
    $hGpos = WinGetPos($hGUI)
    $iPos = ControlGetPos($hGUI, '', 'Edit1')
    _WinAPI_MoveWindow($History, 2, 2, ($hGpos[2] - $SepPos) - 50, $hGpos[3] - $iPos[3] - 55, False)
EndFunc   ;==>History_Resize
Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • Moderators

mistersquirrle,

Easy! :)

Just run the resizing function inside your own message handler and call the UDF handle from there:

#include <GUIRichEdit.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <GUIEdit.Au3>
#include "GUIFrame.au3"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $GUIMINWID = 300, $GUIMINHT = 100 ;Min window sizes
Local $GUIMAXWID = @DesktopWidth, $GUIMAXHT = @DesktopHeight ;Max window sizes

$hGUI = GUICreate('MEOW', 500, 300, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
GUISetState(@SW_SHOW)

$iFrames = _GUIFrame_Create($hGUI, 0, 200) ;Creation of the two GUI frames
_GUIFrame_ResizeSet(0, 1) ;Required for proper resizing
;_GUIFrame_ResizeReg() ;Required for proper resizing ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do not use this
_GUIFrame_SetMin($iFrames, 150, 200, True) ;Set frame min size
_GUIFrame_Switch($iFrames, 2) ;Switch to second frame to create controls
Global $hWinHandle = _GUIFrame_GetHandle($iFrames, 2)

$History = _GUICtrlRichEdit_Create(_GUIFrame_Switch($iFrames, 2), 'adsfadsfasdf', 2, 2, 263, 255)

$Input = GUICtrlCreateEdit('', 2, 272, 293, 20, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_BORDER), $WS_EX_STATICEDGE)
GUICtrlSetFont(-1, 10, 400, 0, "Courier New")
GUICtrlSetResizing(-1, 582) ;Resizing parameters

GUIRegisterMsg($WM_GETMINMAXINFO, "WM_GETMINMAXINFO")
GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Do this instead

While 1
    Sleep(10) ; Not needed if you use GUIGetMsg <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            _GUICtrlRichEdit_Destroy($History)
            Exit
    EndSwitch
WEnd

Func WM_GETMINMAXINFO($hwnd, $Msg, $wParam, $lParam)
    If $hwnd = $hGUI Then ; Check it is the main GUI
        $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
        History_Resize() ; Resize richedit
    EndIf
    Return 0
EndFunc   ;==>WM_GETMINMAXINFO

Func WM_SIZE($hwnd, $iMsg, $wParam, $lParam) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Here we resize the richedit if required
    _GUIFrame_SIZE_Handler($hwnd, $iMsg, $wParam, $lParam) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< But also call the UDF handler
    If $hwnd = $hWinHandle Then ; Check it is the frame being resized
        History_Resize() ; Resize richedit
    EndIf
EndFunc   ;==>WM_SIZE

Func History_Resize()
    $SepPos = _GUIFrame_GetSepPos($iFrames)
    $hGpos = WinGetPos($hGUI)
    $iPos = ControlGetPos($hGUI, '', 'Edit1')
    _WinAPI_MoveWindow($History, 2, 2, ($hGpos[2] - $SepPos) - 50, $hGpos[3] - $iPos[3] - 55, False)
EndFunc   ;==>History_Resize

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

Ahh, indeed, that works. I remember even reading that while looking at your UDF, not to use the ResizeReg and WM_SIZE together. I just forgot, and I probably wouldn't have known quite how to use it anyway. :P

For the most part, I get that.

I just found a little bug with resizing things when the system (Windows 7 32-bit) doesn't have the "Show window contents while dragging" (System Properies -> Advanced -> Performance -> Visual Effects). When you resize the window, the history edit doesn't resize instantly. It doesn't get repainted until you click to start resizing again, move the window, or move the separator bar. Any thoughts on this?

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • Moderators

mistersquirrle,

Yes, tick the "Show window contents while dragging" box. ;)

Seriously, if you tell Windows not to redraw the GUI when you change it, it seems a little churlish to blame my UDF for not doing it for you instead. ;)

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 wasn't blaming your UDF at all. This issue is completely separate from your UDF. It still works when you move the separator bar with that setting unticked. I just would've expected the window, after being resized, to redraw everything, a Windows issue, I suppose.

I actually did find a workaround, with your code.

Commenting out lines 56 & 58 (If $hwnd = $hWinHandle Then/EndIf) allows the history edit to be resized without the option ticked, immediately after being resized.

Why are those lines needed?

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • Moderators

mistersquirrle,

Those lines are checking that it is the particular frame in which you have placed the richedit being resized. I added them so that resizing other sections of the GUI would not force a richedit resize when it was not required - in this particular GUI it always will be, but if there were other frames within the GUI it would be a valid test to run.

It appears that without the "Show window contents while dragging" option the resized message for the frame is only received after the main GUI resizing is complete. I have very little knowledge of the scheduling of Windows messages so I had no idea that this might be the case. Thanks for noticing - and finding a solution. :thumbsup:

M23

P.S. And I know you were not really complaining - look at the emoticon on that line. ;)

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

Yeah, ok. I thought that's what they were. Thanks for your help :)

BTW, can I edit my own topic titles? Or is that Mod+ only? I was gonna put a [solved] tag, or something.

Edited by mistersquirrle

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

  • Moderators

mistersquirrle,

Edit the first post and select the "Use Full Editor" option - that opens up the titles for amendment. :)

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

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

×
×
  • Create New...