From ba9c42e5bbee70975795bb60104ebbc2d65a54b6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 15 Oct 2018 01:53:22 -0400 Subject: [PATCH] More theming work. We may actually have it this time! --- doc/misctests/winbuttonexplorertheme.cpp | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/doc/misctests/winbuttonexplorertheme.cpp b/doc/misctests/winbuttonexplorertheme.cpp index 53101212..b536a4b9 100644 --- a/doc/misctests/winbuttonexplorertheme.cpp +++ b/doc/misctests/winbuttonexplorertheme.cpp @@ -209,8 +209,10 @@ void updateTheme(HWND hwnd) HDC dc; SIZE size; HBITMAP hb; - HTHEME fontTheme; + HTHEME fontTheme, buttonTheme; LOGFONTW lf; + MARGINS marginOffsets; + RECT margins; int i; if (buttonFont != NULL) { @@ -253,7 +255,32 @@ void updateTheme(HWND hwnd) bim.margin.left = 1; bim.uAlign = BUTTON_IMAGELIST_ALIGN_RIGHT; for (i = 0; i < 3; i++) - SendMessage(leftButtons[i], BCM_SETIMAGELIST, 0, (LPARAM) (&bim)); + SendMessageW(leftButtons[i], BCM_SETIMAGELIST, 0, (LPARAM) (&bim)); + + fontTheme = OpenThemeData(hwnd, L"TEXTSTYLE"); + // TODO find the right TMT constant + GetThemeFont(fontTheme, NULL, + 4, 0, + TMT_FONT, &lf); + buttonFont = CreateFontIndirectW(&lf); + CloseThemeData(fontTheme); + for (i = 0; i < 5; i++) + SendMessageW(leftButtons[i], WM_SETFONT, (WPARAM) buttonFont, TRUE); + + buttonTheme = OpenThemeData(hwnd, L"Button"); + ZeroMemory(&marginOffsets, sizeof (MARGINS)); + GetThemeMargins(buttonTheme, NULL, + BP_PUSHBUTTON, PBS_NORMAL, + TMT_CONTENTMARGINS, NULL, &marginOffsets); + CloseThemeData(buttonTheme); + // TODO the constants should be DIPs + margins.left = 13 - marginOffsets.cxLeftWidth; + margins.top = 5 - marginOffsets.cyTopHeight; + margins.right = 13 - marginOffsets.cxRightWidth; + margins.bottom = 5 - marginOffsets.cyBottomHeight; + for (i = 0; i < 5; i++) + if (SendMessageW(leftButtons[i], BCM_SETTEXTMARGIN, 0, (LPARAM) (&margins)) == FALSE) + diele("BCM_SETTEXTMARGIN"); } void repositionButtons(HWND hwnd)