分类: C/C++
2008-08-01 16:52:46
CRect m_rtButtExit; //关闭按钮位置 CRect m_rtButtMax; //最大化按钮位置 CRect m_rtButtMin; //最小化按钮位置 CRect m_rtButtHelp; //帮助按钮位置 CRect m_rtIcon; //图标位置 void DrawTitleBar(CDC *pDC); //画非客户区主函数三、函数实现:
void CTitleBarDlg::DrawTitleBar(CDC *pDC) { if (m_hWnd) { CBrush Brush(RGB(0,100,255)); CBrush* pOldBrush = pDC->SelectObject(&Brush); CRect rtWnd, rtTitle, rtButtons; GetWindowRect(&rtWnd); …………………………….. //因代码过长,未贴,见源程序 ……………………………... } }//将消息进行过滤,对可能影响界面初始及更新的消息,产生重画消息执行DrawTitleBar函数
LRESULT CTitleBarDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam) { LRESULT lrst=CDialog::DefWindowProc(message, wParam, lParam); if (!::IsWindow(m_hWnd)) return lrst; if (message==WM_MOVE||message==WM_PAINT||message==WM_NCPAINT|| message== WM_NCACTIVATE ||message == WM_NOTIFY) { CDC* pWinDC = GetWindowDC(); if (pWinDC) DrawTitleBar(pWinDC); ReleaseDC(pWinDC); } return lrst; }//实现标题栏按钮的鼠标移动效果
void CTitleBarDlg::OnNcMouseMove(UINT nHitTest, CPoint point) { CDC* pDC = GetWindowDC(); if (pDC) { …………………………….. //因代码过长,未贴,见源程序 ……………………………... } ReleaseDC(pDC); CDialog::OnNcMouseMove(nHitTest, point); }//实现非客户区,用户鼠标点击操作
void CTitleBarDlg::OnNcLButtonDown(UINT nHitTest, CPoint point) { //检测各按钮是否按到 if (m_rtIcon.PtInRect(point)) AfxMessageBox("欢迎访问FlySnowStdio主页"); else if (m_rtButtHelp.PtInRect(point)) SendMessage(WM_HELP); else if (m_rtButtExit.PtInRect(point)) SendMessage(WM_CLOSE); else if (m_rtButtMin.PtInRect(point)) SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, MAKELPARAM(point.x, point.y)); else if (m_rtButtMax.PtInRect(point)) { if (IsZoomed()) SendMessage(WM_SYSCOMMAND, SC_RESTORE, MAKELPARAM(point.x, point.y)); else { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, MAKELPARAM(point.x, point.y)); Invalidate(); } } else if (!IsZoomed()) Default(); }四、总结