Jump to content

Rebar Resize doesn't work with WM_NOTIFY


Rodger
 Share

Recommended Posts

Hello,

When running the below code and you maximize the GUI, the resize of the Rebar doesn't work properly. When you "disable" the line "GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")" the resize of the Rebar works fine. 

Does anybody know why this happens ?

Thanks,

Rodger

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiEdit.au3>
#include <GuiReBar.au3>
#include <GuiToolbar.au3>
#include <WindowsConstants.au3>

Global $g_hReBar

Example()

Func Example()
    Local $hGui, $idBtnExit, $hToolbar, $hCombo, $hDTP, $hInput
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $idHelp

    $hGui = GUICreate("Rebar", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")

    ; create the rebar control
    $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))

    ; create a toolbar to put in the rebar
    $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN))

    ; Add standard system bitmaps
    Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
        Case 0
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
        Case 2
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
    EndSwitch

    ; Add buttons
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)

    ; create a combobox to put in the rebar
    $hCombo = _GUICtrlComboBox_Create($hGui, "", 0, 0, 120)

    _GUICtrlComboBox_BeginUpdate($hCombo)
    _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($hCombo)

    ; create a date time picker to put in the rebar
    $hDTP = _GUICtrlDTP_Create($hGui, 0, 0, 190)

    ; create a input box to put in the rebar
    ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20)
    $hInput = _GUICtrlEdit_Create($hGui, "Input control", 0, 0, 120, 20)

    ; default for add is append

    ; add band with control
    _GUICtrlRebar_AddBand($g_hReBar, $hCombo, 120, 200, "Dir *.exe")

    ; add band with date time picker
    _GUICtrlRebar_AddBand($g_hReBar, $hDTP, 120)

    ; add band with toolbar to beginning of rebar
    _GUICtrlRebar_AddToolBarBand($g_hReBar, $hToolbar, "", 0)

    ;add another control
    ; _GUICtrlRebar_AddBand($g_hReBar, GUICtrlGetHandle($hInput), 120, 200, "Name:")
    _GUICtrlRebar_AddBand($g_hReBar, $hInput, 120, 200, "Name:")

    $idBtnExit = GUICtrlCreateButton("Exit", 150, 360, 100, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idBtnExit
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    Local $tAUTOBREAK, $tAUTOSIZE, $tNMREBAR, $tCHEVRON, $tCHILDSIZE, $tOBJECTNOTIFY

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hReBar
            Switch $iCode
                Case $RBN_AUTOBREAK
                    ; Notifies a rebar's parent that a break will appear in the bar. The parent determines whether to make the break
                    ; Return value not used
                Case $RBN_AUTOSIZE
                    ; Sent by a rebar control created with the $RBS_AUTOSIZE style when the rebar automatically resizes itself
                    ; Return value not used
                Case $RBN_BEGINDRAG
                    ; Sent by a rebar control when the user begins dragging a band
                    Return 0 ; to allow the rebar to continue the drag operation
                    ; Return 1 ; nonzero to abort the drag operation
                Case $RBN_CHEVRONPUSHED
                    ; Sent by a rebar control when a chevron is pushed
                    ; When an application receives this notification, it is responsible for displaying a popup menu with items for each hidden tool.
                    ; Use the rc member of the NMREBARCHEVRON structure to find the correct position for the popup menu
                    ; Return value not used
                Case $RBN_CHILDSIZE
                    ; Sent by a rebar control when a band's child window is resized
                 ; Return value not used
                Case $RBN_DELETEDBAND
                    ; Sent by a rebar control after a band has been deleted
                    ; Return value not used
                Case $RBN_DELETINGBAND
                    ; Sent by a rebar control when a band is about to be deleted
                   ; Return value not used
                Case $RBN_ENDDRAG
                    ; Sent by a rebar control when the user stops dragging a band
                    ; Return value not used
                Case $RBN_GETOBJECT
                    ; Sent by a rebar control created with the $RBS_REGISTERDROP style when an object is dragged over a band in the control
                    ; Return value not used
                Case $RBN_HEIGHTCHANGE
                    ; Sent by a rebar control when its height has changed
                    ; Rebar controls that use the $CCS_VERT style send this notification message when their width changes
                    ; Return value not used
                Case $RBN_LAYOUTCHANGED
                    ; Sent by a rebar control when the user changes the layout of the control's bands
                    ; Return value not used
                Case $RBN_MINMAX
                    ; Sent by a rebar control prior to maximizing or minimizing a band
                    ; Return 1 ; a non-zero value to prevent the operation from taking place
                    Return 0 ; zero to allow it to continue
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)

    $wPos = WinGetPos($hWnd)
    ControlMove($hWnd, "", $g_hReBar, 0, 0, $wPos[2])

    Return $GUI_RUNDEFMSG

EndFunc

 

Link to comment
Share on other sites

