Author Topic: More on theme for dialog  (Read 669 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7485
  • AKA Daniel
More on theme for dialog
« on: October 19, 2022, 06:01:45 AM »
cool ZW supports themes

Just a note, CMFCButton has methods to set the button face, and text color

I'll post more controls as I get to them.

Code - C: [Select]
  1. CAdUiTheme* ThemedDialog::getThmeme()
  2. {
  3.     CAdUiThemeManager* pThemeManager = AdUiGetThemeManager();
  4.     return pThemeManager->GetTheme(PROPERTY_PALETTE_THEME);
  5. }
  6.  
  7. void ThemedDialog::initTheme()
  8. {
  9.     CAdUiTheme* pTheme = this->getThmeme();
  10.     const auto bkColor = pTheme->GetColor(kPaletteBackground);
  11.     const auto fgColor = pTheme->GetColor(kPaletteTabText);
  12.     this->SetBackgroundColor(bkColor);
  13.     this->SetForegroundColor(fgColor);
  14.     m_buttonOk.SetFaceColor(bkColor);
  15.     m_buttonCancel.SetFaceColor(bkColor);
  16.     m_buttonOk.SetTextColor(fgColor);
  17.     m_buttonCancel.SetTextColor(fgColor);
  18.     m_brush.CreateSolidBrush(bkColor);
  19. }
  20. //
  21. HBRUSH ThemedDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  22. {
  23.     switch (nCtlColor)
  24.     {
  25.         case CTLCOLOR_MSGBOX:
  26.         case CTLCOLOR_EDIT:
  27.         case CTLCOLOR_LISTBOX:
  28.         case CTLCOLOR_BTN:
  29.         case CTLCOLOR_DLG:
  30.         case CTLCOLOR_SCROLLBAR:
  31.         case CTLCOLOR_STATIC:
  32.         case CTLCOLOR_MAX:
  33.         {
  34.             pDC->SetTextColor(m_fgcolor);
  35.             pDC->SetBkColor(m_fgcolor);
  36.             pDC->SetBkMode(TRANSPARENT);
  37.             return (HBRUSH)(m_brush.GetSafeHandle());
  38.         }
  39.         default:
  40.             return CAcUiDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  41.     }
  42. }
  43.  
Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7485
  • AKA Daniel
Re: More on theme for dialog
« Reply #1 on: November 02, 2022, 07:45:01 PM »
found a cool function

Code - C: [Select]
  1. #include "dwmapi.h"
  2. #pragma comment( lib, "dwmapi.lib")
  3. void WndTheme::setTitleThemeDark(HWND hwnd)
  4. {
  5.     constexpr DWORD DWMWA_USE_IMMERSIVE_DARK_MODE_I20 = 20;
  6.     BOOL USE_DARK_MODE = true;
  7.     BOOL SET_IMMERSIVE_DARK_MODE_SUCCESS = SUCCEEDED(DwmSetWindowAttribute(
  8.         hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_I20, &USE_DARK_MODE, sizeof(USE_DARK_MODE)));
  9.     const auto style = GetWindowLong(hwnd, GWL_STYLE);
  10.     SetWindowLong(hwnd, GWL_STYLE, 0);
  11.     SetWindowLong(hwnd, GWL_STYLE, style);
  12. }
  13.  

Retired

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7485
  • AKA Daniel
Re: More on theme for dialog
« Reply #2 on: November 02, 2022, 07:47:16 PM »
its kind of an all or none thing, mixing themes in the same app is fugly
except palettes i suppose
Retired