void CDittoWindow::DoNcMouseMove(CWnd *pWnd, UINT nHitTest, CPoint point) { CPoint clPoint(point); pWnd->ScreenToClient(&clPoint); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crCloseBT.PtInRect(clPoint)) { m_bMouseOverClose = true; CWindowDC dc(pWnd); DrawCloseBtn(dc, pWnd); //this->DoNcPaint(pWnd); } else if(m_bMouseOverClose) { m_bMouseOverClose = false; DoNcPaint(pWnd); } if(m_crChevronBT.PtInRect(clPoint)) { m_bMouseOverChevron = true; CWindowDC dc(pWnd); DrawChevronBtn(dc, pWnd); } else if(m_bMouseOverChevron) { m_bMouseOverChevron = false; DoNcPaint(pWnd); } if(m_crMinimizeBT.PtInRect(clPoint)) { m_bMouseOverMinimize = true; CWindowDC dc(pWnd); DrawMinimizeBtn(dc); } else if(m_bMouseOverMinimize) { m_bMouseOverMinimize = false; DoNcPaint(pWnd); } if(m_crMaximizeBT.PtInRect(clPoint)) { m_bMouseOverMaximize = true; CWindowDC dc(pWnd); DrawMaximizeBtn(dc, pWnd); } else if(m_bMouseOverMaximize) { m_bMouseOverMaximize = false; DoNcPaint(pWnd); } }
LRESULT CSkinWndHelper::OnSysCommand(WPARAM wParam, LPARAM lParam) { if (wParam != SC_CLOSE) { DoNcPaint(); } return CallWindowProc(m_oldWndProc,m_hWnd, WM_SYSCOMMAND,wParam,lParam); }
LRESULT CSkinWndHelper::OnNcLButtonUp(WPARAM wParam, LPARAM lParam) { UINT nHitTest = wParam; CPoint point(LOWORD(lParam),HIWORD(lParam)); CRect rtButton; CRect rcWindow; GetWindowRect(m_hWnd,&rcWindow); point.x -=rcWindow.left; point.y -= rcWindow.top; int iButton = TButtonHitTest(point, rtButton); if(iButton != -1) { switch(iButton) { case ID_CLOSE_BTN: { SendMessage(m_hWnd,WM_SYSCOMMAND,SC_CLOSE,0); } break; case ID_MAX_BTN: { if (IsZoomed(m_hWnd)) { SendMessage(m_hWnd,WM_SYSCOMMAND,SC_RESTORE,0); } else { SendMessage(m_hWnd,WM_SYSCOMMAND,SC_MAXIMIZE,0); } } break; case ID_MIN_BTN: { SendMessage(m_hWnd,WM_SYSCOMMAND,SC_MINIMIZE,0); } break; default: { m_TitleBtn[iButton].LButtonUp(); DoNcPaint(); } break; } } else { return CallWindowProc(m_oldWndProc,m_hWnd, WM_NCLBUTTONUP,wParam,lParam); } return 1; }
LRESULT CSkinWndHelper::OnSize(WPARAM wParam, LPARAM lParam) { LRESULT lResult = CallWindowProc(m_oldWndProc,m_hWnd, WM_SIZE,wParam,lParam); UINT nType = wParam; int cx = LOWORD(lParam); int cy = HIWORD(lParam); if (nType != SIZE_MINIMIZED && nType != SIZE_MAXHIDE ) { if (m_Rgn.m_hRgn) { m_Rgn.DeleteObject(); m_Rgn.m_hRgn = NULL; } CRect rc; GetWindowRect(m_hWnd,&rc); //获得窗口矩形 rc -= rc.TopLeft(); m_Rgn.CreateRoundRectRgn(rc.left, rc.top, rc.right+1, rc.bottom+1, 5, 5); //根据窗口矩形创建一个圆角矩形 SetWindowRgn(m_hWnd,m_Rgn, TRUE); //根据圆角矩形指定的区域改变窗口的形状 } CRect rcWnd; GetWindowRect(m_hWnd,&rcWnd); rcWnd.OffsetRect( -rcWnd.left, -rcWnd.top); if (m_bHaveMaxBox||m_bHaveMinBox) { CRect rMin(rcWnd.right - 74, 8, rcWnd.right-54, 30); m_TitleBtn[ID_MIN_BTN].SetRect(rMin); CRect rMax(rcWnd.right - 52, 8, rcWnd.right-32, 30); m_TitleBtn[ID_MAX_BTN].SetRect(rMax); } CRect rClose(rcWnd.right - 30, 8, rcWnd.right - 10, 30); m_TitleBtn[ID_CLOSE_BTN].SetRect(rClose); if (nType == SIZE_MAXIMIZED|| nType == SIZE_RESTORED) { DoNcPaint(); } return lResult; }
LRESULT CSkinWndHelper::OnNcLButtonDblClk(WPARAM wParam, LPARAM lParam) { UINT nHitTest = wParam; CPoint point(LOWORD(lParam),HIWORD(lParam)); CRect rcWindow; GetWindowRect(m_hWnd,&rcWindow); rcWindow.bottom = rcWindow.top + m_nTitleHeight; CRect rtButton; int iButton = TButtonHitTest(point, rtButton); if(iButton != -1) { m_TitleBtn[iButton].LButtonDown(); DoNcPaint(); return 1; } if (rcWindow.PtInRect(point)) { if (IsZoomed(m_hWnd)) { ShowWindow(m_hWnd,SW_RESTORE); } else { ShowWindow(m_hWnd,SW_MAXIMIZE); } DoNcPaint(); return 1; } DoNcPaint(); return 1; }
LRESULT CSkinWndHelper::OnNcMouseMove(WPARAM wParam, LPARAM lParam) { UINT nHitTest = wParam; CPoint point(LOWORD(lParam),HIWORD(lParam)); LRESULT lResult = 0; if (!m_bNCTracking) { TRACKMOUSEEVENT tme; tme.cbSize = sizeof(tme); tme.hwndTrack = m_hWnd; tme.dwFlags = TME_NONCLIENT; tme.dwHoverTime = 1; m_bNCTracking = _TrackMouseEvent(&tme); } if(nHitTest>=HTLEFT && nHitTest <= HTBOTTOMRIGHT || nHitTest == HTCAPTION) { lResult = CallWindowProc(m_oldWndProc,m_hWnd, WM_NCMOUSEMOVE,wParam,lParam); } CRect rtButton; CRect rcWindow; GetWindowRect(m_hWnd,&rcWindow); point.x -=rcWindow.left; point.y -= rcWindow.top; int iButton = TButtonHitTest(point, rtButton); if(iButton != m_iButtonHovering) { if(m_iButtonHovering != -1) { m_TitleBtn[m_iButtonHovering].MouseLeave(); m_iButtonHovering = -1; } if(iButton != -1) { m_iButtonHovering = iButton; m_TitleBtn[m_iButtonHovering].MouseHover(); } DoNcPaint(); } return lResult; }
void CDittoWindow::DoNcLButtonDown(CWnd *pWnd, UINT nHitTest, CPoint point) { CPoint clPoint(point); pWnd->ScreenToClient(&clPoint); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crCloseBT.PtInRect(clPoint)) { pWnd->SetCapture(); m_bMouseDownOnClose = true; DoNcPaint(pWnd); //CWindowDC dc(pWnd); //DrawCloseBtn(dc); } else if(m_crChevronBT.PtInRect(clPoint)) { pWnd->SetCapture(); m_bMouseDownOnChevron = true; CWindowDC dc(pWnd); DrawChevronBtn(dc, pWnd); } else if(m_crMinimizeBT.PtInRect(clPoint)) { pWnd->SetCapture(); m_bMouseDownOnMinimize = true; CWindowDC dc(pWnd); DrawMinimizeBtn(dc); } else if(m_crMaximizeBT.PtInRect(clPoint)) { pWnd->SetCapture(); m_bMouseDownOnMaximize = true; CWindowDC dc(pWnd); DrawMaximizeBtn(dc, pWnd); } else if(m_bMinimized) { //MinMaxWindow(FORCE_MAX); } }
LRESULT CSkinWndHelper::OnNcLButtonDown(WPARAM wParam, LPARAM lParam) { UINT nHitTest = wParam; CPoint point(LOWORD(lParam),HIWORD(lParam)); CPoint ptOrg = point; CRect rtButton; CRect rcWindow; GetWindowRect(m_hWnd,&rcWindow); point.x -=rcWindow.left; point.y -= rcWindow.top; int iButton = TButtonHitTest(point, rtButton); if(iButton != -1) { m_TitleBtn[iButton].LButtonDown(); DoNcPaint(); return 1; } if(m_rcIcon.PtInRect(point)) { HMENU hSysMenu = GetSystemMenu(m_hWnd,FALSE); if (hSysMenu) { TrackPopupMenu(hSysMenu,TPM_LEFTALIGN, ptOrg.x, ptOrg.y,0,m_hWnd, NULL); } return 1; } else if(nHitTest >= HTLEFT && nHitTest <= HTBOTTOMRIGHT || nHitTest == HTCAPTION) { return CallWindowProc(m_oldWndProc,m_hWnd, WM_NCLBUTTONDOWN,wParam,lParam); } return CallWindowProc(m_oldWndProc,m_hWnd, WM_NCLBUTTONDOWN,wParam,lParam); }
LRESULT CCtrlMessageBar::DoWindowProc(UINT message, WPARAM wParam, LPARAM lParam, LRESULT lResult) { // respond to our special message to get the message bar height if (message == s_nMsgGetMessageBarHeight) return m_nMessageBarHeight; if (m_tipMessageBar.m_hWnd != NULL && ::IsWindow(m_tipMessageBar.m_hWnd)) { MSG msg; ZeroMemory(&msg, sizeof(MSG)); msg.hwnd = m_pCtrlMessageBarThis->m_hWnd; msg.lParam = lParam; msg.message = message; msg.wParam = wParam; m_tipMessageBar.RelayEvent(&msg); } switch (message) { case WM_CREATE: if (::IsWindow(m_pCtrlMessageBarThis->m_hWnd)) m_tipMessageBar.Create(m_pCtrlMessageBarThis); break; case WM_NCLBUTTONDOWN: case WM_NCMBUTTONDOWN: case WM_NCRBUTTONDOWN: case WM_NCLBUTTONUP: case WM_NCMBUTTONUP: case WM_NCRBUTTONUP: case WM_NCLBUTTONDBLCLK: case WM_NCMBUTTONDBLCLK: case WM_NCRBUTTONDBLCLK: DoNcMouseButtonMsg(message, (UINT)wParam, CPoint(lParam)); break; case WM_NCCALCSIZE: { // If the window is a CListCtrl, then we need to intercept the // HDM_LAYOUT message that it sends to its header so that we can // adjust the layout, so subclass its header. // The header may already be subclassed, so we need to use a double- // subclassing technique to make sure we don't break its existing subclassing CListCtrl* pListCtrl = DYNAMIC_DOWNCAST(CListCtrl, m_pCtrlMessageBarThis); if (pListCtrl != NULL && pListCtrl->m_hWnd != NULL && ! CCtrlMessageBarDblSubclassWnd::IsSubclassed(pListCtrl->m_hWnd)) CCtrlMessageBarDblSubclassWnd::SubclassWindow(::GetDlgItem(pListCtrl->m_hWnd, 0)); } DoNcCalcSize((BOOL)wParam, (NCCALCSIZE_PARAMS*)lParam); break; case WM_NCHITTEST: return (LRESULT)DoNcHitTest(CPoint(lParam), (UINT)lResult); break; case WM_NCPAINT: DoNcPaint(); break; case WM_SIZE: m_pCtrlMessageBarThis->SetWindowPos(NULL, 0, 0, 0, 0, s_dwSWPFlags); break; case WM_VSCROLL: if (m_bShowMessageBar && m_pCtrlMessageBarThis->IsKindOf(RUNTIME_CLASS(CListCtrl))) { // ListView controls base their client areas on the window size, and // so using WM_NCCALCSIZE to resize the client causes the scrolling // to go wrong. There doesn't seem to be any way of influencing this, // so the best we can do is to fiddle the scrolling to behave the // way it should be. This, however, still isn't perfect and the // window scrolls back up a little after scrolling to the very bottom. CListCtrl* pList = (CListCtrl*)m_pCtrlMessageBarThis; UINT nStyle = pList->GetStyle() & LVS_TYPEMASK; if (nStyle == LVS_ICON || nStyle == LVS_SMALLICON) { SCROLLINFO si = { sizeof(si), SIF_RANGE }; pList->GetScrollInfo(SB_VERT, &si); CRect rcView; pList->GetViewRect(&rcView); si.nMax = rcView.Height() + m_nMessageBarHeight; pList->SetScrollInfo(SB_VERT, &si); } } break; case WM_NCMOUSEMOVE: case WM_NCMOUSELEAVE: case WM_MOUSELEAVE: // if we're over the bar, then set the bar to draw highlighted if (m_bHighlightOnMouseOver) { if (message == WM_NCMOUSEMOVE) { // make sure we get leave TRACKMOUSEEVENT tme; tme.cbSize = sizeof(TRACKMOUSEEVENT); tme.dwFlags = TME_LEAVE | TME_NONCLIENT; tme.dwHoverTime = HOVER_DEFAULT; tme.hwndTrack = m_pCtrlMessageBarThis->m_hWnd; TrackMouseEvent(&tme); } BOOL bOldMouseOver = m_bMouseHover; if (message == WM_NCMOUSEMOVE && DoNcHitTest(CPoint(lParam), (UINT)lResult) == HTMESSAGEBAR) m_bMouseHover = TRUE; else m_bMouseHover = FALSE; if (m_bMouseHover != bOldMouseOver) m_pCtrlMessageBarThis->SetWindowPos(NULL, 0, 0, 0, 0, s_dwSWPFlags); } break; } return lResult; }
LRESULT CSkinWndHelper::OnActivate(WPARAM wParam, LPARAM lParam) { LRESULT lResult= CallWindowProc(m_oldWndProc,m_hWnd, WM_ACTIVATE,wParam,lParam); DoNcPaint(); return lResult; }
LRESULT CSkinWndHelper::OnNcPaint(WPARAM wParam, LPARAM lParam) { //LRESULT lResult = CallWindowProc(m_oldWndProc,m_hWnd, WM_NCPAINT,wParam,lParam); DoNcPaint(); return 0; }
long CDittoWindow::DoNcLButtonUp(CWnd *pWnd, UINT nHitTest, CPoint point) { long lRet = 0; if(m_bMouseDownOnClose) { ReleaseCapture(); m_bMouseDownOnClose = false; m_bMouseOverClose = false; DoNcPaint(pWnd); CPoint clPoint(point); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crCloseBT.PtInRect(clPoint)) { if(m_sendWMClose) { pWnd->SendMessage(WM_CLOSE, 0, 0); } lRet = BUTTON_CLOSE; } } else if(m_bMouseDownOnChevron) { ReleaseCapture(); m_bMouseDownOnChevron = false; m_bMouseOverChevron = false; DoNcPaint(pWnd); CPoint clPoint(point); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crChevronBT.PtInRect(clPoint)) { lRet = BUTTON_CHEVRON; } } else if(m_bMouseDownOnMinimize) { ReleaseCapture(); m_bMouseDownOnMinimize = false; m_bMouseOverMinimize = false; DoNcPaint(pWnd); CPoint clPoint(point); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crMinimizeBT.PtInRect(clPoint)) { pWnd->ShowWindow(SW_MINIMIZE); lRet = BUTTON_MINIMIZE; } } else if(m_bMouseDownOnMaximize) { ReleaseCapture(); m_bMouseDownOnMaximize = false; m_bMouseOverMaximize = false; DoNcPaint(pWnd); CPoint clPoint(point); clPoint.x += m_lLeftBorder; clPoint.y += m_lTopBorder; if(m_crMaximizeBT.PtInRect(clPoint)) { if(pWnd->GetStyle() & WS_MAXIMIZE) pWnd->ShowWindow(SW_RESTORE); else pWnd->ShowWindow(SW_SHOWMAXIMIZED); lRet = BUTTON_MAXIMIZE; } } return lRet; }
//***************************************************************************** void CBCGPCaptionBar::OnNcPaint() { CWindowDC dcWin(this); DoNcPaint(&dcWin); }