If you use both a WM_NOTIFY and a WM_SIZE message handler, you must be sure that the code in the message handlers is executed at the right time. This means that the WM_SIZE code should not be executed until the WM_NOTIFY code is finished.

If you insist in using a WM_SIZE message handler you can use a dummy control in this way:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiEdit.au3>
#include <GuiReBar.au3>
#include <GuiToolbar.au3>
#include <WindowsConstants.au3>

Global $g_hReBar, $idRebarResize

Example()

Func Example()
    Local $hGui, $idBtnExit, $hToolbar, $hCombo, $hDTP, $hInput
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $idHelp

    $hGui = GUICreate("Rebar", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUIRegisterMsg($WM_SIZE, "WM_SIZE")
    $idRebarResize = GUICtrlCreateDummy()

    ; create the rebar control
    $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))

    ; create a toolbar to put in the rebar
    $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN))

    ; Add standard system bitmaps
    Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
        Case 0
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
        Case 2
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
    EndSwitch

    ; Add buttons
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)

    ; create a combobox to put in the rebar
    $hCombo = _GUICtrlComboBox_Create($hGui, "", 0, 0, 120)

    _GUICtrlComboBox_BeginUpdate($hCombo)
    _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($hCombo)

    ; create a date time picker to put in the rebar
    $hDTP = _GUICtrlDTP_Create($hGui, 0, 0, 190)

    ; create a input box to put in the rebar
    ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20)
    $hInput = _GUICtrlEdit_Create($hGui, "Input control", 0, 0, 120, 20)

    ; default for add is append

    ; add band with control
    _GUICtrlRebar_AddBand($g_hReBar, $hCombo, 120, 200, "Dir *.exe")

    ; add band with date time picker
    _GUICtrlRebar_AddBand($g_hReBar, $hDTP, 120)

    ; add band with toolbar to beginning of rebar
    _GUICtrlRebar_AddToolBarBand($g_hReBar, $hToolbar, "", 0)

    ;add another control
    ; _GUICtrlRebar_AddBand($g_hReBar, GUICtrlGetHandle($hInput), 120, 200, "Name:")
    _GUICtrlRebar_AddBand($g_hReBar, $hInput, 120, 200, "Name:")

    $idBtnExit = GUICtrlCreateButton("Exit", 150, 360, 100, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $idRebarResize
                ControlMove($hGui, "", $g_hReBar, 0, 0, WinGetPos($hGui)[2])
            Case $GUI_EVENT_CLOSE, $idBtnExit
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    Local $tAUTOBREAK, $tAUTOSIZE, $tNMREBAR, $tCHEVRON, $tCHILDSIZE, $tOBJECTNOTIFY

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hReBar
            Switch $iCode
                Case $RBN_AUTOBREAK
                    ; Notifies a rebar's parent that a break will appear in the bar. The parent determines whether to make the break
                    ; Return value not used
                Case $RBN_AUTOSIZE
                    ; Sent by a rebar control created with the $RBS_AUTOSIZE style when the rebar automatically resizes itself
                    ; Return value not used
                Case $RBN_BEGINDRAG
                    ; Sent by a rebar control when the user begins dragging a band
                    Return 0 ; to allow the rebar to continue the drag operation
                    ; Return 1 ; nonzero to abort the drag operation
                Case $RBN_CHEVRONPUSHED
                    ; Sent by a rebar control when a chevron is pushed
                    ; When an application receives this notification, it is responsible for displaying a popup menu with items for each hidden tool.
                    ; Use the rc member of the NMREBARCHEVRON structure to find the correct position for the popup menu
                    ; Return value not used
                Case $RBN_CHILDSIZE
                    ; Sent by a rebar control when a band's child window is resized
                 ; Return value not used
                Case $RBN_DELETEDBAND
                    ; Sent by a rebar control after a band has been deleted
                    ; Return value not used
                Case $RBN_DELETINGBAND
                    ; Sent by a rebar control when a band is about to be deleted
                   ; Return value not used
                Case $RBN_ENDDRAG
                    ; Sent by a rebar control when the user stops dragging a band
                    ; Return value not used
                Case $RBN_GETOBJECT
                    ; Sent by a rebar control created with the $RBS_REGISTERDROP style when an object is dragged over a band in the control
                    ; Return value not used
                Case $RBN_HEIGHTCHANGE
                    ; Sent by a rebar control when its height has changed
                    ; Rebar controls that use the $CCS_VERT style send this notification message when their width changes
                    ; Return value not used
                Case $RBN_LAYOUTCHANGED
                    ; Sent by a rebar control when the user changes the layout of the control's bands
                    ; Return value not used
                Case $RBN_MINMAX
                    ; Sent by a rebar control prior to maximizing or minimizing a band
                    ; Return 1 ; a non-zero value to prevent the operation from taking place
                    Return 0 ; zero to allow it to continue
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
    GUICtrlSendToDummy( $idRebarResize )
    Return $GUI_RUNDEFMSG
EndFunc

But the proper AutoIt way is to use $GUI_EVENT_MAXIMIZE and $GUI_EVENT_RESTORE events instead of a WM_SIZE message handler:

#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiEdit.au3>
#include <GuiReBar.au3>
#include <GuiToolbar.au3>
#include <WindowsConstants.au3>

Global $g_hReBar

Example()

Func Example()
    Local $hGui, $idBtnExit, $hToolbar, $hCombo, $hDTP, $hInput
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $idHelp

    $hGui = GUICreate("Rebar", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX))

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    ; create the rebar control
    $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))

    ; create a toolbar to put in the rebar
    $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN))

    ; Add standard system bitmaps
    Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
        Case 0
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
        Case 2
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
    EndSwitch

    ; Add buttons
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $idHelp, $STD_HELP)

    ; create a combobox to put in the rebar
    $hCombo = _GUICtrlComboBox_Create($hGui, "", 0, 0, 120)

    _GUICtrlComboBox_BeginUpdate($hCombo)
    _GUICtrlComboBox_AddDir($hCombo, @WindowsDir & "\*.exe")
    _GUICtrlComboBox_EndUpdate($hCombo)

    ; create a date time picker to put in the rebar
    $hDTP = _GUICtrlDTP_Create($hGui, 0, 0, 190)

    ; create a input box to put in the rebar
    ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20)
    $hInput = _GUICtrlEdit_Create($hGui, "Input control", 0, 0, 120, 20)

    ; default for add is append

    ; add band with control
    _GUICtrlRebar_AddBand($g_hReBar, $hCombo, 120, 200, "Dir *.exe")

    ; add band with date time picker
    _GUICtrlRebar_AddBand($g_hReBar, $hDTP, 120)

    ; add band with toolbar to beginning of rebar
    _GUICtrlRebar_AddToolBarBand($g_hReBar, $hToolbar, "", 0)

    ;add another control
    ; _GUICtrlRebar_AddBand($g_hReBar, GUICtrlGetHandle($hInput), 120, 200, "Name:")
    _GUICtrlRebar_AddBand($g_hReBar, $hInput, 120, 200, "Name:")

    $idBtnExit = GUICtrlCreateButton("Exit", 150, 360, 100, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_MAXIMIZE, $GUI_EVENT_RESTORE
                ControlMove($hGui, "", $g_hReBar, 0, 0, WinGetPos($hGui)[2])
            Case $GUI_EVENT_CLOSE, $idBtnExit
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    Local $tAUTOBREAK, $tAUTOSIZE, $tNMREBAR, $tCHEVRON, $tCHILDSIZE, $tOBJECTNOTIFY

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $g_hReBar
            Switch $iCode
                Case $RBN_AUTOBREAK
                    ; Notifies a rebar's parent that a break will appear in the bar. The parent determines whether to make the break
                    ; Return value not used
                Case $RBN_AUTOSIZE
                    ; Sent by a rebar control created with the $RBS_AUTOSIZE style when the rebar automatically resizes itself
                    ; Return value not used
                Case $RBN_BEGINDRAG
                    ; Sent by a rebar control when the user begins dragging a band
                    Return 0 ; to allow the rebar to continue the drag operation
                    ; Return 1 ; nonzero to abort the drag operation
                Case $RBN_CHEVRONPUSHED
                    ; Sent by a rebar control when a chevron is pushed
                    ; When an application receives this notification, it is responsible for displaying a popup menu with items for each hidden tool.
                    ; Use the rc member of the NMREBARCHEVRON structure to find the correct position for the popup menu
                    ; Return value not used
                Case $RBN_CHILDSIZE
                    ; Sent by a rebar control when a band's child window is resized
                 ; Return value not used
                Case $RBN_DELETEDBAND
                    ; Sent by a rebar control after a band has been deleted
                    ; Return value not used
                Case $RBN_DELETINGBAND
                    ; Sent by a rebar control when a band is about to be deleted
                   ; Return value not used
                Case $RBN_ENDDRAG
                    ; Sent by a rebar control when the user stops dragging a band
                    ; Return value not used
                Case $RBN_GETOBJECT
                    ; Sent by a rebar control created with the $RBS_REGISTERDROP style when an object is dragged over a band in the control
                    ; Return value not used
                Case $RBN_HEIGHTCHANGE
                    ; Sent by a rebar control when its height has changed
                    ; Rebar controls that use the $CCS_VERT style send this notification message when their width changes
                    ; Return value not used
                Case $RBN_LAYOUTCHANGED
                    ; Sent by a rebar control when the user changes the layout of the control's bands
                    ; Return value not used
                Case $RBN_MINMAX
                    ; Sent by a rebar control prior to maximizing or minimizing a band
                    ; Return 1 ; a non-zero value to prevent the operation from taking place
                    Return 0 ; zero to allow it to continue
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

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