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);

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/mao0504/p/4706746.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
VBA中的ClientToScreen函数是用于将窗口客户区的坐标转换为屏幕坐标。该函数的返回值是一个Long型整数,表示转换后的屏幕坐标。 在VBA中,使用ClientToScreen函数需要引用user32.dll动态链接库。在代码中可以通过以下方式调用该函数: Declare Function ClientToScreen Lib "user32.dll" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long 其中hwnd是一个Long型参数,表示窗口的句柄。lpPoint是一个POINTAPI类型的参数,表示窗口客户区的坐标。 在调用ClientToScreen函数之前,首先需要声明一个POINTAPI类型的变量,用于存储转换前的窗口客户区坐标和转换后的屏幕坐标。 接下来,可以使用ClientToScreen函数进行坐标转换。示例代码如下: Dim hwnd As Long Dim clientPoint As POINTAPI Dim screenPoint As Long hwnd = Form1.hwnd clientPoint.x = 100 clientPoint.y = 100 ' 调用ClientToScreen函数进行坐标转换 screenPoint = ClientToScreen(hwnd, clientPoint) MsgBox "转换后的屏幕坐标为:(" & clientPoint.x & "," & clientPoint.y & ")" 上述代码中,首先将Form1的句柄赋值给hwnd变量。然后将要转换的窗口客户区坐标(100, 100)赋值给clientPoint结构体。最后调用ClientToScreen函数进行坐标转换,将转换后的屏幕坐标赋值给screenPoint变量。 最后,通过MsgBox函数弹出一个对话框,显示转换后的屏幕坐标。 这样就可以在VBA中使用ClientToScreen函数进行窗口客户区坐标和屏幕坐标的转换了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值