Re: Saving and Restoring a Child Window to its Former Position and Size
- From: "AliR \(VC++ MVP\)" <AliR@xxxxxxxxxxxxx>
- Date: Fri, 16 Feb 2007 16:01:34 GMT
By child window do you mean ChildFrame (CMDIChildWnd)? Try getting the
views Frame position.
Save
pView->GetParentFrame()->GetWindowRect( &m_WndRect );
Restore
CFrameWnd *pFrame = pView->GetParentFrame();
pFrame->MoveWindow( &WndRect, TRUE );
You shouldn't have to change the coordinates to Screen coordinates, You only
have to do that if the view is a popup. As long as it's embedded in the
frame the coordinates you pass to MoveWindow or SetWindowPos are relative to
the upper left corner of the parent window.
And in which class and method are you calling this code from?
AliR.
"Artist" <artist@xxxxxxxxxxxxxxxx> wrote in message
news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@xxxxxxxxxxxxxxxx
I want to save a child window's position and size in the Main Window of an
MDI application, and restore it at any time later. I want to do this after
the user may have reposition and resized it. The parent of this child
window is the Main Window. Below is the code I am using to save the
position and size:
pView->GetWindowRect( &m_WndRect );
AfxGetMainWnd()->ScreenToClient( &m_WndRect );
where pView is a pointer to the child window and m_WndRect is used for the
storage. Below is the code I am using in an attempt to restore the
position and size stored in m_WndRect:
CFrameWnd *pFrame = pView->GetParentFrame();
pFrame->MoveWindow( &WndRect, TRUE );
Where once again pView is a pointer to the child frame.
This does not quite work. When the restoration is attempted the child
window is below and a little to the right of where it was. It appears to
be lower by the sum of the widths of the Ttitle Bar, Menu Bar, and
Toolbar. It appears to the right of where it was by the width of the the
Main Window's border. It is as if the storage is referenced to the upper
left corner of the title bar and the restoration is referenced to the
upper left corner of the client area where its child windows reside. This
would mean instead of
AfxGetMainWnd()->ScreenToClient( &m_WndRect );
I need a function another function that would reference m_WndRect to the
upper left of the client area. I have tried in its place:
pView->GetParent()->ScreenToClient( &m_WndRect );
But this also did not work. The window always went to the upper left of
the Main Window's client area.
How can this be fixed?
***
To respond to me directly remove sj. from my email address. This is a spam
jammer.
.
- Follow-Ups:
- Re: Saving and Restoring a Child Window to its Former Position and Size
- From: Artist
- Re: Saving and Restoring a Child Window to its Former Position and Size
- From: Joseph M . Newcomer
- Re: Saving and Restoring a Child Window to its Former Position and Size
- References:
- Prev by Date: Re: Uppercase/Lowercase routine for current codepage?
- Next by Date: Re: Using HTML Help with MFC8
- Previous by thread: Saving and Restoring a Child Window to its Former Position and Size
- Next by thread: Re: Saving and Restoring a Child Window to its Former Position and Size
- Index(es):
Relevant Pages
|