Tech Support > Microsoft Windows > Development Resources > Finding Dialog's Position
Finding Dialog's Position
Posted by matt on January 23rd, 2004


I'm trying to find the position of a dialog box, but I'm having
trouble. I think I need to use GetWindowRect, but I'm not sure of the
proper format/syntax.

Thanks,

Matt

Posted by lallous on January 23rd, 2004


Hello,

Given 'hWnd':
RECT rect;

::GetWindowRect(hWnd, &rect);

You can restore it back using SetWindowPos()

--
Elias
"matt" <bonmatt10@cs.com> wrote in message
news:c2838b8f.0401222034.70e8fce7@posting.google.c om...


Posted by matt on January 23rd, 2004


This is what I tried but it didn't work. This code is within OnPaint
of the main window, not within the dialog box's code. So what do I
put to the left of :: ? Is that the problem?

Thanks.

CWnd* DlgWindow=GetDlgItem(IDC_RESET);
HWND mHwnd=DlgWindow->GetSafeHwnd();

CRect DlgRect;
::GetWindowRect(mHwnd,&DlgRect);


"lallous" <lallous@lgwm.org> wrote in message news:<buqkha$krncm$1@ID-161723.news.uni-berlin.de>...

Posted by Scott McPhillips [MVP] on January 23rd, 2004


matt wrote:
To get the dialog box's position you have to call the dialog box's
GetWindowRect function. Your GetDlgItem(IDC_RESET) does not look right,
but you haven't explained enough to be sure. Don't you already have a
member variable that is the dialog object? For example, for a modeless
dialog you would generally have a variable like CMyDialog* m_pDlg. Use
this variable to call the dialog's GetWindowRect:

CRect DlgRect;
m_pDlg->GetWindowRect(&DlgRect);

You're also confusing yourself by asking an MFC question in a non-MFC
newsgroup. In MFC you rarely need HWND's and GetDlgItem.

--
Scott McPhillips [VC++ MVP]


Posted by r_z_aret@pen_fact.com on January 24th, 2004


On 23 Jan 2004 08:45:47 -0800, bonmatt10@cs.com (matt) wrote:

Sort of. In the snippet lallous provided, ::GetWindowRect references
the global (Win32 API) function. So _nothing_ goes to the left of the
"::". The first argument (a HWND) specifies the window. I believe the
MFC equivalent has the same name, but omits the HWND argument; it gets
the dimensions of the window object specified to the left of the "->"
or ".". Either way, the "trick" here is to get hold of the dialog box,
starting with code in the main window. I think that is a question that
can't be answered without more info about your application. I think we
need to know how the main window and "the" dialog box are related and
what might be unique about "the" dialog box so we can find it.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com


Similar Posts