Jump to content

Drawing gripper edge and chevron on Rebar bands in WM_NOTIFY


Go to solution Solved by WildByDesign,

Recommended Posts

Posted

I have had some success recently while working on the Rebar control subclass that will eventually be added to GUIDarkTheme UDF. The dark mode colors used for the background and text are working well now.

Goal:

  • Draw dotted lines over existing white (0xf0f0f0) gripper edge on bands
    • I've seen C++ projects use Polyline WinAPI used for this
    • Although other dotted line methods could be used
  • Draw chevrons when needed
    • I don't even know how to make chevrons appear in Rebar (not familiar with Rebar)
    • I've seen C++ projects use DrawText to draw chevron shape/glyph from text

I have tried a bunch of things to draw dotted lines over the existing white gripper. The only success that I ever had was only drawing on the first band. So I think that my mistake was drawing on the Rect from the whole Rebar instead of the Rect of individual bands. I don't know how to do that or how to get DC for individual bands.

If anybody can help with the dotted lines for gripper edges and chevrons, I would really appreciate it. :)

If that works out successfully, then I can add the checking of style parts after to ensure that we only draw those on bands that are using them at the time of drawing.

Some relevant C++ code from win32-darkmodelib project:

/**
 * @brief Applies custom drawing to a rebar control during `CDDS_PREPAINT`.
 *
 * Paints chevrons and 'gripper' edges for all bands if applicable.
 *
 * @param[in] lpnmcd Reference to `LPNMCUSTOMDRAW`.
 * @return `CDRF_SKIPDEFAULT` if drawing was applied.
 *
 * @see darkRebarNotifyCustomDraw()
 */
[[nodiscard]] static LRESULT prepaintRebar(const LPNMCUSTOMDRAW& lpnmcd) noexcept
{
    ::FillRect(lpnmcd->hdc, &lpnmcd->rc, dmlib::getDlgBackgroundBrush());

    REBARBANDINFO rbBand{};
    rbBand.cbSize = sizeof(REBARBANDINFO);
    rbBand.fMask = RBBIM_STYLE | RBBIM_CHEVRONLOCATION | RBBIM_CHEVRONSTATE;

    const auto nBands = static_cast<UINT>(::SendMessage(lpnmcd->hdr.hwndFrom, RB_GETBANDCOUNT, 0, 0));
    for (UINT i = 0; i < nBands; ++i)
    {
        ::SendMessage(lpnmcd->hdr.hwndFrom, RB_GETBANDINFO, static_cast<WPARAM>(i), reinterpret_cast<LPARAM>(&rbBand));

        // paints chevron
        if ((rbBand.fStyle & RBBS_USECHEVRON) == RBBS_USECHEVRON
            && (rbBand.rcChevronLocation.right - rbBand.rcChevronLocation.left) > 0)
        {
            static const int roundness = dmlib::isAtLeastWindows11() ? dmlib_paint::kWin11CornerRoundness + 1 : 0;

            const bool isHot = (rbBand.uChevronState & STATE_SYSTEM_HOTTRACKED) == STATE_SYSTEM_HOTTRACKED;
            const bool isPressed = (rbBand.uChevronState & STATE_SYSTEM_PRESSED) == STATE_SYSTEM_PRESSED;

            if (isHot)
            {
                dmlib_paint::paintRoundRect(lpnmcd->hdc, rbBand.rcChevronLocation, dmlib::getHotEdgePen(), dmlib::getHotBackgroundBrush(), roundness, roundness);
            }
            else if (isPressed)
            {
                dmlib_paint::paintRoundRect(lpnmcd->hdc, rbBand.rcChevronLocation, dmlib::getEdgePen(), dmlib::getCtrlBackgroundBrush(), roundness, roundness);
            }

            ::SetTextColor(lpnmcd->hdc, isHot ? dmlib::getTextColor() : dmlib::getDarkerTextColor());
            ::SetBkMode(lpnmcd->hdc, TRANSPARENT);

            const auto hFont = dmlib_paint::GdiObject{ lpnmcd->hdc, lpnmcd->hdr.hwndFrom };
            static constexpr UINT dtFlags = DT_CENTER | DT_TOP | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX;
            ::DrawText(lpnmcd->hdc, dmlib_glyph::kChevron, -1, &rbBand.rcChevronLocation, dtFlags);
        }

        // paints gripper edge
        if ((rbBand.fStyle & RBBS_GRIPPERALWAYS) == RBBS_GRIPPERALWAYS
            && ((rbBand.fStyle & RBBS_FIXEDSIZE) != RBBS_FIXEDSIZE
                || (rbBand.fStyle & RBBS_NOGRIPPER) != RBBS_NOGRIPPER))
        {
            auto holdPen = static_cast<HPEN>(::SelectObject(lpnmcd->hdc, dmlib::getDarkerTextPen()));

            RECT rcBand{};
            ::SendMessage(lpnmcd->hdr.hwndFrom, RB_GETRECT, static_cast<WPARAM>(i), reinterpret_cast<LPARAM>(&rcBand));

            static constexpr LONG offset = 5;
            const std::array<POINT, 2> edges{ {
                { rcBand.left, rcBand.top + offset},
                { rcBand.left, rcBand.bottom - offset}
            } };
            ::Polyline(lpnmcd->hdc, edges.data(), static_cast<int>(edges.size()));

            ::SelectObject(lpnmcd->hdc, holdPen);
        }
    }
    return CDRF_SKIPDEFAULT;
}

 

