1,在重绘函数中加载关闭按钮图片,
2,给MainFrame增加单击事件,在单击响应中判断是否点击的关闭按钮
//如果点击关闭按钮,关闭软件
void CMainFrame::OnNcLButtonUp(UINT nHitTest, CPoint point){
// TODO: Add your message handler code here and/or call default
POINT pt;
//分别用于保存窗口位置、按钮位置、框架位置和标题栏位置的临时变量
CRect rtWnd,rtButtons,rtTitle;
//获取窗口位置
GetWindowRect(&rtWnd);
//获取标题栏位置
rtTitle.top = GetSystemMetrics(SM_CYFRAME);
rtTitle.left = GetSystemMetrics(SM_CXFRAME);
rtTitle.bottom = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYSIZE);
rtTitle.right = rtWnd.Width()-GetSystemMetrics(SM_CXFRAME);
CBitmap *pBitmap = new CBitmap;
BITMAP bm;
//获取重绘关闭按钮
pBitmap->LoadBitmap(IDB_EXIT_GRAY);
pBitmap->GetBitmap(&bm);
//pDisplayMemDC->SelectObject(pBitmap);
//获取关闭按钮位置
rtButtons.left=rtTitle.right-bm.bmWidth-5;
rtButtons.top=GetSystemMetrics(SM_CYFRAME)+(rtTitle.Height()-bm.bmHeight)/2;
rtButtons.right=rtButtons.left+bm.bmWidth;
rtButtons.bottom=rtButtons.top+bm.bmHeight;
pt.x = point.x;
pt.y = point.y;
if (PtInRect(&rtButtons, pt))
{
//int a = 10;
//::SendMessage(AfxGetMainWnd()->m_hWnd,WM_CLOSE,0,0);//最常用
::PostMessage(AfxGetMainWnd()->m_hWnd,WM_CLOSE,0,0);//最常用
}
CFrameWndEx::OnNcLButtonUp(nHitTest, point);
}