控件坐标获取问题

uyficu 2012-02-01 11:41:47
怎样获取一个按钮在对话框中的坐标?

CPoint point;
GetWindowRect(&rcBtn);
GetParent()->GetWindowRect(&rcDlg);
point.x = rcBtn.left - rcDlg.left;
point.y = rcBtn.top - rcDlg.top;
发觉上面的方法好像不行,因为对话框也有自己的边框
...全文
42 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eleven 2012-02-02
  • 打赏
  • 举报
回复

m_Button.GetWindowRect(rect);
m_Button.GetParent()->ScreenToClient(rect);
gold_water 2012-02-02
  • 打赏
  • 举报
回复
看穿了就是三个坐标系,慢慢去映射:屏幕坐标系,对话框窗口坐标系,控件本身坐标系(控件本身也是个窗口)
schlafenhamster 2012-02-02
  • 打赏
  • 举报
回复
BOOL CxxxDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// the way to make a tree multi-selected
if(pMsg->message == WM_LBUTTONDOWN)
{ // for win98 and win2000
if((GetKeyState(VK_CONTROL) & 0x8000) || (GetKeyState(VK_SHIFT) & 0x8000))
{
CPoint pt=pMsg->pt;
ScreenToClient(&pt); // convert to client
MapWindowPoints((CWnd*)&m_Tree,&pt, 1); // convert to tree

uyficu 2012-02-01
  • 打赏
  • 举报
回复
上面跟下面的代码都在这个按钮类的消息响应函数写的也用过这样的方法还是不行
CRect rcBtn;
GetWindowRect(&rcBtn);
GetParent()->ScreenToClient(rcBtn);

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