获取屏幕任意点的颜色

发表于:2007-07-01来源:作者:点击数: 标签:
主要代码如下: void CPage1::OnLButtonDown(UINT nFlags, CPoint point) { if (::ChildWindowFromPoint(m_hWnd,point) == m_start.m_hWnd) { SetCapture(); SetCursor(AfxGetApp()->LoadCursor(IDC_MAG_GLASS)); m_start.SetIcon(AfxGetApp()->LoadIcon(IDI


 

主要代码如下:

void CPage1::OnLButtonDown(UINT nFlags, CPoint point)
{
 if (::ChildWindowFromPoint(m_hWnd,point) == m_start.m_hWnd)
 {
  SetCapture();
  SetCursor(AfxGetApp()->LoadCursor(IDC_MAG_GLASS));
  m_start.SetIcon(AfxGetApp()->LoadIcon(IDI_MAG_GLASS_BLANK));  
  m_bIsCapturing = true;
  if(m_bHide)
   AfxGetMainWnd()->ShowWindow(SW_SHOWMINIMIZED);
 }
 
 AfxGetMainWnd()->SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,0); 
 
 CPropertyPage::OnLButtonDown(nFlags, point);
}

 

HBRUSH CPage1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
 HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
 
 if(pWnd->GetDlgCtrlID()==IDC_RGB || pWnd->GetDlgCtrlID()==IDC_HEX    )
  pDC->SetTextColor(RGB(0,128,192));
 if(pWnd->GetDlgCtrlID()==IDC_STATE)
  pDC->SetTextColor(RGB(0,0,255));
 
 
 return hbr;
}

void CPage1::OnLButtonDblClk(UINT nFlags, CPoint point)
{
 if(m_rect.PtInRect(point))
 {   
  CColorDialog colordlg; 
  colordlg.m_clearcase/" target="_blank" >cc.Flags |= CC_FULLOPEN; //颜色对话框显示全部
  if(colordlg.DoModal()==IDOK)
   m_color=colordlg.GetColor();  
  InvalidateRect(m_rect);
  
  m_strRGB.Format("RGB(%d,%d,%d)",GetRValue(m_color),GetGValue(m_color),GetBValue(m_color));
  
  m_hex.Format("%02x%02x%02x",GetRValue(m_color),GetGValue(m_color),GetBValue(m_color));
  m_hex.MakeUpper();
  
  
  UpdateData(false);
  
  
 }
 
 CPropertyPage::OnLButtonDblClk(nFlags, point);
}

void CPage1::OnLButtonUp(UINT nFlags, CPoint point)
{
 if (m_bIsCapturing)
 {
  ReleaseCapture();
  m_bIsCapturing = FALSE;
  
  SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
  m_start.SetIcon(AfxGetApp()->LoadIcon(IDI_MAG_GLASS));
  
  if(m_bAutoCopy)    //是否自动复制到剪贴板上
  {       
   GLOBALHANDLE hGMem=::GlobalAlloc(GHND,m_strRGB.GetLength()+1);
   LPSTR lpGMem=(LPSTR)::GlobalLock(hGMem);          
   strcpy(lpGMem,(LPTSTR)(LPCTSTR)m_strRGB);                                  
   ::GlobalUnlock(hGMem);    
   
   if(::OpenClipboard(NULL))
   {
    ::EmptyClipboard();                              
    ::SetClipboardData(CF_TEXT,hGMem);
    ::CloseClipboard();
   }
   static int tt=0;
   CString str;
   str.Format("%d",tt);  tt++;
   SetDlgItemText(IDC_STATE,"已经将颜色值复制到了剪贴板上___" + str);
   
   AfxGetMainWnd()->ShowWindow(SW_SHOWNORMAL);
  }
 }
 CPropertyPage::OnLButtonUp(nFlags, point);
}

程序运行界面如下:

具体代码请看程序。


原文转自:http://www.ltesting.net