Here is my current Rebar subclass testing code:

#include <WinAPIGdi.au3>
#include <WinAPITheme.au3>
#include <WindowsNotifsConstants.au3>
#include <ToolbarConstants.au3>
#include <RebarConstants.au3>
#include <AutoItConstants.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiEdit.au3>
#include <GuiReBar.au3>
#include <GuiToolbar.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WindowsStylesConstants.au3>
#include <APIGdiConstants.au3>

; Initialize System DPI awareness
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2)

Global Const $TBCDRF_USECDCOLORS = 0x800000

Global Const $tagNMTBCUSTOMDRAW = $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;" & _
    "ptr hbrMonoDither;ptr hbrLines;ptr hpenLines;dword clrText;dword clrMark;dword clrTextHighlight;dword clrBtnFace;dword clrBtnHighlight;dword clrHighlightHotTrack;" & _
    "long TextLeft;long TextTop;long TextRight;long TextBottom;int nStringBkMode;int nHLStringBkMode;int iListGap;"

Global $g_hReBar, $hGui

Example()

Func Example()
    $hGui = GUICreate("Rebar Create (v" & @AutoItVersion & ")", 400, 396, -1, -1, $WS_OVERLAPPEDWINDOW)
    GUISetBkColor(0x202020)


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

    _GUICtrlRebar_SetColorScheme($g_hReBar, 0x383838, 0x383838)

    ; create a toolbar to put in the rebar
    Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN))
    _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838)
    _GUICtrlToolbar_SetStyleTransparent($hToolbar, False)

    ; Add standard system bitmaps
    _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

    ; Add strings
    Local $aStrings[4]
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&New")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "&Open")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Save")
    $aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Help")

    ; Add buttons
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW, $aStrings[0])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN, $aStrings[1])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE, $aStrings[2], $BTNS_CHECK)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idHelp, $STD_HELP, $aStrings[3])

    ; create a combobox to put in the rebar
    Local $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
    Local $hDTP = _GUICtrlDTP_Create($hGui, 0, 0, 190)

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

    ; 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, $hInput, 120, 200, "Name:")

    _WinAPI_SetWindowTheme($g_hReBar, "", "")

    GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
    GUISetState(@SW_SHOW)


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

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
    If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG

    Local $dwDrawStage = $tTool.dwDrawStage
    Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom)
    Switch $sClass
        Case "ReBarWindow32"
            Switch $dwDrawStage
                Case $CDDS_PREPAINT
                    Local $hBrush = _WinAPI_CreateSolidBrush(0x383838)
                    Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                    _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush)
                    _WinAPI_DeleteObject($hBrush)
                    Return $CDRF_NOTIFYITEMDRAW

                Case $CDDS_ITEMPREPAINT
                    _WinAPI_SetTextColor($tTool.hdc, 0xFFFFFF)
                    _WinAPI_SetBkMode($tTool.hdc, $TRANSPARENT)
                    Return $CDRF_NEWFONT
            EndSwitch

        Case "ToolbarWindow32"
            Switch $dwDrawStage
                Case $CDDS_PREPAINT
                    Local $hBrush = _WinAPI_CreateSolidBrush(0x383838)
                    Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                    _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush)
                    _WinAPI_DeleteObject($hBrush)
                    Return $CDRF_NOTIFYITEMDRAW

                Case $CDDS_ITEMPREPAINT
                    Local $iState = $tTool.uItemState

                    If BitAND($iState, $CDIS_HOT) Then
                        $tTool.clrText = 0xFFFFFF
                        $tTool.clrTextHighlight = 0xFFFFFF

                        Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                        Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x121212)
                        Local $hOldPen = _WinAPI_SelectObject($tTool.hdc, $hPen)
                        Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060)
                        Local $hObj = _WinAPI_SelectObject($tTool.hdc, $hBrush)
                        _WinAPI_InflateRect($tRect, 0, -2)
                        _WinAPI_RoundRect($tTool.hdc, $tRect, 8, 8)
                        _WinAPI_SelectObject($tTool.hdc, $hObj)
                        _WinAPI_SelectObject($tTool.hdc, $hOldPen)
                        _WinAPI_DeleteObject($hBrush)
                        _WinAPI_DeleteObject($hPen)

                        ; clear item state or else this will not work
                        $tTool.uItemState = Null

                        Return $TBCDRF_USECDCOLORS
                    EndIf

                    If BitAND($iState, $CDIS_CHECKED) Then
                        $tTool.clrText = 0xFFFFFF
                        $tTool.clrTextHighlight = 0xFFFFFF

                        Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                        Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x121212)
                        Local $hOldPen = _WinAPI_SelectObject($tTool.hdc, $hPen)
                        Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060)
                        Local $hObj = _WinAPI_SelectObject($tTool.hdc, $hBrush)
                        _WinAPI_InflateRect($tRect, 0, -2)
                        _WinAPI_RoundRect($tTool.hdc, $tRect, 8, 8)
                        _WinAPI_SelectObject($tTool.hdc, $hObj)
                        _WinAPI_SelectObject($tTool.hdc, $hOldPen)
                        _WinAPI_DeleteObject($hBrush)
                        _WinAPI_DeleteObject($hPen)

                        ; clear item state or else this will not work
                        $tTool.uItemState = Null

                        Return $TBCDRF_USECDCOLORS
                    EndIf

                    If Not BitAND($iState, $CDIS_DISABLED) Then
                        $tTool.clrText = 0xFFFFFF
                        $tTool.clrTextHighlight = 0xFFFFFF

                        Return $TBCDRF_USECDCOLORS
                    EndIf

            EndSwitch
        
        Case Else
            Return $GUI_RUNDEFMSG
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

  • 2 months later...
  • Solution
