ClientToScreen( )是把窗口坐标转换为屏幕坐标
ScreenToClient( )是把屏幕坐标转换为窗口坐标
屏幕坐标是相对于屏幕左上角的,而窗口坐标是相对于窗口用户区左上角的
VC下,有些函SEO靠我数使用窗口坐标,有些使用屏幕坐标,使用时要分清。
一个窗体分为两部分:系统区和客户区
象标题和菜单之类的是系统区,由系统来控制,客户区就是你的地盘喽!!!
Width, Height 是指整体的,ClienSEO靠我tWidth, ClientHeight是指客户区的,两者相减就是
系统区的啦!!!
ClientToScreen是把坐标从当前窗体转化成全屏幕的!!!
ScreenToClient是把屏幕坐标转化成相对当SEO靠我前窗体的坐标!!!!
bool m_bIsLButtonDawn =false;
void CDrawDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TOSEO靠我DO: Add your message handler code here and/or call default
CWnd *pwnd=GetDlgItem(IDC_EDIT1);
CDC *pdc=SEO靠我pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwnd->ScreenToClient(&point);
pwnd->GetClientReSEO靠我ct(&rect);
// HCURSOR hcur=::LoadCursorFromFile("pen.cur");
// SetClassLong(GetSafeHwnd(),GCL_HCURSEO靠我SOR,(LONG)hcur);
// CPen pen(PS_INSIDEFRAME,-1,RGB(255,255,255));
// CPen* olePen=pdc->SelectObjeSEO靠我ct(&pen);
if(rect.PtInRect(point) && m_bIsLButtonDawn )
{
pdc->DPtoLP(&m_fp);
pdc->MoveTo(m_fp);
pdc->DSEO靠我PtoLP(&point);
pdc->LineTo(point);
}
m_fp=point;
// pdc->SelectObject(olePen);
ReleaseDC(pdc);
CDialog::SEO靠我OnMouseMove(nFlags, point);
}
void CDrawDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bIsLButtonDawn =SEO靠我false;
// TODO: Add your message handler code here and/or call default
/**//*
CWnd *pwnd=GetDlgItem(IDCSEO靠我_EDIT1);
CDC *pdc=pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwnd->ScreenToClient(&point);SEO靠我
pwnd->GetClientRect(&rect);
if(rect.PtInRect(point))
{
pdc->DPtoLP(&m_fp);
pdc->MoveTo(m_fp);
pdc->DPtoLPSEO靠我(&point);
pdc->LineTo(point);
}
ReleaseDC(pdc);*/
CDialog::OnLButtonUp(nFlags, point);
}
void CDrawDlg::OnSEO靠我LButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call defauSEO靠我lt
CWnd *pwnd=GetDlgItem(IDC_EDIT1);
CDC *pDC=pwnd->GetDC();
CRect rect;
this->ClientToScreen(&point);
pwSEO靠我nd->ScreenToClient(&point);
pwnd->GetClientRect(&rect);
if(rect.PtInRect(point))
{
m_fp.x=point.x;
m_fp.ySEO靠我=point.y;
}
ReleaseDC(pDC);
m_bIsLButtonDawn =true;
CDialog::OnLButtonDown(nFlags, point);
}
_____________SEO靠我__________________________________________________________________
GetWindowRect是取得窗口在屏幕坐标系下的RECT坐标(包SEO靠我括客户区和非客户区),这样可以得到窗口的大小和相对屏幕左上角(0,0)的位置。
GetClientRect取得窗口客户区(不包括非客户区)在客户区坐标系下的RECT坐标,可以得到窗口的大小,而不能得到相SEO靠我对屏幕的位置,因为这个矩阵是在客户区坐标系下(相对于窗口客户区的左上角)的。
ClientToScreen把客户区坐标系下的RECT坐标转换为屏幕坐标系下的RECT坐标.
ScreenToClient把屏SEO靠我幕坐标系下的RECT坐标转换为客户区坐标系下的RECT坐标.我们对同一个窗口先GetWindowRect取得一个RECT,再用ScreenToClient转换到客户坐标系。然后 GetClientReSEO靠我ct取得一个RECT,再用ClientToScreen转换到屏幕坐标系。显然,GetWindowRect取得的矩阵不小于 GetClientRect取得的矩阵。因为前者包含了非客户区,而后包括了客户区SEO靠我。
对GetWindowRect取得的矩阵ScreenToClient后,矩阵的大小没有变小,(-3,-29)是窗口的左上角的坐标,相对窗口客户区左上角。
对GetClientRect取得的矩阵ClienSEO靠我tToScreen后,矩阵也没有变大,新得到的矩阵是窗口客户区在屏幕坐标系上的RECT。
网站备案号:浙ICP备17034767号-2