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

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

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

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



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

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

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

系统区的啦!!!

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

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


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

}

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 25岁的心里话
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器