Skip to content

Commit

Permalink
Enable Rounded Corners for WinMerge Menu on Windows 11 (#2364) (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Jun 30, 2024
1 parent eae750d commit c3bcb45
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
41 changes: 41 additions & 0 deletions Src/Common/BCMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#include "stdafx.h" // Standard windows header file
#include "BCMenu.h" // BCMenu class declaration
#include <afxpriv.h> //SK: makes A2W and other spiffy AFX macros work
#include <../src/mfc/afximpl.h>
#include <cmath>

#pragma comment(lib, "uxtheme.lib")

Expand Down Expand Up @@ -225,6 +227,12 @@ void BCMenuData::SetWideString(const wchar_t *szWideString)
m_szMenuText=nullptr;//set to nullptr so we need not bother about dangling non-nullptr Ptrs
}

void BCMenu::DisableOwnerDraw()
{
m_bEnableOwnerDraw = false;
afxData.hbmMenuDot = reinterpret_cast<HBITMAP>(CreateRadioDotBitmap()->Detach());
}

bool BCMenu::IsMenu(HMENU submenu)
{
INT_PTR m;
Expand Down Expand Up @@ -1854,6 +1862,39 @@ int BCMenu::GlobalImageListOffset(int nID)
return existsloc;
}

CBitmap* BCMenu::CreateRadioDotBitmap()
{
const COLORREF color = GetSysColor(COLOR_MENUTEXT);
const DWORD dibcolor = (GetRValue(color) << 16) | (GetGValue(color) << 8) | GetBValue(color);
const int cxSMIcon = GetSystemMetrics(SM_CXSMICON);
const int cySMIcon = GetSystemMetrics(SM_CYSMICON);
BYTE* pBits;
BITMAPINFO bmi{ sizeof(BITMAPINFOHEADER), cxSMIcon, -cySMIcon, 1, 32, BI_RGB };
CBitmap *pBitmap = new CBitmap();
HBITMAP hBitmap = CreateDIBSection(nullptr, &bmi, DIB_RGB_COLORS, (void**)&pBits, nullptr, 0);
pBitmap->Attach(hBitmap);
CDC dcMem;
dcMem.CreateCompatibleDC(nullptr);
CBitmap* pOldBitmap = dcMem.SelectObject(pBitmap);
CRect rcDot(cxSMIcon/2-cxSMIcon/5,cySMIcon/2-cxSMIcon/5,cxSMIcon/2+cxSMIcon/5,cySMIcon/2+cySMIcon/5);
DWORD* p = reinterpret_cast<DWORD*>(pBits);
const int cx = (rcDot.left + rcDot.right ) / 2;
const int cy = (rcDot.top + rcDot.bottom) / 2;
const double r = std::sqrt((cxSMIcon / 5) * (cxSMIcon / 5));
for (int y = rcDot.top; y < rcDot.bottom; ++y)
{
for (int x = rcDot.left; x < rcDot.right; ++x)
{
const double d = std::sqrt((x - cx) * (x - cx) + (y - cy) * (y - cy));
if (d <= r)
p[x + y * cxSMIcon] = dibcolor | ((r - d >= 1.0) ? 0xff000000 : (static_cast<BYTE>(255.0 * (r - d)) << 24));

}
}
dcMem.SelectObject(pOldBitmap);
return pBitmap;
}

void BCMenu::LoadImages()
{
if (!m_bHasNotLoadedImages)
Expand Down
3 changes: 2 additions & 1 deletion Src/Common/BCMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BCMenu : public CMenu
BCMenu();
virtual ~BCMenu();

static void DisableOwnerDraw() { m_bEnableOwnerDraw = false; }
static void DisableOwnerDraw();

// Functions for loading and applying bitmaps to menus (see example application)
virtual BOOL LoadMenu(LPCTSTR lpszResourceName);
Expand Down Expand Up @@ -172,6 +172,7 @@ class BCMenu : public CMenu
void LoadImages();
inline unsigned MakeOwnerDrawFlag() const { return BCMenu::m_bEnableOwnerDraw ? MF_OWNERDRAW : MF_STRING; }
inline const tchar_t *MakeItemData(const BCMenuData* mdata) const { return m_bEnableOwnerDraw ? reinterpret_cast<const tchar_t *>(mdata) : mdata->GetWideString(); }
static CBitmap* CreateRadioDotBitmap();

// Member Variables
protected:
Expand Down

0 comments on commit c3bcb45

Please sign in to comment.