ClientToScreen

ClientToScreen

目录导航

基本内容

 这个函数的功能:该函数将指定点的用户坐标转换成屏幕坐标。

函数原型:BOOL ClientToScreen(HWND hWnd,LPPOINT lpPoint);

  参数:

  :用户区域用于转换的窗口句柄。

  :指向一个含有要转换的用户坐标的结构的指针,如果函数调用成功,新屏幕坐标复制到此结构。

  返回值:如果函数调用成功,返回值为非零值,否则为零。

  注释:函数用屏幕坐标取代POINT结构中的用户坐标,屏幕坐标与屏幕左上角相关联。

  速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;头文件:winuser.h;库文件:user32.lib。

相近用法

ClientToScreen 和ScreenToClient函数的用法相近,但是也有一定区别:

ClientToScreen( )是把窗口坐标转换为屏幕坐标

ScreenToClient( )是把屏幕坐标转换为窗口坐标

屏幕坐标是相对于屏幕左上角的,而窗口坐标是相对于窗口用户区左上角的

VC下,有些函数使用窗口坐标,有些使用屏幕坐标,使用时要分清。

一个窗体分为两部分:系统区和客户区

象标题和菜单之类的是系统区,由系统来控制,客户区就是你的地盘喽!!!

Width, Height 是指整体的,ClientWidth, ClientHeight是指客户区的,两者相减就是

系统区的啦!!!

ClientToScreen是把坐标从当前窗体转化成全屏幕的!!!

ScreenToClient是把屏幕坐标转化成相对当前窗体的坐标!!!!

ClientToScreen 和ScreenToClientClientToScreen 和ScreenToClientbool 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);

}

相关百科
返回顶部
产品求购 求购