WEB开发网
开发学院软件开发VC QQ 静态截图完善实现之改造 CRectTracker 类 阅读

QQ 静态截图完善实现之改造 CRectTracker 类

 2007-03-17 21:58:32 来源:WEB开发网   
核心提示: // get messages until capture lost or cancelled/acceptedfor (;;){MSG msg;VERIFY(::GetMessage(&msg, NULL, 0, 0));if (CWnd::GetCapture() != pWnd)br
// get messages until capture lost or cancelled/accepted
  for (;;)
  {
    MSG msg;
    VERIFY(::GetMessage(&msg, NULL, 0, 0));
       
    if (CWnd::GetCapture() != pWnd)
      break;
        //增加的,把消息派送给窗口
    DispatchMessage(&msg);
    switch (msg.message)
    {
    // handle movement/accept messages
    case WM_LBUTTONUP:
    case WM_MOUSEMOVE:
      rectOld = m_rect;
      // handle resize cases (and part of move)
      if (px != NULL)
        *px = (int)(short)LOWORD(msg.lParam) - xDiff;
      if (py != NULL)
        *py = (int)(short)HIWORD(msg.lParam) - yDiff;
      // handle move case
      if (nHandle == hitMiddle)
      {
        m_rect.right = m_rect.left + nWidth;
        m_rect.bottom = m_rect.top + nHeight;
      }
      // allow caller to adjust the rectangle if necessary
      AdjustRect(nHandle, &m_rect);
      // only redraw and callback if the rect actually changed!
      m_bFinalErase = (msg.message == WM_LBUTTONUP);
      if (!rectOld.EqualRect(&m_rect) || m_bFinalErase)
      {
        if (bMoved)
        {
          m_bErase = TRUE;
          DrawTrackerRect(&rectOld, pWndClipTo, pDrawDC, pWnd);
        }
        OnChangedRect(rectOld);
        if (msg.message != WM_LBUTTONUP)
        {
          bMoved = TRUE;
        }
      }
      if (m_bFinalErase)
        goto ExitLoop;
      if (!rectOld.EqualRect(&m_rect))
      {
        m_bErase = FALSE;
        DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd);
      }
      break;
    // handle cancel messages
    case WM_KEYDOWN:
      if (msg.wParam != VK_ESCAPE)
        break;
    case WM_RBUTTONDOWN:
      if (bMoved)
      {
        m_bErase = m_bFinalErase = TRUE;
        //DrawTrackerRect(&m_rect, pWndClipTo, pDrawDC, pWnd);
      }
      m_rect = rectSave;
      goto ExitLoop;
    // just dispatch rest of the messages
    default:
      DispatchMessage(&msg);
      break;
    }
  }
  我们只要在GetMessage(&msg, NULL, 0, 0)之后调用DispatchMessage(&msg),就可以把消息传递到主窗口,这样,内部处理和主窗口消息两不误,进而为程序为CRectTrakcer不能响应WM_LBUTTONUP和其消息而不用大改程序了...

三、CRectTracker类的简要说明和改造类CMyTracker, CMyTracker类中增加了更改矩形颜色方法,增加StyleFlags的resizeMiddle设置中

Tags:QQ 静态 截图

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接