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

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

 2010-01-09 20:32:06 来源:WEB开发网   
核心提示:二、程序在调整大小和位置时,主窗口收不到消息,QQ静态截图完善实现之改造CRectTracker类(2),这是由于CRectTracker内部处处理了消息,看一下 CRectTracker::TrackHandle的MFC源码 :// get messages until capture lost or cancell

二、程序在调整大小和位置时,主窗口收不到消息,这是由于CRectTracker内部处处理了消息,看一下 CRectTracker::TrackHandle的MFC源码 :

// 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和其消 息而不用大改程序了...

Tags:QQ 静态 截图

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