请问怎样才能用一个Button控件被按下时,些时按住MOUSE左键在屏幕上移动,可以取得
RGB值.也就是MOUSE移出了本程序窗口,程序还能得到MOUSE的消息.

解决方案 »

  1.   

    CPoint point;
    CString str;
    COLORREF clr;
    DWORD dw;while(1)
    {
        HDC hDC = ::GetDC(0);
    GetCursorPos(&point);
    dw = MAKELONG(point.x,point.y);
    str.Format("X=%d Y=%d DWORD=%d",point.x,point.y,dw);
    pDlg->GetDlgItem(IDC_STATIC1)->SetWindowText(str); //在窗口中显示当前坐标    CString ClrText="",text="";
    clr = ::GetPixel(hDC,point.x,point.y); ClrText.Format("R=%d G=%d B=%d",GetRValue(clr),GetGValue(clr),GetBValue(clr));
    pDlg->GetDlgItem(IDC_STATIC2)->SetWindowText(ClrText); //在窗口中显示RGB值
    }
      

  2.   

    CWnd::SetCapture
    CWnd* SetCapture( );Return ValueA pointer to the window object that previously received all mouse input. It is NULL if there is no such window. The returned pointer may be temporary and should not be stored for later use.ResCauses all subsequent mouse input to be sent to the current CWnd object regardless of the position of the cursor. 
      

  3.   

    差点忘了 解除的代码
    ReleaseCapture
    The ReleaseCapture function releases the mouse capture from a window in the current thread and restores normal mouse input processing. A window that has captured the mouse receives all mouse input, regardless of the position of the cursor, except when a mouse button is clicked while the cursor hot spot is in the window of another thread. BOOL ReleaseCapture(VOID);
    Parameters
    This function has no parameters. Return Values
    If the function succeeds, the return value is nonzero.
      

  4.   

    在while(if(bFlag==0)break;}加个这个标记,用来结束~