Re: Saving and Restoring a Child Window to its Former Position and Size

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.






.



Relevant Pages

  • Re: NSView flickering
    ... The usual approach is to use the view's autoresizing mask to have it changes its frame automatically. ... changes the bounds so that drawing at the new bounds origin draws in the lower (or upper) left corner of your view. ... Make it as large as your window and set its autoresizing mask to have its width and height sizable. ...
    (comp.sys.mac.programmer.help)
  • Re: In the need for some advice!
    ... int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInnstance, ... PSTR szCmdLine, int iCmdShow) ... //CONFIGURE WINDOW APPLICATION ... //CONFIGURE CHILD WINDOW #1 ...
    (microsoft.public.vc.language)
  • Re: Saving and Restoring a Child Window to its Former Position and Size
    ... It has to be the position of the frame window in the MDIClient ... The position of the view window in the main frame is not useful. ... The parent of this child ... It is as if the storage is referenced to the upper ...
    (microsoft.public.vc.mfc)
  • Re: GetTextExtent and Window Placement
    ... the pDC comes from the OnPaint handler. ... I've two windows: a parent window and a child window. ... because the CPaintDC is not a CDC *. ...
    (microsoft.public.vc.mfc)
  • Re: GetTextExtent and Window Placement
    ... the pDC comes from the OnPaint handler. ... I've two windows: a parent window and a child window. ... because the CPaintDC is not a CDC *. ...
    (microsoft.public.vc.mfc)