Skip to content

Commit

Permalink
smaller border in owner drawn menus for themes
Browse files Browse the repository at this point in the history
  • Loading branch information
kjk committed Nov 2, 2023
1 parent d0f91af commit 4b58a85
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,10 +1905,35 @@ void FreeMenuOwnerDrawInfoData(HMENU hmenu) {
}
};
}

void MarkMenuOwnerDraw(HMENU hmenu) {
if (!ThemeColorizeControls()) {
return;
}

// https://stackoverflow.com/questions/30353644/cmenu-border-color-on-mfc
static HBRUSH hbrBrush = nullptr;
static COLORREF bgCol = (COLORREF)-1;
COLORREF col = ThemeMainWindowBackgroundColor();
if (!hbrBrush) {
bgCol = col;
hbrBrush = ::CreateSolidBrush(col);
} else {
if (col != bgCol) {
// in case theme changed
DeleteBrush(hbrBrush);
bgCol = col;
hbrBrush = ::CreateSolidBrush(col);
}
}

MENUINFO mi = {0};
mi.cbSize = sizeof(MENUINFO);
GetMenuInfo(hmenu, &mi);
mi.hbrBack = hbrBrush;
mi.fMask = MIM_BACKGROUND | MIM_STYLE | MIM_APPLYTOSUBMENUS;
SetMenuInfo(hmenu, &mi);

WCHAR buf[1024];

MENUITEMINFOW mii{};
Expand All @@ -1923,7 +1948,6 @@ void MarkMenuOwnerDraw(HMENU hmenu) {
mii.cch = dimof(buf);
BOOL ok = GetMenuItemInfoW(hmenu, (uint)i, TRUE /* by position */, &mii);
CrashIf(!ok);

mii.fMask = MIIM_FTYPE | MIIM_DATA;
mii.fType |= MFT_OWNERDRAW;
if (mii.dwItemData != 0) {
Expand Down
2 changes: 1 addition & 1 deletion src/SumatraStartup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) {
// and also to keep TabState forever for lazy loading of tabs
sessionData = gGlobalPrefs->sessionData;
gGlobalPrefs->sessionData = new Vec<SessionData*>();
// do not restore a session if there's
// do not restore a session if tabs are disabled and SumatraPDF is already running
if (sessionData->size() > 0 && !gPluginURL) {
bool noRestore = !gGlobalPrefs->useTabs && (FindPrevInstWindow(&hMutex) != nullptr);
if (!noRestore) {
Expand Down

0 comments on commit 4b58a85

Please sign in to comment.