Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Aug 14, 2024
1 parent e8071cc commit 9d37e04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
36 changes: 21 additions & 15 deletions Src/MenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ CMenuBar::CMenuBar()
, m_bActive(false)
, m_bMouseTracking(false)
, m_nMDIButtonDown(-1)
, m_nMDIButtonHot(-1)
, m_hwndOldFocus(nullptr)
, m_nCurrentMenuItemFlags(0)
, m_nCurrentHotItem(-1)
Expand Down Expand Up @@ -113,18 +114,18 @@ bool CMenuBar::AttachMenu(CMenu* pMenu)

void CMenuBar::DrawMDIButtons(HDC hDC)
{
const int nTypes[3] = {
DFCS_CAPTIONMIN | DFCS_FLAT | (m_nMDIButtonDown == 0 ? DFCS_PUSHED : 0),
DFCS_CAPTIONRESTORE | DFCS_FLAT | (m_nMDIButtonDown == 1 ? DFCS_PUSHED : 0),
DFCS_CAPTIONCLOSE | DFCS_FLAT | (m_nMDIButtonDown == 2 ? DFCS_PUSHED : 0)
};
int nTypes[3] = { DFCS_CAPTIONMIN | DFCS_FLAT, DFCS_CAPTIONRESTORE | DFCS_FLAT, DFCS_CAPTIONCLOSE | DFCS_FLAT };
CRect rcButtons = GetMDIButtonsRect();
const int bw = GetSystemMetrics(SM_CXSMICON);
const int w = bw + GetSystemMetrics(SM_CXBORDER) * 2;
const int h = rcButtons.Height();
CRect rc{ rcButtons.left, rcButtons.top + (h - bw) / 2, rcButtons.left + bw, rcButtons.top + (h + bw) / 2};
for (int i = 0; i < 3; ++i)
{
if (m_nMDIButtonDown == i)
nTypes[i] |= DFCS_PUSHED;
if (m_nMDIButtonHot == i)
nTypes[i] |= DFCS_HOT;
::DrawFrameControl(hDC, rc, DFC_CAPTION, nTypes[i]);
rc.left += w;
rc.right += w;
Expand Down Expand Up @@ -224,6 +225,7 @@ void CMenuBar::OnMouseMove(UINT nFlags, CPoint point)
{
CRect rcMDIButtons = GetMDIButtonsRect();
InvalidateRect(&rcMDIButtons);
m_nMDIButtonHot = rcMDIButtons.PtInRect(point) ? GetMDIButtonIndexFromPoint(point) : -1;
if (!m_bMouseTracking)
{
TRACKMOUSEEVENT tme = { sizeof TRACKMOUSEEVENT, TME_LEAVE, m_hWnd };
Expand All @@ -241,6 +243,7 @@ void CMenuBar::OnMouseLeave()
CRect rcButtons = GetMDIButtonsRect();
InvalidateRect(&rcButtons);
m_nMDIButtonDown = -1;
m_nMDIButtonHot = -1;
__super::OnMouseLeave();
}

Expand All @@ -265,17 +268,20 @@ void CMenuBar::OnLButtonUp(UINT nFlags, CPoint point)
if (pMDIFrameWnd)
{
CFrameWnd* pFrameWnd = pMDIFrameWnd->GetActiveFrame();
switch (GetMDIButtonIndexFromPoint(point))
if (pFrameWnd)
{
case 0:
pFrameWnd->ShowWindow(SW_MINIMIZE);
break;
case 1:
::SendMessage(pMDIFrameWnd->m_hWndMDIClient, WM_MDIRESTORE, (WPARAM)(pFrameWnd->m_hWnd), 0);
break;
case 2:
pFrameWnd->PostMessage(WM_CLOSE);
break;
switch (GetMDIButtonIndexFromPoint(point))
{
case 0:
pFrameWnd->ShowWindow(SW_MINIMIZE);
break;
case 1:
::SendMessage(pMDIFrameWnd->m_hWndMDIClient, WM_MDIRESTORE, (WPARAM)(pFrameWnd->m_hWnd), 0);
break;
case 2:
pFrameWnd->PostMessage(WM_CLOSE);
break;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Src/MenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class CMenuBar : public CToolBar
bool m_bMouseTracking;
bool m_bShowKeyboardCues;
int m_nMDIButtonDown;
int m_nMDIButtonHot;
HWND m_hwndOldFocus;
int m_nCurrentHotItem;
UINT m_nCurrentMenuItemFlags;
Expand Down

0 comments on commit 9d37e04

Please sign in to comment.