コード例 #1
0
ファイル: DlgMovedBase.cpp プロジェクト: tianyx/TxUIProject
void CDlgMovedBase::DrawDragRect( CRect* pRcBefore, CRect* pRcAfter , int nMode /*= 1*/)
{
	//CPaintDC dc(GetDesktopWindow()); //this will failed, why
	CSize szBefor(2,2);
	CSize szAfter(2,2);
	if (nMode == 2)
	{
		szAfter = CSize(0,0);
	}
	else if (nMode == 0)
	{
		szBefor = CSize(0,0);
	}

	CDC *pDC = GetDesktopWindow()->GetWindowDC();
	ASSERT(pDC != NULL);
	pDC->DrawDragRect(pRcAfter, szAfter, pRcBefore,szBefor );
	GetDesktopWindow()->ReleaseDC(pDC);
}
コード例 #2
0
	LRESULT CNormalsChartsCtrl::DrawDragLine(const CPoint& oldPt, const CPoint& newPt, int w)
	{
		// Draw last rect, but no new one (erase old rect)
		CDC *cdc = GetDC();

		static const CRect RECT_NULL = CRect(0, 0, 0, 0);

		CRect rectRange;
		GetClientRect(&rectRange);
		CRect oldRect(oldPt.x - w, rectRange.top, oldPt.x + w, rectRange.bottom);
		CRect newRect(newPt.x - w, rectRange.top, newPt.x + w, rectRange.bottom);
		bool bOldValid = oldPt.x >= 0 && oldPt.y >= 0;
		bool bNewValid = newPt.x >= 0 && newPt.y >= 0;

		cdc->DrawDragRect(bNewValid ? newRect : RECT_NULL, CSize(w, w), bOldValid ? oldRect : RECT_NULL, CSize(w, w));

		ReleaseDC(cdc);

		return TRUE;
	}
コード例 #3
0
void CySplitterWnd::OnLButtonDown(UINT /*nFlags*/, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default

	// don't handle if capture already set
	if (::GetCapture() != NULL) return;

    // don't handle if no room to drag
    RECT rectMouseClip;
    if (!GetMouseClipRect(&rectMouseClip, point)) return;
    ::ClipCursor(&rectMouseClip);

	// set capture to the window which received this message
	SetCapture();
	ASSERT(this == CWnd::GetCapture());

    // get DC for drawing
	CDC* pDrawDC;
    pDrawDC = m_Parent->GetDC();
	ASSERT_VALID(pDrawDC);

    int     curX, curY;
	int     xDiff, yDiff;
	CRect   rectOrg, rectCur, rectOld;
    CSize   sizeBar;

    GetWindowRect(rectOrg);
    sizeBar = CSize(rectOrg.Width(), rectOrg.Height());

    m_Parent->ScreenToClient(rectOrg);
    pDrawDC->DrawDragRect(&rectOrg, sizeBar, NULL, sizeBar);
    rectOld = rectCur = rectOrg;
    xDiff = yDiff = 0;

	// get messages until capture lost or cancelled/accepted
	for (;;) {
		MSG msg;
		VERIFY(::GetMessage(&msg, NULL, 0, 0));

		if (CWnd::GetCapture() != this)
			break;

		switch (msg.message) {
		// handle movement/accept messages
		case WM_MOUSEMOVE:
			// handle resize cases (and part of move)
            curX = (int)(short)LOWORD(msg.lParam);
            curY = (int)(short)HIWORD(msg.lParam);

            xDiff = curX - point.x;
            yDiff = curY - point.y;

            rectCur = rectOrg;
            rectCur.top += yDiff;
            rectCur.bottom += yDiff;
            pDrawDC->DrawDragRect(&rectCur, sizeBar, &rectOld, sizeBar);
            rectOld = rectCur;

            break;

		// handle cancel messages
		case WM_KEYDOWN:
			if (msg.wParam != VK_ESCAPE)
				break;
		case WM_LBUTTONUP:
		case WM_RBUTTONDOWN:
            goto ExitLoop;

		// just dispatch rest of the messages
		default:
			DispatchMessage(&msg);
			break;
		}
	}

ExitLoop:
    pDrawDC->DrawDragRect(&rectCur, sizeBar, NULL, sizeBar);

    m_Parent->ReleaseDC(pDrawDC);
    ReleaseCapture();
    ::ClipCursor(NULL);

    if (yDiff == 0) return;

    // move the splitter bar & re-position the attached panes if necessary
    MoveWindow(rectCur, FALSE);
    RecalcLayout();

	m_Parent->SendMessage(WM_SPLITTER_MOVED, yDiff, GetDlgCtrlID());

    //CWnd::OnLButtonDown(nFlags, point);
}