閱讀47 返回首頁    go 阿裏雲 go 技術社區[雲棲]


ClientToScreen 和ScreenToClient 用法

ClientToScreen( )是把窗口坐標轉換為屏幕坐標
ScreenToClient( )是把屏幕坐標轉換為窗口坐標
屏幕坐標是相對於屏幕左上角的,而窗口坐標是相對於窗口用戶區左上角的
VC下,有些函數使用窗口坐標,有些使用屏幕坐標,使用時要分清。


一個窗體分為兩部分:係統區和客戶區
象標題和菜單之類的是係統區,由係統來控製,客戶區就是你的地盤嘍!!!
Width, Height 是指整體的,ClientWidth, ClientHeight是指客戶區的,兩者相減就是
係統區的啦!!!
ClientToScreen是把坐標從當前窗體轉化成全屏幕的!!!
ScreenToClient是把屏幕坐標轉化成相對當前窗體的坐標!!!!
 
 //Resize window to proper size based on video standard
 CRect recDstD1( 0, 0, 720, 576 );  
 static_preview_window.ClientToScreen(&recDstD1); //    recDstD1 {top=53 bottom=629 left=200 right=920} CRect

 static_preview_window.SetWindowPos(&CWnd::wndBottom, recDstD1.left, recDstD1.top, recDstD1.right - recDstD1.left + 10, new_height + 10, SWP_NOMOVE | SWP_SHOWWINDOW); 
 

bool   m_bIsLButtonDawn =false;

void CDrawDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd *pwnd=GetDlgItem(IDC_EDIT1);
     CDC *pdc=pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwnd->ScreenToClient(&point);
pwnd->GetClientRect(&rect);

//   HCURSOR hcur=::LoadCursorFromFile("pen.cur");
//   SetClassLong(GetSafeHwnd(),GCL_HCURSOR,(LONG)hcur);  

// CPen pen(PS_INSIDEFRAME,-1,RGB(255,255,255));
//      CPen* olePen=pdc->SelectObject(&pen);
if(rect.PtInRect(point) &&   m_bIsLButtonDawn )
{

   pdc->DPtoLP(&m_fp);
   pdc->MoveTo(m_fp);
   pdc->DPtoLP(&point);
   pdc->LineTo(point);

}
   m_fp=point;
//   pdc->SelectObject(olePen);
ReleaseDC(pdc);
CDialog::OnMouseMove(nFlags, point);
}

void CDrawDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
   m_bIsLButtonDawn =false;
// TODO: Add your message handler code here and/or call default
/**//*
    CWnd *pwnd=GetDlgItem(IDC_EDIT1);
      CDC *pdc=pwnd->GetDC();
   CRect rect;
   this->ClientToScreen(&point);
   pwnd->ScreenToClient(&point);
   pwnd->GetClientRect(&rect);
  
   if(rect.PtInRect(point))
   {
    pdc->DPtoLP(&m_fp);
    pdc->MoveTo(m_fp);
    pdc->DPtoLP(&point);
    pdc->LineTo(point);

   }
   ReleaseDC(pdc);*/

CDialog::OnLButtonUp(nFlags, point);
}

void CDrawDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CWnd *pwnd=GetDlgItem(IDC_EDIT1);
CDC *pDC=pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwnd->ScreenToClient(&point);
pwnd->GetClientRect(&rect);
if(rect.PtInRect(point))
{
   m_fp.x=point.x;
   m_fp.y=point.y;
}
ReleaseDC(pDC);
   m_bIsLButtonDawn =true;
CDialog::OnLButtonDown(nFlags, point);

最後更新:2017-04-03 14:53:55

  上一篇:go poj 2545 Hamming Problem
  下一篇:go 基礎加強