Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Colorize menu bar on dark theme #255

Open
henrypp opened this issue Aug 3, 2024 · 3 comments
Open

Colorize menu bar on dark theme #255

henrypp opened this issue Aug 3, 2024 · 3 comments

Comments

@henrypp
Copy link

henrypp commented Aug 3, 2024

#define WM_UAHDRAWMENU 0x0091 // lParam is UAHMENU
#define WM_UAHDRAWMENUITEM 0x0092 // lParam is UAHDRAWMENUITEM

// hmenu is the main window menu; hdc is the context to draw in
typedef struct _UAHMENU
{
	HMENU hmenu;
	HDC hdc;
	ULONG dwFlags; // no idea what these mean, in my testing it's either 0x00000a00 or sometimes 0x00000a10
} UAHMENU, *LPUAHMENU;

// the position index of the item in the menu, which is duplicated in
// the UAHMENUITEM's iPosition as well
typedef struct _UAHDRAWMENUITEM
{
	DRAWITEMSTRUCT dis;
	UAHMENU um;
	UAHMENUITEM umi;
} UAHDRAWMENUITEM, *LPUAHDRAWMENUITEM;

case WM_UAHDRAWMENU:
{
	MENUBARINFO mbi = {0};
	LPUAHMENU menu_item;
	RECT rect;

	menu_item = (LPUAHMENU)lparam;

	mbi.cbSize = sizeof (mbi);

	// get the menubar rect
	if (!GetMenuBarInfo (hwnd, OBJID_MENU, 0, &mbi))
		break;

	if (!GetWindowRect (hwnd, &rect))
		break;

	// the rcBar is offset by the window rect
	OffsetRect (&mbi.rcBar, -rect.left, -rect.top);

	mbi.rcBar.top -= 1;

	FillRect (menu_item->hdc, &mbi.rcBar, <dark color brush>);

	return TRUE;
}

case WM_UAHDRAWMENUITEM:
{
	LPUAHDRAWMENUITEM menu_item;
	MENUITEMINFO mii = {0};
	DTTOPTS dtto = {0};
	WCHAR buffer[128] = {0};
	HTHEME htheme;
	ULONG flags = DT_CENTER | DT_SINGLELINE | DT_VCENTER;
	INT state_id = MPI_NORMAL;

	menu_item = (LPUAHDRAWMENUITEM)lparam;

	mii.cbSize = sizeof (mii);
	mii.fMask = MIIM_STRING;
	mii.dwTypeData = buffer;
	mii.cch = RTL_NUMBER_OF (buffer);

	if (!GetMenuItemInfoW (menu_item->um.hmenu, menu_item->umi.iPosition, TRUE, &mii))
		break;

	if ((menu_item->dis.itemState & ODS_DEFAULT) || (menu_item->dis.itemState & ODS_INACTIVE))
		state_id = MBI_NORMAL; // normal display

	if ((menu_item->dis.itemState & ODS_SELECTED) || (menu_item->dis.itemState & ODS_HOTLIGHT))
		state_id = MBI_HOT; // hot tracking

	if ((menu_item->dis.itemState & ODS_GRAYED) || (menu_item->dis.itemState & ODS_DISABLED))
		state_id = MBI_DISABLED;

	if (menu_item->dis.itemState & ODS_NOACCEL)
		flags |= DT_HIDEPREFIX;

	htheme = OpenThemeData (hwnd, VSCLASS_MENU);

	if (!htheme)
		break;

	FillRect (menu_item->um.hdc, &menu_item->dis.rcItem, <dark color brush>);

	DrawThemeBackground (htheme, menu_item->um.hdc, MENU_POPUPITEM, state_id, &menu_item->dis.rcItem, NULL);

	dtto.dwFlags = DTT_TEXTCOLOR;
	dtto.crText = RGB (255, 255, 255);

	DrawThemeTextEx (htheme, menu_item->um.hdc, MENU_BARITEM, state_id, buffer, (UINT)wcslen (buffer), flags, &menu_item->dis.rcItem, &dtto);
 (htheme, menu_item->um.hdc, &sr, &menu_item->dis.rcItem, MENU_BARITEM, state_id, flags, WND_TEXT_CLR);

	CloseThemeData (htheme);

	return TRUE;
}

ps: taked from win32-custom-menubar-aero-theme

@henrypp
Copy link
Author

henrypp commented Aug 3, 2024

now it looks like this:

sshot-001

@henrypp
Copy link
Author

henrypp commented Aug 9, 2024

any update?

@henrypp
Copy link
Author

henrypp commented Aug 31, 2024

Okay, now it looks fine, but listview header is not dark themed, how it can be done.

sshot-001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant