📄 winmini.cpp
字号:
{
Default();
return;
}
ClientToScreen(&pt);
if (GetCapture() != this)
{
m_bSysTracking = FALSE;
SendMessage(WM_NCPAINT);
}
else if ((OnNcHitTest(pt) == HTSYSMENU) != m_bInSys)
{
m_bInSys = !m_bInSys;
InvertSysMenu();
}
}
void CMiniFrameWnd::OnLButtonUp(UINT /*nFlags*/, CPoint pt)
{
if (!m_bSysTracking)
{
Default();
return;
}
ReleaseCapture();
m_bSysTracking = FALSE;
ClientToScreen(&pt);
if (OnNcHitTest(pt) == HTSYSMENU)
{
InvertSysMenu();
SendMessage(WM_CLOSE);
}
}
void CMiniFrameWnd::InvertSysMenu()
{
CSize sizeBorder(GetSystemMetrics(SM_CXBORDER),
GetSystemMetrics(SM_CYBORDER));
CSize sizeFrame(GetSystemMetrics(SM_CXFRAME),
GetSystemMetrics(SM_CYFRAME));
CRect rect(sizeBorder.cx, sizeBorder.cy,
_afx_sizeMiniSys.cx - sizeBorder.cx, _afx_sizeMiniSys.cy);
if (GetStyle() & (MFS_4THICKFRAME | MFS_THICKFRAME | WS_THICKFRAME))
rect.OffsetRect(sizeFrame.cx - sizeBorder.cx, sizeFrame.cy - sizeBorder.cy);
CDC* pDC = GetWindowDC();
pDC->InvertRect(rect);
ReleaseDC(pDC);
}
// _AfxDrawFrame: [static]
// Draws a frame in a given brush, with a given width for the lines.
// Works like the doors to a cabinet: two tall stiles up and down the sides
// and two short spacers across the top and bottom. The thickness of the
// lines are painted inside the rectangle.
//
AFX_STATIC void AFXAPI
_AfxDrawFrame(CDC* dc, LPCRECT lpRect, int nWidth, int nHeight, CBrush& br)
{
CRect rect;
// left stile
rect = *lpRect;
rect.right = rect.left + nWidth;
dc->FillRect(rect, &br);
// right stile
rect.right = lpRect->right;
rect.left = rect.right - nWidth;
dc->FillRect(rect, &br);
// top spacer
rect = *lpRect;
rect.bottom = rect.top + nHeight;
rect.left += nWidth;
rect.right -= nWidth;
dc->FillRect(rect, &br);
// bottom spacer
rect.bottom = lpRect->bottom;
rect.top = rect.bottom - nHeight;
dc->FillRect(rect, &br);
}
void CMiniFrameWnd::OnNcPaint()
{
if (afxData.bSmCaption)
{
Default();
return;
}
// Prepare for drawing the non-client area of the mini frame
CWindowDC dc(this);
CRect rect, rectCaption;
LONG dwStyle = GetStyle();
GetWindowRect(&rect);
rect.OffsetRect(-rect.left, -rect.top);
// Create brushes we might need.
CBrush brFrame;
brFrame.CreateSolidBrush(::GetSysColor(COLOR_WINDOWFRAME));
CBrush brBorder;
brBorder.CreateSolidBrush(::GetSysColor(m_bActive ?
COLOR_ACTIVEBORDER : COLOR_INACTIVEBORDER));
CBrush brCaption;
brCaption.CreateSolidBrush(::GetSysColor(m_bActive ?
COLOR_ACTIVECAPTION : COLOR_INACTIVECAPTION));
CSize sizeBorder(GetSystemMetrics(SM_CXBORDER),
GetSystemMetrics(SM_CYBORDER));
CSize sizeFrame(GetSystemMetrics(SM_CXFRAME),
GetSystemMetrics(SM_CYFRAME));
// Draw the thickframe. Remove it from the rect.
if (dwStyle & (MFS_4THICKFRAME | WS_THICKFRAME | MFS_THICKFRAME))
{
_AfxDrawFrame(&dc, rect, sizeBorder.cx, sizeBorder.cy, brFrame);
rect.InflateRect(-sizeBorder.cx, -sizeBorder.cy);
_AfxDrawFrame(&dc, rect, sizeFrame.cx - sizeBorder.cx,
sizeFrame.cy - sizeBorder.cy, brBorder);
CSize sizeTick(sizeFrame.cx - sizeBorder.cx * 2,
sizeFrame.cy - sizeBorder.cy * 2);
if (!(dwStyle & MFS_4THICKFRAME))
{
CSize sizeOffset(sizeFrame.cx + _afx_sizeMiniSys.cx - sizeBorder.cx * 3,
sizeFrame.cy + _afx_sizeMiniSys.cy - sizeBorder.cy * 2);
dc.FillSolidRect(rect.left, rect.top + sizeOffset.cy,
sizeTick.cx, 1, RGB(0, 0, 0));
dc.FillSolidRect(rect.left, rect.bottom - sizeOffset.cy,
sizeTick.cx, 1, RGB(0, 0, 0));
dc.FillSolidRect(rect.right - sizeTick.cx,
rect.top + sizeOffset.cy, sizeTick.cx, 1, RGB(0, 0, 0));
dc.FillSolidRect(rect.right - sizeTick.cx,
rect.bottom - sizeOffset.cy, sizeTick.cx, 1, RGB(0, 0, 0));
dc.FillSolidRect(rect.left + sizeOffset.cx, rect.top,
1, sizeTick.cy, RGB(0, 0, 0));
dc.FillSolidRect(rect.right - sizeOffset.cx, rect.top,
1, sizeTick.cy, RGB(0, 0, 0));
dc.FillSolidRect(rect.left + sizeOffset.cx,
rect.bottom - sizeTick.cy, 1, sizeTick.cy, RGB(0, 0, 0));
dc.FillSolidRect(rect.right - sizeOffset.cx,
rect.bottom - sizeTick.cy, 1, sizeTick.cy, RGB(0, 0, 0));
}
rect.InflateRect(-sizeTick.cx, -sizeTick.cy);
}
// Draw the caption. Remove it from rect.
if (dwStyle & WS_CAPTION)
{
rectCaption = rect;
rectCaption.bottom = rectCaption.top + _afx_sizeMiniSys.cy + sizeBorder.cy;
_AfxDrawFrame(&dc, rectCaption, sizeBorder.cx, sizeBorder.cy, brFrame);
rectCaption.InflateRect(-sizeBorder.cx, -sizeBorder.cy);
dc.FillRect(&rectCaption, &brCaption);
// Draw the border around the client area.
// At this point, rc==rcClient.InflateRect(cxBorder, cyBorder).
//
_AfxDrawFrame(&dc, rect, sizeBorder.cx, sizeBorder.cy, brFrame);
if (_afx_hfontMiniSys != NULL)
{
HFONT hFontOld = (HFONT)dc.SelectObject(_afx_hfontMiniSys);
CString strTitle;
GetWindowText(strTitle);
int xLeft = rectCaption.left +
(dwStyle & WS_SYSMENU ? _afx_sizeMiniSys.cx : 0);
CSize sizeText = dc.GetTextExtent(strTitle, strTitle.GetLength());
if (sizeText.cx <= rectCaption.Width())
{
dc.SetTextAlign(TA_CENTER);
xLeft += (rectCaption.right - xLeft) / 2;
}
TEXTMETRIC tm;
VERIFY(dc.GetTextMetrics(&tm));
int yHeight = tm.tmAscent + tm.tmDescent + tm.tmInternalLeading;
rectCaption.InflateRect(0, 1);
int yHeightDiff = (rectCaption.Height() - yHeight + 1) / 2;
dc.SetTextColor(::GetSysColor(m_bActive ?
COLOR_CAPTIONTEXT : COLOR_INACTIVECAPTIONTEXT));
dc.SetBkMode(TRANSPARENT);
dc.ExtTextOut(xLeft, rectCaption.top + yHeightDiff, ETO_CLIPPED,
rectCaption, strTitle, strTitle.GetLength(), NULL);
dc.SelectObject(hFontOld);
}
// Draw the system menu.
if (dwStyle & WS_SYSMENU)
{
CDC dcBitmap;
HBITMAP hBitmapOld;
if (!dcBitmap.CreateCompatibleDC(&dc))
return;
hBitmapOld = (HBITMAP)dcBitmap.SelectObject(_afx_hbmMiniSys);
dc.BitBlt(rect.left, rect.top, _afx_sizeMiniSys.cx, _afx_sizeMiniSys.cy,
&dcBitmap, 0, 0, SRCCOPY);
dcBitmap.SelectObject(hBitmapOld);
}
rect.top = rectCaption.bottom;
}
else
{
// Draw the border around the client area.
// At this point, rect == rcClient.InflateRect(cxBorder, cyBorder).
_AfxDrawFrame(&dc, rect, sizeBorder.cx, sizeBorder.cy, brFrame);
}
}
void CMiniFrameWnd::OnSysCommand(UINT nID, LPARAM lParam)
{
DWORD dwStyle = GetStyle();
if ((dwStyle & WS_POPUP) &&
((nID & 0xFFF0) != SC_CLOSE ||
(GetKeyState(VK_F4) < 0 && GetKeyState(VK_MENU) < 0 &&
(dwStyle & MFS_SYNCACTIVE))))
{
if (HandleFloatingSysCommand(nID, lParam))
return;
}
CFrameWnd::OnSysCommand(nID, lParam);
}
void CMiniFrameWnd::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
{
if (afxData.bSmCaption)
{
CFrameWnd::CalcWindowRect(lpClientRect, nAdjustType);
return;
}
LONG dwStyle = GetStyle();
if (dwStyle & (MFS_4THICKFRAME | WS_THICKFRAME | MFS_THICKFRAME))
{
::InflateRect(lpClientRect,
GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME));
}
else
{
::InflateRect(lpClientRect,
GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
}
if (dwStyle & WS_CAPTION)
lpClientRect->top -= _afx_sizeMiniSys.cy;
}
void PASCAL CMiniFrameWnd::CalcBorders(
LPRECT lpClientRect, DWORD dwStyle, DWORD dwExStyle)
{
UNUSED_ALWAYS(dwExStyle);
if (afxData.bSmCaption)
{
AdjustWindowRectEx(lpClientRect, dwStyle, FALSE, WS_EX_PALETTEWINDOW);
return;
}
if (dwStyle & (MFS_4THICKFRAME | WS_THICKFRAME | MFS_THICKFRAME))
{
::InflateRect(lpClientRect,
GetSystemMetrics(SM_CXFRAME), GetSystemMetrics(SM_CYFRAME));
}
else
{
::InflateRect(lpClientRect,
GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
}
if (dwStyle & WS_CAPTION)
{
Initialize();
lpClientRect->top -= _afx_sizeMiniSys.cy;
}
}
LRESULT CMiniFrameWnd::OnGetText(WPARAM wParam, LPARAM lParam)
{
if (afxData.bSmCaption)
return Default();
lstrcpyn((LPTSTR)lParam, (LPCTSTR)m_strCaption, wParam);
if ((int)wParam > m_strCaption.GetLength())
wParam = m_strCaption.GetLength();
return wParam;
}
LRESULT CMiniFrameWnd::OnGetTextLength(WPARAM, LPARAM)
{
if (afxData.bSmCaption)
return Default();
return m_strCaption.GetLength();
}
// CMiniFrameWnd::OnSetText
// Windows will repaint just the caption, as a thick caption, if
// we don't override WM_SETTEXT. NOTE: Unfortunately, this will never
// get called if you do a SetWindowText() on this window from another
// task. Use SendMessage instead.
LRESULT CMiniFrameWnd::OnSetText(WPARAM, LPARAM lParam)
{
if (afxData.bSmCaption)
return Default();
TRY
{
if (lParam == NULL)
{
// NULL lParam means set caption to nothing
m_strCaption.Empty();
}
else
{
// non-NULL sets caption to that specified by lParam
lstrcpy(m_strCaption.GetBufferSetLength(lstrlen((LPCTSTR)lParam)),
(LPCTSTR)lParam);
}
SendMessage(WM_NCPAINT);
}
CATCH_ALL(e)
{
// Note: DELETE_EXCEPTION(e) not required
return FALSE;
}
END_CATCH_ALL
return TRUE;
}
LRESULT CMiniFrameWnd::OnFloatStatus(WPARAM wParam, LPARAM)
{
// these asserts make sure no conflicting actions are requested
ASSERT(!((wParam & FS_SHOW) && (wParam & FS_HIDE)));
ASSERT(!((wParam & FS_ENABLE) && (wParam & FS_DISABLE)));
ASSERT(!((wParam & FS_ACTIVATE) && (wParam & FS_DEACTIVATE)));
// FS_SYNCACTIVE is used to detect MFS_SYNCACTIVE windows
LRESULT lResult = 0;
if ((GetStyle() & MFS_SYNCACTIVE) && (wParam & FS_SYNCACTIVE))
lResult = 1;
if (wParam & (FS_SHOW|FS_HIDE))
{
SetWindowPos(NULL, 0, 0, 0, 0,
((wParam & FS_SHOW) ? SWP_SHOWWINDOW : SWP_HIDEWINDOW) | SWP_NOZORDER |
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
}
if (wParam & (FS_ENABLE|FS_DISABLE))
EnableWindow((wParam & FS_ENABLE) != 0);
if ((wParam & (FS_ACTIVATE|FS_DEACTIVATE)) &&
GetStyle() & MFS_SYNCACTIVE)
{
ModifyStyle(MFS_SYNCACTIVE, 0);
SendMessage(WM_NCACTIVATE, (wParam & FS_ACTIVATE) != 0);
ModifyStyle(0, MFS_SYNCACTIVE);
}
return lResult;
}
LRESULT CMiniFrameWnd::OnQueryCenterWnd(WPARAM, LPARAM)
{
// forward WM_QUERYCENTERWND to parent window
HWND hWndParent = ::GetParent(m_hWnd);
LRESULT lResult = ::SendMessage(hWndParent, WM_QUERYCENTERWND, 0, 0);
if (lResult == 0)
lResult = (LRESULT)hWndParent;
return lResult;
}
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
IMPLEMENT_DYNCREATE(CMiniFrameWnd, CFrameWnd)
////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -