Menu

How to merge dark mode support in mini frame sample?

kite
2023-01-17
2023-01-19
  • kite

    kite - 2023-01-17

    I like mini mode/full mode for main frame like TitlebarFrame sample, and I like dark/light mode switching like darkmode sample. I want to leverage dark mode support for mini/full mode. How can I?

     
  • David

    David - 2023-01-18

    Hi Kite,

    For the most part, the DarkMode sample differs from the Frame sample in that it overrides CFrame::OnSysColorChange and CFrame::SetTheme, and adds SetDarkTheme.

    You should be able to modify the TitlebarFrame sample to support dark mode by copying code from the DarkMode sample.

    The following guide might prove useful.

    1) Start with a copy of the TitlebarFrame sample. Its best to use the most recent TitlebarFrame available from the code snapshot from SourceForge.

    2) Add the following files from the DarkMode sample to your project:
    - DarkAbout.h
    - DarkAbout.cpp
    - DarkMode.h
    - DarkMode.cpp
    - DarkPreview.h

    3) Add the following functions from the DarkMode sample:
    - CMainFrame::OnHelp
    - CMainFrame::OnSysColorChange
    - CMainFrame::SetDarkTheme
    - CMainFrame::SetTheme

    4) Remove the ::DwmSetWindowAttribute function from CMainFrame::OnSysColorChange

    5) Add the following private members to CMainFrame:
    CDarkPreview<cview> m_preview;
    CDarkAbout m_helpDialog;</cview>

    6) Add the following to MainFrame.h
    #include "DarkAbout.h"
    #include "DarkPreview.h"

    7) Add the following to MainFrame.cpp
    #include "DarkMode.h"

    8) The code should now compile and detect dark mode. You will need to tweak the colors for darkmode in:
    - CMainFrame::DrawTitleText
    - CMainFrame::DrawBackground
    - CMainFrame::DrawCloseButton
    - CMainFrame::DrawMinimizeButton
    - CMainFrame::DrawMaximizeButton

    Best regards,
    David

     
  • kite

    kite - 2023-01-19

    Got it. Thanks!

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.