如何获取对话框的位置,宽度和长度。 [英] How to get the position ,width and length of the dialog box.

查看:105
本文介绍了如何获取对话框的位置,宽度和长度。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在移动该对话框时获取对话框的位置,宽度和长度,并且应该在该对话框中显示。我使用了OnMove和OnSize但它在基于对话框的应用程序中不起作用。下面给出的代码就是我所知道的在移动窗口时获取坐标。



I have to get the position,width and length of the dialog box when im moving that dialog box and that should be displayed in that dialog itself.I used OnMove and OnSize but it doesn''t work in the dialog based applications. The given below code is what i know to get the coordinates while moving the window.

void CTickCounterDlg::OnMove(int x, int y)
{
    CDialog::OnMove(x, y);
    // TODO: Add your message handler code here
wchar_t *s=new wchar_t[20];
wsprintf(s,L"%d|%d",x,y);
m_size.Format(L"%s",s);
//CRect dialogRect;
//GetWindowRect(&dialogRect);
//ScreenToClient(dialogRect);
//int a=dialogRect.left;
//int b=dialogRect.right;
//wsprintf(s,L"%d|%d",a,b);
//m_size.Format(L"%s",s);
}

void CTickCounterDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialog::OnSize(nType, cx, cy);
    // TODO: Add your message handler code here
wchar_t *sz=new wchar_t[20];
wsprintf(sz,L"%d|%d",cx,cy);
m_ScreenSize.Format(L"%s",sz);
}





任何人告诉我基于对话框的应用程序的解决方案。



谢谢&问候

J.Surjith Kumar



Anyone tell me the solutions for the dialog based applications.

Thanks & regards
J.Surjith Kumar

推荐答案

GetWindowRect()给你绝对的坐标。这里不需要使用 ScreenToClient()(绝对坐标是你可能想要的):

GetWindowRect() gives you the absolute coordinates. Using ScreenToClient() is not necessary here (the absolute coordinates are what you probably want):
void CTickCounterDlg::OnMove(int x, int y)
{
    CRect dialogRect;
    GetWindowRect(&dialogRect);
    m_Size.Format(L"Before move: x = %d, y = %d, width = %d, height = %d", 
        dialogRect.left, dialogRect.top, dialogRect.Width(), dialogRect.Height());
    CDialog::OnMove(x, y);
    GetWindowRect(&dialogRect);
    m_Size.Format(L"After move: x = %d, y = %d, width = %d, height = %d", 
        dialogRect.left, dialogRect.top, dialogRect.Width(), dialogRect.Height());
}


亲爱的朋友

你必须在计时器事件中写下获取功能。

当你点击对话框时,在OnLCickDown事件中你必须启用并调用OnTimer事件。

在OnTimer中你必须得到对话的Rect使用GetWindowRect功能。

之后你可以得到你想要的东西。

它很容易且有效。确定我的朋友。
dear friend
you have to write the "getting" features in a timer event.
when you''re clicking on the dialog,in "OnLCickDown" event you have to enable and call the "OnTimer" event.
in OnTimer you have to get Rect of your dialog with GetWindowRect function.
after that you can get what you want.
it''s easy and works.be sure my friend.


这篇关于如何获取对话框的位置,宽度和长度。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