Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 10, 2024
1 parent c82b15f commit a4b4150
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 43 deletions.
14 changes: 12 additions & 2 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
ON_WM_ACTIVATEAPP()
ON_WM_NCCALCSIZE()
ON_WM_NCHITTEST()
ON_WM_NCLBUTTONDOWN()
ON_WM_NCLBUTTONUP()
ON_WM_SIZE()
ON_WM_PAINT()
ON_UPDATE_COMMAND_UI_RANGE(CMenuBar::FIRST_MENUID, CMenuBar::FIRST_MENUID + 10, OnUpdateMenuBarMenuItem)
Expand Down Expand Up @@ -2510,14 +2512,22 @@ LRESULT CMainFrame::OnNcHitTest(CPoint point)
return __super::OnNcHitTest(point);
}

void CMainFrame::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
__super::OnNcLButtonDown(nHitTest, point);
}

void CMainFrame::OnNcLButtonUp(UINT nFlags, CPoint point)
{
__super::OnNcLButtonUp(nFlags, point);
}

void CMainFrame::OnPaint()
{
__super::OnPaint();
CRect rcClient;
GetClientRect(&rcClient);
CClientDC dc(this);
CRect rc = { rcClient.left, rcClient.top, rcClient.right, rcClient.top + 32 };
dc.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));
m_titleBar.DrawIcon(this, dc);
const int bw = 64;
CRect rc1{ rcClient.right - bw, 0, rcClient.right, bw };
Expand Down
2 changes: 2 additions & 0 deletions Src/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ class CMainFrame : public CMDIFrameWnd
afx_msg void OnSaveProject();
afx_msg void OnActivateApp(BOOL bActive, DWORD dwThreadID);
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
afx_msg void OnNcLButtonUp(UINT nHitTest, CPoint point);
afx_msg void OnPaint();
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg void OnSize(UINT nType, int cx, int cy);
Expand Down
95 changes: 54 additions & 41 deletions Src/TitleBarHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ void CTitleBarHelper::DrawIcon(CWnd* pWnd, CDC& dc)
hIcon = (HICON)GetClassLongPtr(pWnd->m_hWnd, GCLP_HICONSM);
if (hIcon != nullptr)
{
DrawIconEx(dc.m_hDC, 8, 8 + (m_nType == SIZE_MAXIMIZED ? 8 : 0), hIcon, 16, 16, 0, nullptr, DI_NORMAL);
const int height = PointToPixel(28.5f);
const int leftMarginWidth = PointToPixel(36.f);
const int cx = PointToPixel(12.f);
const int cy = PointToPixel(12.f);
const int my = (m_nType == SIZE_MAXIMIZED ? 8 : 0);
CRect rc = { 0, 0, leftMarginWidth, height + my };
dc.FillSolidRect(&rc, GetSysColor(COLOR_3DFACE));
DrawIconEx(dc.m_hDC, (leftMarginWidth - cx) / 2, (height - cy) / 2 + my, hIcon,
cx, cy, 0, nullptr, DI_NORMAL);
}
}

Expand All @@ -40,58 +48,63 @@ void CTitleBarHelper::OnSize(CWnd* pWnd, UINT nType, int cx, int cy)
m_size = CSize(cx, cy);
m_nType = nType;
m_pWnd = pWnd;
CClientDC dc(pWnd);
m_dpi = dc.GetDeviceCaps(LOGPIXELSX);
}

int CTitleBarHelper::HitTest(CPoint pt)
{
if (!m_pWnd)
return HTNOWHERE;
CClientDC dc(m_pWnd);
const int lpx = dc.GetDeviceCaps(LOGPIXELSX);
auto pointToPixel = [lpx](int point) { return MulDiv(point, lpx, 72); };
const int height = pointToPixel(24);
const int buttonWidth = pointToPixel(24);
const int height = PointToPixel(24);
const int buttonWidth = PointToPixel(24);
CRect rc;
const int bw = buttonWidth;
const int m = 8;
m_pWnd->GetWindowRect(&rc);
if (pt.y < rc.top + height)
if (pt.y < rc.top + 4)
{
if (pt.x < rc.left + m)
return HTTOPLEFT;
else if (rc.right - m <= pt.x)
return HTTOPRIGHT;
return HTTOP;
}
if (rc.bottom - m <= pt.y)
{
const int bw = buttonWidth;
const int m = 4;
if (pt.y < rc.top + 4)
{
if (pt.x < rc.left + m)
return HTTOPLEFT;
else if (rc.right - m <= pt.x)
return HTTOPRIGHT;
return HTTOP;
}
if (rc.bottom - m <= pt.y)
{
if (pt.x < rc.left + m)
return HTBOTTOMLEFT;
else if (rc.right - m <= pt.x)
return HTBOTTOMRIGHT;
return HTBOTTOM;
}
if (pt.x < rc.left + m)
return HTLEFT;
if (rc.right - m <= pt.x)
return HTRIGHT;
if (pt.x < rc.left + bw)
return HTSYSMENU;
if (rc.right - bw * 3 <= pt.x && pt.x < rc.right - bw * 2)
{
return HTMINBUTTON;
}
else if (rc.right - bw * 2 <= pt.x && pt.x < rc.right - bw)
{
return HTMAXBUTTON;
}
else if (rc.right - bw <= pt.x && pt.x < rc.right)
{
return HTCLOSE;
}
return HTBOTTOMLEFT;
else if (rc.right - m <= pt.x)
return HTBOTTOMRIGHT;
return HTBOTTOM;
}
if (pt.x < rc.left + m)
return HTLEFT;
if (rc.right - m <= pt.x)
return HTRIGHT;
if (pt.x < rc.left + bw)
return HTSYSMENU;
if (rc.right - bw * 3 <= pt.x && pt.x < rc.right - bw * 2)
{
return HTMINBUTTON;
}
else if (rc.right - bw * 2 <= pt.x && pt.x < rc.right - bw)
{
return HTMAXBUTTON;
}
else if (rc.right - bw <= pt.x && pt.x < rc.right)
{
return HTCLOSE;
}
if (pt.y < rc.top + height)
{
return HTCAPTION;
}
return HTCLIENT;
}

int CTitleBarHelper::PointToPixel(float point)
{
return static_cast<int>(point * m_dpi / 72.f);
};
3 changes: 3 additions & 0 deletions Src/TitleBarHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ class CTitleBarHelper {
int HitTest(CPoint pt);

private:
int PointToPixel(float point);

CWnd* m_pWnd;
CSize m_size;
int m_nType;
int m_iconSize;
int m_dpi;
};

0 comments on commit a4b4150

Please sign in to comment.