ClientToScreen 和ScreenToClient 用法

简介: <div class="mod-page-main wordwrap clearfix"> <div class="x-page-container"> <div class="mod-blogpage-wraper"> <div class="grid-80 mod-blogpage"> <div class="mod-text-content mod-post-content
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);
相关文章
|
8月前
|
测试技术 API
harfbuzz 的用法
HarfBuzz 整形 API 的核心是函数。此函数采用一种字体,即 包含一串 Unicode 代码点的缓冲区和 (可选)字体功能列表作为其输入。它取代了 缓冲区中的代码点,其中包含来自 字体,正确排序和定位,以及任何 应用的可选字体功能。hb_shape()
228 0
|
10月前
|
Python
__name__的基本用法
__name__的基本用法
66 0
|
Java
Systrace的用法小结
通过SysTrace可以帮助我们分析性能问题,包含方法的耗时时长、CPU的使用情况、ANR、布局情况等;相比性能工具TraceView,主要用来分析每个方法的执行时间,对于冷启动而言,想抓trace只能通过代码的方式,这样会导致整个应用比较卡顿,测试出的方法时间,不是真正的执行时间,只能看下时间长短的相对占比。
3430 0
iTween的基本用法
Unity3D插件-iTween的基本用法 本文提供全流程,中文翻译。Chinar坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 —— 高分辨率用户请根据需求调整网页缩放比例...
1854 0