zoukankan      html  css  js  c++  java
  • [Programming Visual C++]Ex05cCScrollView Revisited

    1. Mouse Move
    void CEx05cView::OnMouseMove(UINT nFlags, CPoint point)
    {
        if (m_bCaptured) {
            CClientDC dc(this);
            OnPrepareDC(&dc);
            CRect rectOld(m_pointTopLeft, m_sizeEllipse);
            dc.LPtoDP(rectOld);
            InvalidateRect(rectOld, TRUE);
            m_pointTopLeft = point - m_sizeOffset;
            dc.DPtoLP(&m_pointTopLeft);
            CRect rectNew(m_pointTopLeft, m_sizeEllipse);
            dc.LPtoDP(rectNew);
            InvalidateRect(rectNew, TRUE);
        }
    }

    The OnMouseMove Coordinate Transformation Code

    As you can see, this function contains several translation statements. The logic can be summarized by the following steps:

    1. Construct the previous ellipse rectangle and convert it from logical to device coordinates.
    2. Invalidate the previous rectangle.
    3. Update the top left coordinate of the ellipse rectangle.
    4. Construct the new rectangle and convert it to device coordinates.
    5. Invalidate the new rectangle.

    The function calls InvalidateRect twice. Windows "saves up" the two invalid rectangles and computes a new invalid rectangle that is the union of the two, intersected with the client rectangle.

    2. Set Cursor Type
    void CEx05cView::OnLButtonDown(UINT nFlags, CPoint point) {
       ...
        if (circle.PtInRegion(point)) {
            // Capturing the mouse ensures subsequent LButtonUp message
            SetCapture();
            ...
            // New mouse cursor is active while mouse is captured
            ::SetCursor(::LoadCursor(NULL, IDC_CROSS));
        }
    }

    3.The SetCapture and ReleaseCapture Functions

    SetCapture is the CWnd member function that "captures" the mouse, such that mouse movement messages are sent to this window even if the mouse cursor is outside the window. An unfortunate side effect of this function is that the ellipse can be moved outside the window and "lost." A desirable and necessary effect is that all subsequent mouse messages are sent to the window, including the WM_LBUTTONUP message, which would otherwise be lost. The Win32 ReleaseCapture function turns off mouse capture.


    void CEx05cView::OnLButtonUp(UINT nFlags, CPoint point)
    {
        if (m_bCaptured) {
            ::ReleaseCapture();
            m_bCaptured = FALSE;
        }
    }

    4.The m_sizeOffset Data Member

    When OnMouseMove moves the ellipse, the relative position of the mouse within the ellipse must be the same as it was when the user first pressed the left mouse button. The m_sizeOffset object stores this original offset of the mouse from the top left corner of the ellipse rectangle.



  • 相关阅读:
    Spring REST
    Spring整合CXF,发布RSETful 风格WebService
    ZT:阿里合伙人发文:十年磨一剑,自研数据库终拿世界第一
    转载:OutOfMemoryError系列(2): GC overhead limit exceeded
    SpringBoot/SpringMVC 下载本地文件
    Eclipse中查找接口实现类快捷键
    [java]察看两个日期间差多少秒/小时/天
    MongoDB(mongodb-win32-x86_64-enterprise-windows-64-4.2.1-signed.msi)下载,启动和插入数据,查询
    简繁瘦金体下载
    方正宋刻本秀楷字体下载
  • 原文地址:https://www.cnblogs.com/huqingyu/p/201188.html
Copyright © 2011-2022 走看看