Posted

I failed miserably at the Rebar control CUSTOMDRAW a few months ago. I failed at getting the Rebar band text to align/fit properly and I also failed at coloring the gripper. I decided to have another look at this and was successful this time around. :)

#include <WinAPIGdi.au3>
#include <WinAPITheme.au3>
#include <WindowsNotifsConstants.au3>
#include <ToolbarConstants.au3>
#include <RebarConstants.au3>
#include <AutoItConstants.au3>
#include <GuiComboBox.au3>
#include <GUIConstantsEx.au3>
#include <GuiDateTimePicker.au3>
#include <GuiEdit.au3>
#include <GuiReBar.au3>
#include <GuiToolbar.au3>
#include <StructureConstants.au3>
#include <WinAPIConstants.au3>
#include <WindowsStylesConstants.au3>
#include <APIGdiConstants.au3>

; Initialize System DPI awareness
DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2)

; Get AutoIt Window DPI
Global $hAutoIt = WinGetHandle(AutoItWinGetTitle())
Global $g_DPI = _WinAPI_GetDpiForWindow($hAutoIt) / 96
If @error Then $g_DPI = 1

Global $g_iBkColor = 0x202020, $g_iRebarGripColor = 0x7A7A7A, $g_iTextColor = 0xFFFFFF

Global Const $TBCDRF_USECDCOLORS = 0x800000

Global Const $tagNMCUSTOMDRAW = _
        $tagNMHDR & ";" & _                                    ; Contains NM_CUSTOMDRAW / NMHDR header among other things
        "dword dwDrawStage;" & _                               ; Current drawing stage (CDDS_*)
        "handle hdc;" & _                                      ; Device Context Handle
        "long left;long top;long right;long bottom;" & _       ; Drawing rectangle
        "dword_ptr dwItemSpec;" & _                            ; Item index or other info (depending on the control)
        "uint uItemState;" & _                                 ; State Flags (CDIS_SELECTED, CDIS_FOCUS etc.)
        "lparam lItemlParam"                                   ; lParam set by the item (e.g., via LVITEM.lParam)

