WildByDesign Posted May 14 Posted May 14 (edited) I'm at the beginning stages of trying to figure out how to subclass a toolbar (ToolbarWindow32) for potential use in GUIDarkTheme UDF. AutoIt does not have a tag structure for $tagNMTBCUSTOMDRAW and I am stuck there. I could generally follow some of the other examples from StructureConstants.au3, however, I don't know how to handle the HBRUSH in the structure because none of the examples have it. Link: NMTBCUSTOMDRAW structure (C++) typedef struct _NMTBCUSTOMDRAW { NMCUSTOMDRAW nmcd; HBRUSH hbrMonoDither; HBRUSH hbrLines; HPEN hpenLines; COLORREF clrText; COLORREF clrMark; COLORREF clrTextHighlight; COLORREF clrBtnFace; COLORREF clrBtnHighlight; COLORREF clrHighlightHotTrack; RECT rcText; int nStringBkMode; int nHLStringBkMode; int iListGap; } NMTBCUSTOMDRAW, *LPNMTBCUSTOMDRAW; I'll share some more details of the subclassing part soon. But for now, here is my current testing example to get started if anyone can help with the structure. Thank you. expandcollapse popup#include <WinAPITheme.au3> #include <ToolbarConstants.au3> #include <GUIConstantsEx.au3> #include <GuiToolbar.au3> #include <StructureConstants.au3> #include <WinAPIConstants.au3> #include <WindowsNotifsConstants.au3> #include <WindowsStylesConstants.au3> #include <WinAPIShellEx.au3> Global $g_hToolbar Global $g_iItem ; Command identifier of the button associated with the notification. Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp ; NMTBCUSTOMDRAW: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-nmtbcustomdraw ; C++ structure #cs typedef struct _NMTBCUSTOMDRAW { NMCUSTOMDRAW nmcd; HBRUSH hbrMonoDither; HBRUSH hbrLines; HPEN hpenLines; COLORREF clrText; COLORREF clrMark; COLORREF clrTextHighlight; COLORREF clrBtnFace; COLORREF clrBtnHighlight; COLORREF clrHighlightHotTrack; RECT rcText; int nStringBkMode; int nHLStringBkMode; int iListGap; } NMTBCUSTOMDRAW, *LPNMTBCUSTOMDRAW; #ce ; Structure for NM_CUSTOMDRAW notification Global Const $tagNMTBCUSTOMDRAW = $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) Example() Func Example() Local $hGUI, $aSize ; Create GUI $hGUI = GUICreate("Toolbar", 600, 400) $g_hToolbar = _GUICtrlToolbar_Create($hGUI) $aSize = _GUICtrlToolbar_GetMaxSize($g_hToolbar) ;_WinAPI_SetWindowTheme($g_hToolbar, 'DarkMode_DarkTheme') ; add subclass for toolbar Local $hSubClass = DllCallbackRegister(WM_NOTIFY, "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") _WinAPI_SetWindowSubclass($g_hToolbar, DllCallbackGetPtr($hSubClass), 1) GUISetState(@SW_SHOW) ; Add standard system bitmaps _GUICtrlToolbar_AddBitmap($g_hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) ; Add buttons _GUICtrlToolbar_AddButton($g_hToolbar, $e_idNew, $STD_FILENEW) _GUICtrlToolbar_AddButton($g_hToolbar, $e_idOpen, $STD_FILEOPEN) _GUICtrlToolbar_AddButton($g_hToolbar, $e_idSave, $STD_FILESAVE) _GUICtrlToolbar_AddButtonSep($g_hToolbar) _GUICtrlToolbar_AddButton($g_hToolbar, $e_idHelp, $STD_HELP) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($g_hToolbar, DllCallbackGetPtr($hSubClass), 1) DllCallbackFree($hSubClass) EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) Local Static $bHover, $tPoint Switch $iMsg Case $WM_NOTIFY Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Switch $tNMHDR.Code Case $NM_CUSTOMDRAW If $tNMHDR.hWndFrom = $pData Then Local $tCustDraw = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) Switch $tCustDraw.dwDrawStage Case $CDDS_PREPAINT Return $CDRF_NOTIFYITEMDRAW Case $CDDS_ITEMPREPAINT Return $CDRF_SKIPDEFAULT EndSwitch EndIf EndSwitch EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>WM_NOTIFY Edited May 14 by WildByDesign
WildByDesign Posted May 14 Author Posted May 14 From the win32-darkmodelib C++ library: Link: Handles custom draw notifications for a toolbar control. What we need to handle is really quite simple from what I can tell. /** * @brief Handles custom draw notifications for a toolbar control. * * Processes `NMTBCUSTOMDRAW` messages to provide custom color painting * at each stage of the custom draw cycle: * - **CDDS_PREPAINT**: Fills the toolbar background and requests item-level drawing. * - **CDDS_ITEMPREPAINT**: Applies custom item painting via @ref prepaintToolbarItem. * - **CDDS_ITEMPOSTPAINT**: Paints dropdown arrows glyphs via @ref postpaintToolbarItem. * * @param[in] hWnd Handle to the toolbar control. * @param[in] uMsg Should be `WM_NOTIFY` with custom draw type (forwarded to default subclass processing). * @param[in] wParam Message parameter (forwarded to default subclass processing). * @param[in] lParam Pointer to `NMTBCUSTOMDRAW`. * @return `LRESULT` containing draw flags or the result of default subclass processing. * * @see prepaintToolbarItem() * @see postpaintToolbarItem() */ [[nodiscard]] static LRESULT darkToolbarNotifyCustomDraw( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) noexcept { switch (auto* lptbcd = reinterpret_cast<LPNMTBCUSTOMDRAW>(lParam); lptbcd->nmcd.dwDrawStage) { case CDDS_PREPAINT: { ::FillRect(lptbcd->nmcd.hdc, &lptbcd->nmcd.rc, dmlib::getDlgBackgroundBrush()); return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT; } case CDDS_ITEMPREPAINT: { return prepaintToolbarItem(lptbcd); } case CDDS_ITEMPOSTPAINT: { Link: Applies custom drawing to a toolbar items (buttons) during `CDDS_ITEMPOSTPAINT. /** * @brief Applies custom drawing to a toolbar items (buttons) during `CDDS_ITEMPOSTPAINT. * * Paints arrow glyph with custom color over system black "down triangle" for button with style `BTNS_DROPDOWN`. * Triggered by `CDRF_NOTIFYPOSTPAINT` from @ref prepaintToolbarItem. * * Logic: * - Retrieves the drop-down rectangle via `TB_GETITEMDROPDOWNRECT`. * - Selects the toolbar font and draws a centered arrow glyph with custom text color. * * @param[in] lptbcd Reference to `LPNMTBCUSTOMDRAW`. * @return `CDRF_DODEFAULT` to let default text/icon drawing proceed normally. * * @note Only applies to iconic buttons. * * @see prepaintToolbarItem() * @see darkToolbarNotifyCustomDraw() */ [[nodiscard]] static LRESULT postpaintToolbarItem(const LPNMTBCUSTOMDRAW& lptbcd) noexcept { TBBUTTONINFOW tbi{}; tbi.cbSize = sizeof(TBBUTTONINFOW); tbi.dwMask = TBIF_IMAGE; ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_GETBUTTONINFO, lptbcd->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&tbi)); if (tbi.iImage == I_IMAGENONE) { return CDRF_DODEFAULT; } RECT rcArrow{}; const auto idx = ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_COMMANDTOINDEX, lptbcd->nmcd.dwItemSpec, 0); ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_GETITEMDROPDOWNRECT, static_cast<WPARAM>(idx), reinterpret_cast<LPARAM>(&rcArrow)); rcArrow.left += 1; rcArrow.bottom -= dmlib_dpi::scale(3, lptbcd->nmcd.hdr.hwndFrom); ::SetBkMode(lptbcd->nmcd.hdc, TRANSPARENT); ::SetTextColor(lptbcd->nmcd.hdc, dmlib::getTextColor()); const auto hFont = dmlib_paint::GdiObject{ lptbcd->nmcd.hdc, lptbcd->nmcd.hdr.hwndFrom }; static constexpr UINT dtFlags = DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX; ::DrawText(lptbcd->nmcd.hdc, dmlib_glyph::kTriangleDown, -1, &rcArrow, dtFlags); return CDRF_DODEFAULT; } Link: Applies custom drawing to a toolbar items (buttons) during `CDDS_ITEMPREPAINT` /** * @brief Applies custom drawing to a toolbar items (buttons) during `CDDS_ITEMPREPAINT` * * Handles color assignment and background painting for toolbar buttons during the * `CDDS_ITEMPREPAINT` stage of `NMTBCUSTOMDRAW`. Applies appropriate brushes, pens, * and background drawing depending on the button state: * - **Hot**: Uses hot background and edge styling. * - **Checked**: Uses control background and standard edge styling. * - **Drop-down**: Calculates and paints iconic split-button drop arrow. * * Also configures transparency and color usage for text, hot-tracking, and background fills. * Ensures hot/checked states are visually overridden by custom color highlights. * * @param[in,out] lptbcd Reference to the toolbar's custom draw structure. * @return Flags to control draw behavior (`TBCDRF_USECDCOLORS`, `TBCDRF_NOBACKGROUND`, `CDRF_NOTIFYPOSTPAINT`). * * @note This function clears `CDIS_HOT`/`CDIS_CHECKED` to allow manual visual overrides. * * @see postpaintToolbarItem() * @see darkToolbarNotifyCustomDraw() */ [[nodiscard]] static LRESULT prepaintToolbarItem(LPNMTBCUSTOMDRAW& lptbcd) noexcept { // Set colors lptbcd->hbrMonoDither = dmlib::getBackgroundBrush(); lptbcd->hbrLines = dmlib::getEdgeBrush(); lptbcd->hpenLines = dmlib::getEdgePen(); lptbcd->clrText = dmlib::getDarkerTextColor(); lptbcd->clrTextHighlight = dmlib::getTextColor(); lptbcd->clrBtnFace = dmlib::getBackgroundColor(); lptbcd->clrBtnHighlight = dmlib::getCtrlBackgroundColor(); lptbcd->clrHighlightHotTrack = dmlib::getHotBackgroundColor(); lptbcd->nStringBkMode = TRANSPARENT; lptbcd->nHLStringBkMode = TRANSPARENT; // Get styles and rectangles const bool isHot = (lptbcd->nmcd.uItemState & CDIS_HOT) == CDIS_HOT; const bool isChecked = (lptbcd->nmcd.uItemState & CDIS_CHECKED) == CDIS_CHECKED; RECT rcItem{ lptbcd->nmcd.rc }; RECT rcDrop{}; TBBUTTONINFOW tbi{}; tbi.cbSize = sizeof(TBBUTTONINFOW); tbi.dwMask = TBIF_IMAGE | TBIF_STYLE; ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_GETBUTTONINFO, lptbcd->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&tbi)); const bool isIcon = tbi.iImage != I_IMAGENONE; const bool isDropDown = ((static_cast<WORD>(tbi.fsStyle) & BTNS_DROPDOWN) == BTNS_DROPDOWN) && isIcon; // has 2 "buttons" if (isDropDown) { const auto idx = ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_COMMANDTOINDEX, lptbcd->nmcd.dwItemSpec, 0); ::SendMessage(lptbcd->nmcd.hdr.hwndFrom, TB_GETITEMDROPDOWNRECT, static_cast<WPARAM>(idx), reinterpret_cast<LPARAM>(&rcDrop)); rcItem.right = rcDrop.left; } static const int roundness = dmlib::isAtLeastWindows11() ? dmlib_paint::kWin11CornerRoundness + 1 : 0; // Paint part if (isHot) // hot must have higher priority to overwrite checked state { if (!isIcon) { ::FillRect(lptbcd->nmcd.hdc, &rcItem, dmlib::getHotBackgroundBrush()); } else { dmlib_paint::paintRoundRect(lptbcd->nmcd.hdc, rcItem, dmlib::getHotEdgePen(), dmlib::getHotBackgroundBrush(), roundness, roundness); if (isDropDown) { dmlib_paint::paintRoundRect(lptbcd->nmcd.hdc, rcDrop, dmlib::getHotEdgePen(), dmlib::getHotBackgroundBrush(), roundness, roundness); } } lptbcd->nmcd.uItemState &= ~static_cast<UINT>(CDIS_CHECKED | CDIS_HOT); // clears states to use custom highlight } else if (isChecked) { if (!isIcon) { ::FillRect(lptbcd->nmcd.hdc, &rcItem, dmlib::getCtrlBackgroundBrush()); } else { dmlib_paint::paintRoundRect(lptbcd->nmcd.hdc, rcItem, dmlib::getEdgePen(), dmlib::getCtrlBackgroundBrush(), roundness, roundness); if (isDropDown) { dmlib_paint::paintRoundRect(lptbcd->nmcd.hdc, rcDrop, dmlib::getEdgePen(), dmlib::getCtrlBackgroundBrush(), roundness, roundness); } } lptbcd->nmcd.uItemState &= ~static_cast<UINT>(CDIS_CHECKED); // clears state to use custom highlight } LRESULT retVal = TBCDRF_USECDCOLORS; if ((lptbcd->nmcd.uItemState & CDIS_SELECTED) == CDIS_SELECTED) { retVal |= TBCDRF_NOBACKGROUND; } if (isDropDown) { retVal |= CDRF_NOTIFYPOSTPAINT; } return retVal; }
Solution Nine Posted May 14 Solution Posted May 14 (edited) Here one way : expandcollapse popup; From Nine #include <GUIConstants.au3> #include <WinAPI.au3> #include <StructureConstants.au3> #include <GuiToolbar.au3> #include <WinAPITheme.au3> Opt("MustDeclareVars", True) 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 Const $TBCDRF_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 ConsoleWrite($tagNMTBCUSTOMDRAW & @CRLF) Example() Func Example() Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp Local $hGUI = GUICreate("Toolbar", 600, 400) Local $hToolbar = _GUICtrlToolbar_Create($hGUI) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState() _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR) _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, $e_idHelp, $STD_HELP) Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _GUICtrlToolbar_Destroy($hToolbar) EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" Or $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG If $tTool.dwDrawStage = $CDDS_PREPAINT Then Local $hBrush = _WinAPI_CreateSolidBrush(0x606060) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) Return $CDRF_NOTIFYITEMDRAW ElseIf $tTool.dwDrawStage = $CDDS_ITEMPREPAINT And BitAND($tTool.uItemState, $CDIS_HOT) Then $tTool.clrHighlightHotTrack = BitAND($tTool.uItemState, $CDIS_SELECTED) ? 0xA0A0A0 : 0x808080 Return $TBCDRF_HILITEHOTTRACK EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited May 14 by Nine better code WildByDesign 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
WildByDesign Posted May 14 Author Posted May 14 1 hour ago, Nine said: Here one way : This is fantastic, thank you! Looking at your $tagNMTBCUSTOMDRAW, I see now that the brushes are Pointers. I definitely never would have got that, so I appreciate it. Now I can also see why the win32-darkmodelib project also has code for painting over the line just above the toolbar. Similar to the white line that has to be painted over with a dark mode menubar. I assume that this white line is likely non-client area as well. This gives me something to work with and try some things and learn from. And if something good comes out of it, maybe it can eventually be added to the GUIDarkTheme UDF.
WildByDesign Posted May 14 Author Posted May 14 Adding the following below GUISetState fixes the issue with the white line above the toolbar: _GUICtrlToolbar_SetColorScheme($hToolbar, 0x606060, 0x606060) Nine 1
WildByDesign Posted Tuesday at 01:08 PM Author Posted Tuesday at 01:08 PM (edited) I'm trying to handle Rebar controls in the Toolbar subclass as well and it is partially working. Can someone please help me with setting the text color to white for Rebar and Toolbar? I have tried various attempts with SetTextColor and SetBkMode but no success at all. I've tried dozens of things to change the text color and all failed. Such as: $tTool.clrText = 0xFFFFFF There are some other controls in my current testing example (below) that are not in dark mode but I'm not worried about those. I'm just trying to handle the Rebar and Toolbar at the moment. expandcollapse popup#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> ; Initialize System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Global Const $TBCDRF_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 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 Example() Func Example() Local $hGui = GUICreate("Rebar Create (v" & @AutoItVersion & ")", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) GUISetBkColor(0x202020) ; create the rebar control $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) _WinAPI_SetWindowTheme($g_hReBar, 'DarkMode_DarkTheme') _GUICtrlRebar_SetColorScheme($g_hReBar, Int(0x333333), Int(0x333333)) _GUICtrlRebar_SetTextColor($g_hReBar, Int(0xFFFFFF)) ; create a toolbar to put in the rebar Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) ;_GUICtrlToolbar_SetWindowTheme($hToolbar, 'DarkMode') ; this will give us white text, but rather WM_NOTIFY _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838) _GUICtrlToolbar_SetStyleTransparent($hToolbar, False) ; 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 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]) _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 ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20) Local $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:") Local $idBtn_Exit = GUICtrlCreateButton("Exit", 150, 360, 100, 25) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtn_Exit Exit EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; commented out code below is just testing resizing of toolbar, but complex now with rebar #cs Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hFrom = $tNMHDR.hWndFrom ConsoleWrite("class: " & _WinAPI_GetClassName($hFrom) & @CRLF) Local $aSize = WinGetClientSize($hWnd) WinMove($tTool.hWndFrom, "", 0, 0, $aSize[0]) Return $GUI_RUNDEFMSG #ce Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" And _WinAPI_GetClassName($tTool.hWndFrom) <> "ReBarWindow32" Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tTool.dwDrawStage $tTool.clrText = 0xFFFFFF 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.clrHighlightHotTrack = BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060 Return $TBCDRF_HILITEHOTTRACK EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited Tuesday at 01:10 PM by WildByDesign updated code example
WildByDesign Posted Tuesday at 01:28 PM Author Posted Tuesday at 01:28 PM I think I know what my mistake was. I was setting text color but I did not follow up with DrawText. I believe that I need to do that for both Rebar and Toolbar. So I still need help with text color, if anyone can please help. The main thing is, I'm not sure yet how to get the text that needs to be drawn.
WildByDesign Posted Tuesday at 01:35 PM Author Posted Tuesday at 01:35 PM It looks like I can get Rebar text with _GUICtrlRebar_GetBandText. However, I don't know how to get the index that is currently being drawn within the WM_NOTIFY. Possibly IDFrom or dwItemSpec but I don't really understand those yet. Please keep in mind that I am almost always learning AutoIt while I do this. Anyway new, I'm learning on-the-fly.
WildByDesign Posted Tuesday at 05:10 PM Author Posted Tuesday at 05:10 PM Some success. I cleaned it up quite a bit but still some stuff to figure out. expandcollapse popup#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_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 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 Example() Func Example() Local $hGui = GUICreate("Rebar Create (v" & @AutoItVersion & ")", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) GUISetBkColor(0x202020) ; create the rebar control $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) _WinAPI_SetWindowTheme($g_hReBar, 'DarkMode_DarkTheme') _GUICtrlRebar_SetColorScheme($g_hReBar, Int(0x333333), Int(0x333333)) _GUICtrlRebar_SetTextColor($g_hReBar, Int(0xFFFFFF)) ; create a toolbar to put in the rebar Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) ;_GUICtrlToolbar_SetWindowTheme($hToolbar, 'DarkMode') ; this will give us white text, but rather WM_NOTIFY _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838) _GUICtrlToolbar_SetStyleTransparent($hToolbar, False) ; 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 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]) _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 ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20) Local $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:") Local $idBtn_Exit = GUICtrlCreateButton("Exit", 150, 360, 100, 25) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtn_Exit Exit EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; commented out code below is just testing resizing of toolbar, but complex now with rebar #cs Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hFrom = $tNMHDR.hWndFrom ConsoleWrite("class: " & _WinAPI_GetClassName($hFrom) & @CRLF) Local $aSize = WinGetClientSize($hWnd) WinMove($tTool.hWndFrom, "", 0, 0, $aSize[0]) Return $GUI_RUNDEFMSG #ce Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG ;If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" And _WinAPI_GetClassName($tTool.hWndFrom) <> "ReBarWindow32" Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tTool.dwDrawStage Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom) Switch $sClass 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.clrHighlightHotTrack = BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060 Return $TBCDRF_HILITEHOTTRACK EndIf EndSwitch Case "ReBarWindow32" ;ConsoleWrite("rebar text: " & _GUICtrlRebar_GetBandText($tTool.hWndFrom, 1) & @CRLF) 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 $tRECT = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) _WinAPI_SetTextColor($tTool.hdc, 0xFFFFFF) _WinAPI_SetBkMode($tTool.hdc, $TRANSPARENT) _WinAPI_DrawText($tTool.hdc, "ABC", $tRECT, BitOR($DT_CENTER, $DT_VCENTER)) Return $CDRF_NEWFONT ;Return BitOR($CDRF_NEWFONT, $CDRF_SKIPDEFAULT) ; problem losing grippers with this EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
WildByDesign Posted Tuesday at 06:07 PM Author Posted Tuesday at 06:07 PM I figured out the Rebar Index and text now. Still need to figure out text size. Need to alter rect a bit I assume. expandcollapse popup#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_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 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 Example() Func Example() Local $hGui = GUICreate("Rebar Create (v" & @AutoItVersion & ")", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) GUISetBkColor(0x202020) ; create the rebar control $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) _WinAPI_SetWindowTheme($g_hReBar, 'DarkMode_DarkTheme') _GUICtrlRebar_SetColorScheme($g_hReBar, Int(0x333333), Int(0x333333)) _GUICtrlRebar_SetTextColor($g_hReBar, Int(0xFFFFFF)) ; create a toolbar to put in the rebar Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) ;_GUICtrlToolbar_SetWindowTheme($hToolbar, 'DarkMode') ; this will give us white text, but rather WM_NOTIFY _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838) _GUICtrlToolbar_SetStyleTransparent($hToolbar, False) ; 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 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]) _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 ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20) Local $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:") Local $idBtn_Exit = GUICtrlCreateButton("Exit", 150, 360, 100, 25) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtn_Exit Exit EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; commented out code below is just testing resizing of toolbar, but complex now with rebar #cs Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hFrom = $tNMHDR.hWndFrom ConsoleWrite("class: " & _WinAPI_GetClassName($hFrom) & @CRLF) Local $aSize = WinGetClientSize($hWnd) WinMove($tTool.hWndFrom, "", 0, 0, $aSize[0]) Return $GUI_RUNDEFMSG #ce Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG ;If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" And _WinAPI_GetClassName($tTool.hWndFrom) <> "ReBarWindow32" Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tTool.dwDrawStage Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom) Switch $sClass 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.clrHighlightHotTrack = BitAND($iState, $CDIS_SELECTED) ? 0x484848 : 0x606060 Return $TBCDRF_HILITEHOTTRACK EndIf EndSwitch Case "ReBarWindow32" ;ConsoleWrite("rebar text: " & _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) & @CRLF) Local $sText = _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) 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 $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) _WinAPI_SetTextColor($tTool.hdc, 0xFFFFFF) _WinAPI_SetBkMode($tTool.hdc, $TRANSPARENT) If $sText <> "" Then _WinAPI_DrawText($tTool.hdc, $sText, $tRect, BitOR($DT_CENTER, $DT_VCENTER, $DT_NOCLIP)) Return $CDRF_NEWFONT ;Return BitOR($CDRF_NEWFONT, $CDRF_SKIPDEFAULT) ; problem losing grippers with this EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY
WildByDesign Posted Wednesday at 12:53 PM Author Posted Wednesday at 12:53 PM (edited) @Nine As persistent as I am, I finally succeeded in something remarkable that can be useful in other CUSTOMDRAW buttons as well. 😁 In the toolbar, I finally got working: White text (without having to apply theme) Rounded CUSTOMDRAW buttons with _WinAPI_RoundRect Hot, Selected and Normal are working beautifully We should be able to change the pen colour also but I kept it default so far. But we should likely change pen colour. EDIT: Added pen colour to example I still need to look into CDIS_CHECKED and likely need to do something with it but haven't tested Checked state at all yet. EDIT: Added CDIS_CHECKED to example I really, really need some help with the "ReBarWindow32" section if you can help, please. I am struggling with changing the text colour to white for rebar bands. I don't think that I can do it as easily as with the toolbars. My DrawText is a mess, alignment is a mess. I had to create a font because the size wasn't exactly right initially. Anyway, here is my current example with rounded toolbar buttons and also includes the Rebar stuff. I feel like if I do the toolbar stuff, I kind of need to handle Rebar as well. expandcollapse popup#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 $g_hRebarFont = _CreateFont("Segoe UI", 9) Global Const $TBCDRF_USECDCOLORS = 0x800000 Global Const $TBCDRF_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 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, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) GUISetBkColor(0x202020) ; create the rebar control $g_hReBar = _GUICtrlRebar_Create($hGui, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) _WinAPI_SetWindowTheme($g_hReBar, 'DarkMode_DarkTheme') _GUICtrlRebar_SetColorScheme($g_hReBar, Int(0x333333), Int(0x333333)) ; create a toolbar to put in the rebar Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) ;_GUICtrlToolbar_SetWindowTheme($hToolbar, 'DarkMode') ; this will give us white text, but rather WM_NOTIFY _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838) _GUICtrlToolbar_SetStyleTransparent($hToolbar, False) ; 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 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 ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20) Local $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:") Local $idBtn_Exit = GUICtrlCreateButton("Exit", 150, 360, 100, 25) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) GUISetState(@SW_SHOW) _GUICtrlToolbar_CheckButton($hToolbar, $e_idSave) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idBtn_Exit Exit EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) ; commented out code below is just testing resizing of toolbar, but complex now with rebar #cs Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hFrom = $tNMHDR.hWndFrom ConsoleWrite("class: " & _WinAPI_GetClassName($hFrom) & @CRLF) Local $aSize = WinGetClientSize($hWnd) WinMove($tTool.hWndFrom, "", 0, 0, $aSize[0]) Return $GUI_RUNDEFMSG #ce Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG ;If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" And _WinAPI_GetClassName($tTool.hWndFrom) <> "ReBarWindow32" Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tTool.dwDrawStage Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom) Switch $sClass 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, 0xC0C0C0) 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 ConsoleWrite("CDIS_CHECKED" & @CRLF) $tTool.clrText = 0xFFFFFF $tTool.clrTextHighlight = 0xFFFFFF Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) Local $hPen = _WinAPI_CreatePen($PS_SOLID, 1, 0xC0C0C0) 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 "ReBarWindow32" ;ConsoleWrite("rebar text: " & _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) & @CRLF) ;Local $sText = _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) 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 $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) Local $sText = _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) _WinAPI_SelectObject($tTool.hdc, $g_hRebarFont) _WinAPI_InflateRect($tRect, -4, -6) _WinAPI_SetTextColor($tTool.hdc, 0xFFFFFF) _WinAPI_SetBkMode($tTool.hdc, $TRANSPARENT) If $sText <> "" Then _WinAPI_DrawText($tTool.hdc, $sText, $tRect, BitOR($DT_LEFT, $DT_VCENTER, $DT_NOCLIP)) Return $CDRF_NEWFONT ;Return BitOR($CDRF_NEWFONT, $CDRF_NOTIFYPOSTPAINT) ;Return BitOR($CDRF_NEWFONT, $CDRF_SKIPDEFAULT) ; problem losing grippers with this #cs Case $CDDS_ITEMPOSTPAINT ConsoleWrite("CDDS_ITEMPOSTPAINT" & @CRLF) Local $hBrush = _WinAPI_CreateSolidBrush(0x383838) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) Return $CDRF_SKIPDEFAULT #ce EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _CreateFont($sFontName, $nHeight = 9, $nWidth = 400) Local $stFontName = DllStructCreate("char[260]") DllStructSetData($stFontName, 1, $sFontName) Local $hDC = _WinAPI_GetDC(0) ; Get the Desktops DC Local $nPixel = _WinAPI_GetDeviceCaps($hDC, 90) $nHeight = 0 - _WinAPI_MulDiv($nHeight, $nPixel, 72) _WinAPI_ReleaseDC(0, $hDC) Local $hFont = _WinAPI_CreateFont($nHeight, 0, 0, 0, $nWidth, False, False, False, _ $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, $sFontName) Return $hFont EndFunc ;==>_CreateFont Edited Wednesday at 01:30 PM by WildByDesign Updated example with pen colour
WildByDesign Posted 16 hours ago Author Posted 16 hours ago On 5/20/2026 at 8:53 AM, WildByDesign said: I really, really need some help with the "ReBarWindow32" section if you can help, please. I am struggling with changing the text colour to white for rebar bands. I don't think that I can do it as easily as with the toolbars. My DrawText is a mess, alignment is a mess. I had to create a font because the size wasn't exactly right initially. I finally succeeded in getting white text without using DrawText. There were far too many complications with DrawText for Rebar controls. The trick ended up being the removal of the theme from the Rebar control. This is what allowed the SetTextColor/SetBkMode functions to start working in the WM_NOTIFY function. It works quite well now. I will still have to find a way to paint a better gripper edge (and possibly chevron) on the rebar bands. But so far, so good. Messy example, but working well. For what it's worth, my examples are always messy while they are still a W.I.P. until all outstanding issues are resolved. Then I go in for the clean up. 😆 expandcollapse popup#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 $g_hRebarFont = _CreateFont("Segoe UI", 9) Global Const $TBCDRF_USECDCOLORS = 0x800000 Global Const $TBCDRF_NOBACKGROUND = 0x400000 Global Const $TBCDRF_HILITEHOTTRACK = 0x20000 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)) _WinAPI_SetWindowTheme($g_hReBar, 'DarkMode_DarkTheme') _GUICtrlRebar_SetColorScheme($g_hReBar, Int(0x333333), Int(0x333333)) ; create a toolbar to put in the rebar Local $hToolbar = _GUICtrlToolbar_Create($hGui, BitOR($TBSTYLE_FLAT, $CCS_NORESIZE, $CCS_NOPARENTALIGN)) ;_GUICtrlToolbar_SetWindowTheme($hToolbar, 'DarkMode') ; this will give us white text, but rather WM_NOTIFY _GUICtrlToolbar_SetColorScheme($hToolbar, 0x383838, 0x383838) _GUICtrlToolbar_SetStyleTransparent($hToolbar, False) ; 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 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 ; $hInput = GUICtrlCreateInput("Input control", 0, 0, 120, 20) Local $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:") _WinAPI_SetWindowTheme($g_hReBar, "", "") ;_GUICtrlRebar_SetTextColor($g_hReBar, 0xFFFFFF) ;GUIRegisterMsg($WM_CTLCOLORDLG, "_WM_CTLCOLOR") ; returns for GUI 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) ; commented out code below is just testing resizing of toolbar, but complex now with rebar #cs Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hFrom = $tNMHDR.hWndFrom ConsoleWrite("class: " & _WinAPI_GetClassName($hFrom) & @CRLF) Local $aSize = WinGetClientSize($hWnd) WinMove($tTool.hWndFrom, "", 0, 0, $aSize[0]) Return $GUI_RUNDEFMSG #ce Local $tTool = DllStructCreate($tagNMTBCUSTOMDRAW, $lParam) If $tTool.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG ;If _WinAPI_GetClassName($tTool.hWndFrom) <> "ToolbarWindow32" And _WinAPI_GetClassName($tTool.hWndFrom) <> "ReBarWindow32" Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tTool.dwDrawStage Local $sClass = _WinAPI_GetClassName($tTool.hWndFrom) Switch $sClass 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 "ReBarWindow32" ;ConsoleWrite("rebar text: " & _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) & @CRLF) ;Local $sText = _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) 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 $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) Local $sText = _GUICtrlRebar_GetBandText($tTool.hWndFrom, $tTool.dwItemSpec) _WinAPI_SelectObject($tTool.hdc, $g_hRebarFont) ;_WinAPI_InflateRect($tRect, -4, -6) _WinAPI_SetTextColor($tTool.hdc, 0xFFFFFF) _WinAPI_SetBkMode($tTool.hdc, $TRANSPARENT) ;If $sText <> "" Then ConsoleWrite("text: " & $sText & " : " & "band: " & $tTool.dwItemSpec & @CRLF) ;If $sText <> "" Then _WinAPI_DrawText($tTool.hdc, $sText, $tRect, BitOR($DT_LEFT, $DT_VCENTER, $DT_NOCLIP)) ;Return $CDRF_NEWFONT Return BitOR($CDRF_NEWFONT, $CDRF_NOTIFYPOSTPAINT) ;Return BitOR($CDRF_NEWFONT, $CDRF_SKIPDEFAULT) ; problem losing grippers with this #cs Case $CDDS_ITEMPOSTPAINT ConsoleWrite("CDDS_ITEMPOSTPAINT" & @CRLF) Local $hBrush = _WinAPI_CreateSolidBrush(0x383838) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tTool, "left")) _WinAPI_FillRect($tTool.hdc, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) Return $CDRF_SKIPDEFAULT #ce EndSwitch Case Else Return $GUI_RUNDEFMSG EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _CreateFont($sFontName, $nHeight = 9, $nWidth = 400) Local $stFontName = DllStructCreate("char[260]") DllStructSetData($stFontName, 1, $sFontName) Local $hDC = _WinAPI_GetDC(0) ; Get the Desktops DC Local $nPixel = _WinAPI_GetDeviceCaps($hDC, 90) $nHeight = 0 - _WinAPI_MulDiv($nHeight, $nPixel, 72) _WinAPI_ReleaseDC(0, $hDC) Local $hFont = _WinAPI_CreateFont($nHeight, 0, 0, 0, $nWidth, False, False, False, _ $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, $sFontName) Return $hFont EndFunc ;==>_CreateFont argumentum 1
Nine Posted 13 hours ago Posted 13 hours ago (edited) That seems to be working fine : expandcollapse popup; From Nine #include <GuiReBar.au3> #include <GUIConstants.au3> #include <GuiComboBox.au3> #include <GuiEdit.au3> #include <WinAPITheme.au3> Example() Func Example() Local $hGUI = GUICreate("Rebar Create", 400, 396, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_MAXIMIZEBOX)) GUISetBkColor(0x202020) Local $hReBar = _GUICtrlRebar_Create($hGUI, BitOR($CCS_TOP, $WS_BORDER, $RBS_VARHEIGHT, $RBS_AUTOSIZE, $RBS_BANDBORDERS)) _WinAPI_SetWindowTheme($hReBar, "", "") _GUICtrlRebar_SetColorScheme($hReBar, Int(0x404040), Int(0x404040)) _GUICtrlRebar_SetBKColor($hReBar, 0x404040) _GUICtrlRebar_SetTextColor($hReBar, 0xFFFFFF) Local $hCombo = _GUICtrlComboBox_Create($hGUI, "", 0, 0, 120) _GUICtrlComboBox_BeginUpdate($hCombo) _GUICtrlComboBox_AddDir($hCombo, @ScriptDir & "\*.au3") _GUICtrlComboBox_EndUpdate($hCombo) Local $hInput = _GUICtrlEdit_Create($hGUI, "Input control", 0, 0, 120, 20) _GUICtrlRebar_AddBand($hReBar, $hCombo, 120, 200, "Dir *.au3") _GUICtrlRebar_AddBand($hReBar, $hInput, 120, 200, "Name:") Local $idExit = GUICtrlCreateButton("Exit", 150, 360, 100, 25) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idExit Exit EndSwitch WEnd EndFunc ;==>Example Edited 13 hours ago by Nine WildByDesign 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
WildByDesign Posted 5 hours ago Author Posted 5 hours ago 7 hours ago, Nine said: _WinAPI_SetWindowTheme($hReBar, "", "") _GUICtrlRebar_SetColorScheme($hReBar, Int(0x404040), Int(0x404040)) _GUICtrlRebar_SetBKColor($hReBar, 0x404040) _GUICtrlRebar_SetTextColor($hReBar, 0xFFFFFF) This was really interesting because I had tried _GUICtrlRebar_SetBKColor and _GUICtrlRebar_SetTextColor on several occasions and they never worked for me. The help file examples for both also fail to color. Those help file examples would need to be fixed. And here you have it working. So it turns out the bug (or trick) is that those functions absolutely must be called before creating any of the rebar bands. If you call them after the bands are created, it will not work to color. Unfortunately, this also means that I cannot use those in GUIDarkTheme UDF because the user will have already created the rebar bands at the time when the UDF is initiated. So I will likely have to continue the subclass method. Although hmm... this has me thinking. I could technically initiate the UDF upon include by implementing an event hook to catch any windows/controls upon creation ($EVENT_OBJECT_CREATE) and theme/subclass them instantly.
mLipok Posted 5 hours ago Posted 5 hours ago What about switching theme ? Signature beginning:* Please remember: "AutoIt"..... * Wondering who uses AutoIt and what it can be used for ? * Forum Rules ** ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Code * for other useful stuff click the following button: Spoiler Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API * ErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 * My contribution to others projects or UDF based on others projects: * _sql.au3 UDF * POP3.au3 UDF * RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF * SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane * Useful links: * Forum Rules * Forum etiquette * Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * Wiki: * Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX IE Related: * How to use IE.au3 UDF with AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler * IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related: * How to get reference to PDF object embeded in IE * IE on Windows 11 * I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions * EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *I also encourage you to check awesome @trancexx code: * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuff * OnHungApp handler * Avoid "AutoIt Error" message box in unknown errors * HTML editor * winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/ "Homo sum; humani nil a me alienum puto" - Publius Terentius Afer"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming" , be and \\//_. Anticipating Errors : "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty." Signature last update: 2023-04-24
WildByDesign Posted 4 hours ago Author Posted 4 hours ago 5 minutes ago, mLipok said: What about switching theme ? Yes, that is a good point. I assume that you are referring to the event hook comment. As fun as it would be to implement and technically possible (yet challenging), I am going to keep the UDF as it is now. This way the user has all control over theme switching.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now