Global Const $tagNMTBCUSTOMDRAW = $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;" & _
    "ptr hbrMonoDither;ptr hbrLines;ptr hpenLines;dword clrText;dword clrMark;dword clrTextHighlight;dword clrBtnFace;dword clrBtnHighlight;dword clrHighlightHotTrack;" & _
    "long TextLeft;long TextTop;long TextRight;long TextBottom;int nStringBkMode;int nHLStringBkMode;int iListGap;"

Global $g_hReBar, $hGui

Example()

Func Example()
    $hGui = GUICreate("Rebar CUSTOMDRAW (v" & @AutoItVersion & ")", 400 * $g_DPI, 380 * $g_DPI, -1, -1, $WS_OVERLAPPEDWINDOW)
    GUISetBkColor($g_iBkColor)

    ; create the rebar control
    $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS))
    _WinAPI_SetWindowTheme($g_hReBar, "", "")
    _GUICtrlRebar_SetBKColor($g_hReBar, $g_iBkColor)
    _GUICtrlRebar_SetTextColor($g_hReBar, $g_iTextColor)

    _GUICtrlRebar_SetColorScheme($g_hReBar, $g_iBkColor, $g_iBkColor)

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

    ; Add standard system bitmaps
    _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)

    ; Add strings
    Local $aStrings[4]
    $aStrings[0] = _GUICtrlToolbar_AddString($hToolbar, "&New")
    $aStrings[1] = _GUICtrlToolbar_AddString($hToolbar, "&Open")
    $aStrings[2] = _GUICtrlToolbar_AddString($hToolbar, "&Save")
    $aStrings[3] = _GUICtrlToolbar_AddString($hToolbar, "&Help")

    ; Add buttons
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp
    _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW, $aStrings[0])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN, $aStrings[1])
    _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE, $aStrings[2], $BTNS_CHECK)
    _GUICtrlToolbar_AddButtonSep($hToolbar)
    _GUICtrlToolbar_AddButton($hToolbar, $e_idHelp, $STD_HELP, $aStrings[3])

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

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

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

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

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

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

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

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

    GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)
    GUISetState(@SW_SHOW)


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

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam)
    If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG

    Local Static $hBrushGrip = _WinAPI_CreateSolidBrush(_WinAPI_SwitchColor($g_iRebarGripColor))
    Local Static $hBrushBack = _WinAPI_CreateSolidBrush(_WinAPI_SwitchColor($g_iBkColor))

    Local $dwDrawStage = $tTool.dwDrawStage
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hFrom = $tNMHDR.hWndFrom
    Local $iCode = $tNMHDR.Code
    Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom)
    Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
    Local $dwStage = $tNMCD.dwDrawStage
    Local $hDC = $tNMCD.hdc
    Switch $sClass
        Case "ReBarWindow32"
                Switch $dwStage
                    Case $CDDS_PREPAINT
                        $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tNMCD, "left"))
                        _WinAPI_FillRect($hDC, $tRect, $hBrushBack)
                        Local $iBandCount = _GUICtrlRebar_GetBandCount($hFrom)
                        _WinAPI_SetTextColor($hDC, _WinAPI_SwitchColor($g_iTextColor))
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT)
                        Local $sBandText, $tBandRect, $iW, $iH, $tGripRect, $tTextRect, $sStyle
                        Local $bDrawGrip = False
                        Local $iTextFlags = BitOR($DT_SINGLELINE, $DT_NOCLIP, $DT_VCENTER, $DT_LEFT)

                        Local $hFont = _SendMessage($hFrom, $WM_GETFONT, 0, 0)
                        If Not $hFont Then $hFont = _WinAPI_GetStockObject($DEFAULT_GUI_FONT)
                        Local $hOldFont = _WinAPI_SelectObject($hDC, $hFont)

                        For $i = 0 To $iBandCount - 1
                            $sBandText = _GUICtrlRebar_GetBandText($hFrom, $i)
                            $sStyle = _GUICtrlRebar_GetBandStyle($hFrom, $i)
                            If BitAND($sStyle, $RBBS_GRIPPERALWAYS) Then $bDrawGrip = True
                            If BitAND($sStyle, $RBBS_FIXEDSIZE) Then $bDrawGrip = False
                            If BitAND($sStyle, $RBBS_NOGRIPPER) Then $bDrawGrip = False
                            $tBandRect = _GUICtrlRebar_GetBandRectEx($hFrom, $i)
                            $iW = $tBandRect.Right - $tBandRect.Left
                            $iH = $tBandRect.Bottom - $tBandRect.Top
                            $tTextRect = _WinAPI_CreateRectEx($tBandRect.Left + 10, $tBandRect.Top, $iW, $iH)
                            If $sBandText Then _WinAPI_DrawText($hDC, $sBandText, $tTextRect, $iTextFlags)
                            If $bDrawGrip Then
                                $tGripRect = _WinAPI_CreateRectEx($tBandRect.Left + 4, $tBandRect.Top + 2, 2, $iH - 4)
                                _WinAPI_FillRect($hDC, $tGripRect, $hBrushGrip)
                            EndIf
                        Next
                        _WinAPI_SelectObject($hDC, $hOldFont)

                        Return $CDRF_SKIPDEFAULT

                    Case Else
                        Return $GUI_RUNDEFMSG
                EndSwitch

                Return $GUI_RUNDEFMSG

        Case "ToolbarWindow32"
            Switch $dwDrawStage
                Case $CDDS_PREPAINT
                    Local $hBrush = _WinAPI_CreateSolidBrush($g_iBkColor)
                    Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                    _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush)
                    _WinAPI_DeleteObject($hBrush)
                    Return $CDRF_NOTIFYITEMDRAW

                Case $CDDS_ITEMPREPAINT
                    Local $iState = $tTool.uItemState

                    If BitAND($iState, $CDIS_HOT) Then
                        $tTool.clrText = $g_iTextColor
                        $tTool.clrTextHighlight = $g_iTextColor

                        Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                        Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x9B9B9B)
                        Local $hOldPen = _WinAPI_SelectObject($tTool.hdc, $hPen)
                        Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060)
                        Local $hObj = _WinAPI_SelectObject($tTool.hdc, $hBrush)
                        _WinAPI_InflateRect($tRect, 0, -2)
                        _WinAPI_RoundRect($tTool.hdc, $tRect, 8, 8)
                        _WinAPI_SelectObject($tTool.hdc, $hObj)
                        _WinAPI_SelectObject($tTool.hdc, $hOldPen)
                        _WinAPI_DeleteObject($hBrush)
                        _WinAPI_DeleteObject($hPen)

                        ; clear item state or else this will not work
                        $tTool.uItemState = Null

                        Return $TBCDRF_USECDCOLORS
                    EndIf

                    If BitAND($iState, $CDIS_CHECKED) Then
                        $tTool.clrText = $g_iTextColor
                        $tTool.clrTextHighlight = $g_iTextColor

                        Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left"))
                        Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0x9B9B9B)
                        Local $hOldPen = _WinAPI_SelectObject($tTool.hdc, $hPen)
                        Local $hBrush = _WinAPI_CreateSolidBrush(BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060)
                        Local $hObj = _WinAPI_SelectObject($tTool.hdc, $hBrush)
                        _WinAPI_InflateRect($tRect, 0, -2)
                        _WinAPI_RoundRect($tTool.hdc, $tRect, 8, 8)
                        _WinAPI_SelectObject($tTool.hdc, $hObj)
                        _WinAPI_SelectObject($tTool.hdc, $hOldPen)
                        _WinAPI_DeleteObject($hBrush)
                        _WinAPI_DeleteObject($hPen)

                        ; clear item state or else this will not work
                        $tTool.uItemState = Null

                        Return $TBCDRF_USECDCOLORS
                    EndIf

                    If Not BitAND($iState, $CDIS_DISABLED) Then
                        $tTool.clrText = $g_iTextColor
                        $tTool.clrTextHighlight = $g_iTextColor

                        Return $TBCDRF_USECDCOLORS
                    EndIf

            EndSwitch
        
        Case Else
            Return $GUI_RUNDEFMSG
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _WinAPI_GetDpiForWindow($hWnd) ; UEZ
    Local $aResult = DllCall("user32.dll", "uint", "GetDpiForWindow", "hwnd", $hWnd) ;requires Win10 v1607+ / no server support
    If Not IsArray($aResult) Or @error Then Return SetError(1, @extended, 0)
    If Not $aResult[0] Then Return SetError(2, @extended, 0)
    Return $aResult[0]
EndFunc   ;==>_WinAPI_GetDpiForWindow

 

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
×
×
  • Create New...