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

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.

 


0
artist1 (13)
2/16/2007 2:05:08 AM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
962 Views

Similar Articles

[PageSpeed] 43

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@sj.speakeasy.net> wrote in message 
news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>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.
>
>
>
> 


0
AliR3470 (3236)
2/16/2007 4:01:34 PM
See below...
On Thu, 15 Feb 2007 18:05:08 -0800, "Artist" <artist@sj.speakeasy.net> wrote:

>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 );
****
Note that you don't want the client coordinates of the main window because MDI windows are
child windows of the MDI Client window, which I believe has some name like m_pMDIClient.
Look in your mainframe window, as I haven't looked for this name for many years now.
*****
>
****
Consider GetWindowPlacement instead
****
>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. 
****
This is because you erroneously computed the coordinates relative to the main window, but
as I pointed out, that isn't the window that holds the MDI child windows.
****
>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 );
****
No, just use the correct window to do ScreenToClient.  Note that the parent of the view is
the view frame, which won't help either.
****
>
>But this also did not work. The window always went to the upper left of the 
>Main Window's client area.
*****
Yes, that sounds about right, since the view is always in the top left corner of the
client area of the view frame.
****
>
>How can this be fixed?
>
>***
>To respond to me directly remove sj. from my email address. This is a spam 
>jammer.
>
> 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
2/16/2007 4:28:36 PM
I forgot about that.  It has to be the position of the frame window in the MDIClient
window.  The position of the view window in the main frame is not useful.
				joe
On Fri, 16 Feb 2007 16:01:34 GMT, "AliR \(VC++ MVP\)" <AliR@online.nospam> wrote:

>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@sj.speakeasy.net> wrote in message 
>news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>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.
>>
>>
>>
>> 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
2/16/2007 7:09:30 PM
The child window is descended from CScrollView. In the code I gave this is 
pointed to by pView.

The parent of this child is the main window of the applicaion and is 
descended from CMDIFrameWnd.

This code is being executed in a global object. So this object is not a 
member of any other object. The pView pointer is a member of that object's 
class and is set in its constructor. That object is instantiated in another 
object pointed to by the pView pointer, and pView gets set by passing to the 
constructor the this pointer.

In the code I gave earlier:

pView->GetWindowRect( &m_WndRect );

AfxGetMainWnd()->ScreenToClient( &m_WndRect );

GetWindowRect() is returning the rectangle in screen coordinates. This is 
consistent with its documentation.

I am changing to client coordinates to cover the possibility the position of 
the parent may have changed. I want to save and restore the position of the 
child (pView) relative to its parent (the main window ).

I attemped your recommendations without changing to client coordinates. As I 
expected the attempt at restoration showed the relative position of the 
child after restoration in the Main Frame was dependent on the position of 
the Main Window on the screen. The farther the Main Window was away from the 
upper left corner of the screen the farther the child window was from the 
upper left corner of the Main Window's client area. So I tried the code:

Save:
pView->GetParentFrame()->GetWindowRect( &m_WndRect );

pView->GetParentFrame()->ScreenToClient( &m_WndRect );

Restore:

CFrameWnd *pFrame = pView->GetParentFrame();

pFrame->MoveWindow( &WndRect, TRUE );

The result was the upper left corner of the child's client area ended up in 
the upper left corner of the parent's child area. The Title bar of the child 
ended up under the Toolbar of the parent window making it impossible to move 
the child. This was true regardles of where the child was when the position 
was saved.

"AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
news:yzkBh.19419$ji1.16752@newssvr12.news.prodigy.net...
> 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@sj.speakeasy.net> wrote in message 
> news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>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.
>>
>>
>>
>>
>
> 


0
artist1 (13)
2/17/2007 1:26:12 AM
Here is a test that I did and it worked fine.

void CChildFrame::OnClose()
{
   CRect Rect;
   GetWindowRect(&Rect);
   GetParent()->ScreenToClient(&Rect);

   CString Temp;
   Temp.Format("%d",Rect.left);
   WritePrivateProfileString("MDIPosition","X1",Temp,"MDIPosition.ini");

   Temp.Format("%d",Rect.top);
   WritePrivateProfileString("MDIPosition","Y1",Temp,"MDIPosition.ini");

   Temp.Format("%d",Rect.right);
   WritePrivateProfileString("MDIPosition","X2",Temp,"MDIPosition.ini");

   Temp.Format("%d",Rect.bottom);
   WritePrivateProfileString("MDIPosition","Y2",Temp,"MDIPosition.ini");

   CMDIChildWnd::OnClose();
}

BOOL CChildFrame::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, 
DWORD dwStyle , const RECT& rect , CMDIFrameWnd* pParentWnd , 
CCreateContext* pContext)
{
   CRect Rect;
   Rect.left = GetPrivateProfileInt("MDIPosition","X1",0,"MDIPosition.ini");
   Rect.top = GetPrivateProfileInt("MDIPosition","Y1",0,"MDIPosition.ini");
   Rect.right = 
GetPrivateProfileInt("MDIPosition","X2",0,"MDIPosition.ini");
   Rect.bottom = 
GetPrivateProfileInt("MDIPosition","Y2",0,"MDIPosition.ini");
   return CMDIChildWnd::Create(lpszClassName, lpszWindowName, dwStyle, Rect, 
pParentWnd, pContext);
}

Ali
"Artist" <artist@sj.speakeasy.net> wrote in message 
news:GqqdnTdShcopxEvYnZ2dnUVZ_sSmnZ2d@speakeasy.net...
> The child window is descended from CScrollView. In the code I gave this is 
> pointed to by pView.
>
> The parent of this child is the main window of the applicaion and is 
> descended from CMDIFrameWnd.
>
> This code is being executed in a global object. So this object is not a 
> member of any other object. The pView pointer is a member of that object's 
> class and is set in its constructor. That object is instantiated in 
> another object pointed to by the pView pointer, and pView gets set by 
> passing to the constructor the this pointer.
>
> In the code I gave earlier:
>
> pView->GetWindowRect( &m_WndRect );
>
> AfxGetMainWnd()->ScreenToClient( &m_WndRect );
>
> GetWindowRect() is returning the rectangle in screen coordinates. This is 
> consistent with its documentation.
>
> I am changing to client coordinates to cover the possibility the position 
> of the parent may have changed. I want to save and restore the position of 
> the child (pView) relative to its parent (the main window ).
>
> I attemped your recommendations without changing to client coordinates. As 
> I expected the attempt at restoration showed the relative position of the 
> child after restoration in the Main Frame was dependent on the position of 
> the Main Window on the screen. The farther the Main Window was away from 
> the upper left corner of the screen the farther the child window was from 
> the upper left corner of the Main Window's client area. So I tried the 
> code:
>
> Save:
> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
>
> pView->GetParentFrame()->ScreenToClient( &m_WndRect );
>
> Restore:
>
> CFrameWnd *pFrame = pView->GetParentFrame();
>
> pFrame->MoveWindow( &WndRect, TRUE );
>
> The result was the upper left corner of the child's client area ended up 
> in the upper left corner of the parent's child area. The Title bar of the 
> child ended up under the Toolbar of the parent window making it impossible 
> to move the child. This was true regardles of where the child was when the 
> position was saved.
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:yzkBh.19419$ji1.16752@newssvr12.news.prodigy.net...
>> 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@sj.speakeasy.net> wrote in message 
>> news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>>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.
>>>
>>>
>>>
>>>
>>
>>
>
> 


0
AliR3470 (3236)
2/19/2007 5:03:14 PM
I have found the right code. It is:

To Save:
pView->GetParentFrame()->GetWindowRect( &m_WndRect );
pView->GetParentFrame()->GetParent()->ScreenToClient( &m_WndRect );

To Restore:
CPoint CrsScrnPos( m_CrsClientPos );
pView->GetParentFrame()->GetParent()->ClientToScreen( &CrsScrnPos );
SetCursorPos( CrsScrnPos.x, CrsScrnPos.y );

"Artist" <artist@sj.speakeasy.net> wrote in message 
news:GqqdnTdShcopxEvYnZ2dnUVZ_sSmnZ2d@speakeasy.net...
> The child window is descended from CScrollView. In the code I gave this is 
> pointed to by pView.
>
> The parent of this child is the main window of the applicaion and is 
> descended from CMDIFrameWnd.
>
> This code is being executed in a global object. So this object is not a 
> member of any other object. The pView pointer is a member of that object's 
> class and is set in its constructor. That object is instantiated in 
> another object pointed to by the pView pointer, and pView gets set by 
> passing to the constructor the this pointer.
>
> In the code I gave earlier:
>
> pView->GetWindowRect( &m_WndRect );
>
> AfxGetMainWnd()->ScreenToClient( &m_WndRect );
>
> GetWindowRect() is returning the rectangle in screen coordinates. This is 
> consistent with its documentation.
>
> I am changing to client coordinates to cover the possibility the position 
> of the parent may have changed. I want to save and restore the position of 
> the child (pView) relative to its parent (the main window ).
>
> I attemped your recommendations without changing to client coordinates. As 
> I expected the attempt at restoration showed the relative position of the 
> child after restoration in the Main Frame was dependent on the position of 
> the Main Window on the screen. The farther the Main Window was away from 
> the upper left corner of the screen the farther the child window was from 
> the upper left corner of the Main Window's client area. So I tried the 
> code:
>
> Save:
> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
>
> pView->GetParentFrame()->ScreenToClient( &m_WndRect );
>
> Restore:
>
> CFrameWnd *pFrame = pView->GetParentFrame();
>
> pFrame->MoveWindow( &WndRect, TRUE );
>
> The result was the upper left corner of the child's client area ended up 
> in the upper left corner of the parent's child area. The Title bar of the 
> child ended up under the Toolbar of the parent window making it impossible 
> to move the child. This was true regardles of where the child was when the 
> position was saved.
>
> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
> news:yzkBh.19419$ji1.16752@newssvr12.news.prodigy.net...
>> 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@sj.speakeasy.net> wrote in message 
>> news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>>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.
>>>
>>>
>>>
>>>
>>
>>
>
> 


0
artist1 (13)
2/19/2007 8:36:28 PM
Why don't you do that in the frame? Won't that be cleaner?

See my previous post.

AliR.

"Artist" <artist@sj.speakeasy.net> wrote in message 
news:SoydnTiWirzQl0fYnZ2dnUVZ_rOqnZ2d@speakeasy.net...
>I have found the right code. It is:
>
> To Save:
> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
> pView->GetParentFrame()->GetParent()->ScreenToClient( &m_WndRect );
>
> To Restore:
> CPoint CrsScrnPos( m_CrsClientPos );
> pView->GetParentFrame()->GetParent()->ClientToScreen( &CrsScrnPos );
> SetCursorPos( CrsScrnPos.x, CrsScrnPos.y );
>
> "Artist" <artist@sj.speakeasy.net> wrote in message 
> news:GqqdnTdShcopxEvYnZ2dnUVZ_sSmnZ2d@speakeasy.net...
>> The child window is descended from CScrollView. In the code I gave this 
>> is pointed to by pView.
>>
>> The parent of this child is the main window of the applicaion and is 
>> descended from CMDIFrameWnd.
>>
>> This code is being executed in a global object. So this object is not a 
>> member of any other object. The pView pointer is a member of that 
>> object's class and is set in its constructor. That object is instantiated 
>> in another object pointed to by the pView pointer, and pView gets set by 
>> passing to the constructor the this pointer.
>>
>> In the code I gave earlier:
>>
>> pView->GetWindowRect( &m_WndRect );
>>
>> AfxGetMainWnd()->ScreenToClient( &m_WndRect );
>>
>> GetWindowRect() is returning the rectangle in screen coordinates. This is 
>> consistent with its documentation.
>>
>> I am changing to client coordinates to cover the possibility the position 
>> of the parent may have changed. I want to save and restore the position 
>> of the child (pView) relative to its parent (the main window ).
>>
>> I attemped your recommendations without changing to client coordinates. 
>> As I expected the attempt at restoration showed the relative position of 
>> the child after restoration in the Main Frame was dependent on the 
>> position of the Main Window on the screen. The farther the Main Window 
>> was away from the upper left corner of the screen the farther the child 
>> window was from the upper left corner of the Main Window's client area. 
>> So I tried the code:
>>
>> Save:
>> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
>>
>> pView->GetParentFrame()->ScreenToClient( &m_WndRect );
>>
>> Restore:
>>
>> CFrameWnd *pFrame = pView->GetParentFrame();
>>
>> pFrame->MoveWindow( &WndRect, TRUE );
>>
>> The result was the upper left corner of the child's client area ended up 
>> in the upper left corner of the parent's child area. The Title bar of the 
>> child ended up under the Toolbar of the parent window making it 
>> impossible to move the child. This was true regardles of where the child 
>> was when the position was saved.
>>
>> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
>> news:yzkBh.19419$ji1.16752@newssvr12.news.prodigy.net...
>>> 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@sj.speakeasy.net> wrote in message 
>>> news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>>>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.
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
AliR3470 (3236)
2/19/2007 9:48:54 PM
By the way, where you setting the cursor position or the window position?

AliR.

"Artist" <artist@sj.speakeasy.net> wrote in message 
news:SoydnTiWirzQl0fYnZ2dnUVZ_rOqnZ2d@speakeasy.net...
>I have found the right code. It is:
>
> To Save:
> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
> pView->GetParentFrame()->GetParent()->ScreenToClient( &m_WndRect );
>
> To Restore:
> CPoint CrsScrnPos( m_CrsClientPos );
> pView->GetParentFrame()->GetParent()->ClientToScreen( &CrsScrnPos );
> SetCursorPos( CrsScrnPos.x, CrsScrnPos.y );
>
> "Artist" <artist@sj.speakeasy.net> wrote in message 
> news:GqqdnTdShcopxEvYnZ2dnUVZ_sSmnZ2d@speakeasy.net...
>> The child window is descended from CScrollView. In the code I gave this 
>> is pointed to by pView.
>>
>> The parent of this child is the main window of the applicaion and is 
>> descended from CMDIFrameWnd.
>>
>> This code is being executed in a global object. So this object is not a 
>> member of any other object. The pView pointer is a member of that 
>> object's class and is set in its constructor. That object is instantiated 
>> in another object pointed to by the pView pointer, and pView gets set by 
>> passing to the constructor the this pointer.
>>
>> In the code I gave earlier:
>>
>> pView->GetWindowRect( &m_WndRect );
>>
>> AfxGetMainWnd()->ScreenToClient( &m_WndRect );
>>
>> GetWindowRect() is returning the rectangle in screen coordinates. This is 
>> consistent with its documentation.
>>
>> I am changing to client coordinates to cover the possibility the position 
>> of the parent may have changed. I want to save and restore the position 
>> of the child (pView) relative to its parent (the main window ).
>>
>> I attemped your recommendations without changing to client coordinates. 
>> As I expected the attempt at restoration showed the relative position of 
>> the child after restoration in the Main Frame was dependent on the 
>> position of the Main Window on the screen. The farther the Main Window 
>> was away from the upper left corner of the screen the farther the child 
>> window was from the upper left corner of the Main Window's client area. 
>> So I tried the code:
>>
>> Save:
>> pView->GetParentFrame()->GetWindowRect( &m_WndRect );
>>
>> pView->GetParentFrame()->ScreenToClient( &m_WndRect );
>>
>> Restore:
>>
>> CFrameWnd *pFrame = pView->GetParentFrame();
>>
>> pFrame->MoveWindow( &WndRect, TRUE );
>>
>> The result was the upper left corner of the child's client area ended up 
>> in the upper left corner of the parent's child area. The Title bar of the 
>> child ended up under the Toolbar of the parent window making it 
>> impossible to move the child. This was true regardles of where the child 
>> was when the position was saved.
>>
>> "AliR (VC++ MVP)" <AliR@online.nospam> wrote in message 
>> news:yzkBh.19419$ji1.16752@newssvr12.news.prodigy.net...
>>> 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@sj.speakeasy.net> wrote in message 
>>> news:TYOdnVdtE_rIjEjYnZ2dnUVZ_qunnZ2d@speakeasy.net...
>>>>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.
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
> 


0
AliR3470 (3236)
2/19/2007 9:50:00 PM
Reply:

Similar Artilces:

Toolbars won't stay in position as placed.
Every time I open Visio the toolbars are not as previously positioned. I would like to create a consistent layout so I can easily remember where a tool is located. I understand toolbars change, for example when I view a shapesheet, and that's ok. I currently place all frequently used toolbars together at the top of my drawings in the standard fashion using four rows. When I first open Visio there are large gaps and they are scattered. Any way to lock them into position? Thanks in advance. Visio Standard 2003 SP2 (11.5509.6568). ...

change horizontal header position in excel
Anyone know how to change the horizontal position of the HEADER or FOOTER in EXCEL???? I would greatly appreciate any help. Thank you for your time. pico Wrote: > Anyone know how to change the horizontal position of the HEADER o > FOOTER in > EXCEL???? I would greatly appreciate any help. Thank you for your time. Pico, Can't you go into View/Header-Footer and use the "Left-Center-Right" catagories? You could use spaces in front of your data to move back an forth. Dav -- Piranh ----------------------------------------------------------------------- Piranha's Profi...

WM_QUERYENDSESSION and saving data through a worker thread
Hello I have an application that uses a worker thread to save/load data. I'm wondering what is the best reaction to WM_QUERYENDSESSION in my case. I have to possible scenarios: 1. When WM_QUERYENDSESSION comes fire the thread and wait for it to end. Only then return TRUE from WM_QUERYENDSESSION handler. The problem is that I will get nusty dialog that my application "is not responding". 2. When WM_QUERYENDSESSION comes fire the thread and return FALSE from the handler. When thread is done force application to end. But this way I will probably prevent Windows from closing,...

Backup & restore
I want to backup outlook 2002. I am unable to locate the .pst file. I am using windows xp. Pls advise. And where can I locate bookmark file for backup? Thanks The default location of your pst is: C:\Documents and Settings\*****\Local Settings\Application Data\Microsoft\Outlook Note: Substitute ***** with your own username profile. You may also have to set your folder options to SHOW HIDDEN FOLDERS AND FILES because the LOCAL SETTINGS folder is hidden. The file you want is OUTLOOK.PST >-----Original Message----- >I want to backup outlook 2002. I am unable to locate >the ...

How to Hide Left Panel of Folder Window?
I'm well behind the Windows curve and I'm just now learning to use Windows XP Home. Up to now I've been using Windows 2000 Pro. On my XP desktop I have a shortcut to my music folder which containins my MP3 files. When I double click on the shortcut, a window opens on the desktop displaying the contents of my music folder. This window has a panel along the left side containing items like "File and Folder Tasks" and "Other Places." I can't figure out how to close, hide or otherwise delete this panel. This panel takes up a lot of prec...

dialogs in w98 vs windows xp
I compiled my VC++ application in Windows 98. I treied to run it on a Windows XP machine and some of the icon buttons were different in their dimensions and fit, as was some of the text writing. When I run it on a Windows 98 mchine, even if I change the screen resolution and dimensions, it looks right. Does XP have a different GUI? Thanks, Matt matt, Windows XP introduces improved theme support. I believe they call it a visual style. So, yes the GUI is quite different from earlier Windows versions. I do not know much more about your problem though. A lot of owner draw controls d...

New message opens up behind outlook window
Everytime I click new in my inbox to open a new message, the new message pops up behind the main oulook window. does anyone know how to make this stop? ...

O2003 New Toolbars Saved Where?
I have XP with O2003 on one computer. Just got a new computer with W7 and installed O2003. I copied over the "outcmd.dat" file and I can see my data (e.g. views) so I know its using the correct "outcmd.dat" file. However two custom toolbars I created are not shown nor are they in the customized toolbar list. Are custom toolbars saved in a different location? Thanks Shawn On Jul 24, 6:22=A0pm, srm <s...@primatech.com> wrote: > I have XP with O2003 on one computer. Just got a new computer with W7 > and installed O2003. I copied over the "outcmd.dat" ...

Keeping a table in a form editable and checking that fields are filled in before allowing a save
Firstly apologies if this is the incorrect forum but I was looking for a general word forum and could not find one. Please point me to one if one exists. I am trying to create a form where I want to specify what items need to be filled in. (Review minutes from design reviews). I want to make certain fields mandatory like the date, attendees and check list used and want to block saving of the document with a warning until they are filled in. Is there a way of doing this? Also as a part of the review actions are filled in to a table. depending on how many actions there are the table...

Outlook and Windows Integrated Authentication
Hello All, Does anyone know if Outlook (not OWA) can use Windows Integrated Authentication (like IE) to automatically log onto Intranet Web sites to retrieve graphics in HTML messages? Right now we get a logon dialog and have to manually log in. Thanks. if you paste the url into a browser, does it work as desired? -- Diane Poremsky [MVP - Outlook] Author, Teach Yourself Outlook 2003 in 24 Hours Coauthor, OneNote 2003 for Windows (Visual QuickStart Guide) Need Help with Common Tasks? http://www.outlook-tips.net/beginner/ Outlook 2007: http://www.slipstick.com/outlook/ol2007/ Outloo...

sizing
In excel, if you use the "forms" toolbar to make a "check mark-box, how do you change the font size while you are changing the information. For example, when you click on the box with the check mark- a little icon says "check box", when you change the wording, how do you change the font also? If you need better explaination let me know.. Thanks! Don't think its possible. For one work-around, try this macro by Bob Phillip: http://tinyurl.com/eute "Nicole" <mnicole0@yahoo.com> wrote in message news:c93f01c38217$f639d5f0$a601280a@phx.gbl... &...

Problems opening/saving attachments
I am unable to open or save any .rtf file attachments - this started happening today, previously there were no problems with .rtf files. When I try to open such an attachment I get this message: Can't create file: xyz.rtf Right click the folder you want to create the file in, and then click Properties on the shortcut menu to check your permissions for the folder. What folder is this? I am trying to open the attachment not creat the file! Also, when I try to send an rtf file as an attachment, in the email message the file does not show in the attachments section but the receipient actu...

Windows media player
Why does windows media player keep popping up? David wrote: > Why does windows media player keep popping up? OK, I give up. Why does Windows Media Player keep popping up ? How to ask a question http://support.microsoft.com/kb/555375 Windows Media Player General Discussion http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.windowsmedia.player&cat=en_US_44d7101f-71dd-4f9a-b6b9-45215557dd35&lang=en&cr=US MowGreen ================ *-343-* FDNY Never Forgotten ================ banthecheck.com "Security update...

I need help restoring Public Folders
Hi I've been having issues getting Public Folder replication going between 2 Exchange 2003 servers. Prior to doing any work I performed a Backup using Veritas Backup Exec and this completed and verified correctly. I screwed things up and managed to delete some of the public folders on my original server. I'm not 100% sure what I did but it is a mess and the only backup I have is the Exchange backup I created before doing any work. The public folders contain a number of Contact Lists and a very important Event Calendar. I have restored the public folders but when the restore c...

Saving address to replyed emails
IN outlook express I could automatically save the email address when I replyed to an email. I want to be able to do this in outlook 2002 Can some please help Not possible. You will need to right click on the address and select to Add to Contacts. -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Having searched the archives, Garth <smilepolice@hotmail.com> typed: | IN outlook express I could automatically save the email | address when I replyed to an email. | | I want to be able to do this in outlook 2002 | | Can some please help ...

Task Manager window only CPU
Vista Ultimate SP2 When I launch Windows Task Manager, only a CPU meter opens. When I right click icon in task bar, I only get Close & Always on top options. How do I restore task manager? Happy New Year -- ***************** John Lenz JohnLenz@comcast.net Double click on the white frame of the task manager window. That should do it. -- whs THX - it worked Happy New Year -- ***************** John Lenz JohnLenz@comcast.net "whs" <guest@unknown-email.com> wrote in message news:89eee91dbeee8173c55e0008be25b622@nntp-gateway....

Outlook saves image attachment as bitmap
Hi. I have Outlook 2003 running on Windows XP. When I save an image attachments, it only allows me to save it as bitmap. Before, it used to let me choose between bitmap & jpeg. I found an article on Microsoft's website, but it only pertains to Internet Explorer (http://support.microsoft.com/?kbid=810978#appliesto). I did it anyways, but it didn't correct my problem. Thanx in advance, Candee ...

Same Table cannot be the child table in two nexted relations...
I've been setting up a schema with the XML Designer in VS .NET 2003. The designer lets me set up a lot of things including a complex type that contains an unnamed complex type called modified. When I try to preview the dataset, I get an error described as "The same table (modified) cannot be the child table in two nested relations. I've run into this before with a different complex type, and I've changed the name of the instance of the type in the various elements it's used, and the problem goes away. In this case, problem is an unnamed complex type, so it only a...

Email Text Dissappears when Save
When we save email messages (as a draft) the text dissappears, even when th I use my administrator account. Anybody have any idea what that is happening. ...

Online Restore using NT Backup has no edb.chk or edb.log files
I have a single site with four servers running Exchange 5.5 SP4 on NT4 SP6a. I am using an internal 35/70 Compaq DLT. When I back up two servers at the same time using online method, I am missing the edb.log and and edb.chk files when trying to restore the db's. Is there a known issue for this? Thanks, Jim When you make online backup, you are backing up the database content perse, the logs files will be skipped because ntbackup cannot back up open files. I recomend you to adquire a third party backup software with open files and exchange database options, like Veritas to ensu...

Saving MY Calendar into "Publication-Calendar"
My problem is that I have to make a certain type of calendar in every month. It would save lots of time forme if I could find a way that I could save my "calendar setting" and also be able to apply the new month's settings. There is any way that I could save my "home-made" calendar into "Publications-Calendar" and call it up just like the other calendars? Thanks. If you have repeating items you just use the Merge for those items every month. -- "If you don't know where you are going, any road will take you there!" I do not understand ho...

M2004 Won't Save Customized Toolbars / Home Page
Unable to find anything in archives or the UFAQ on this... My Money 2004 file recently stopped saving customized toolbars / home page. Any changes I make don't "stick". I've used super salvage, which supposedly found and corrected some errors, but the problem persists. Any ideas? Thanks. Try this (and it is in the UFAQ under a less specific topic at http://umpmfaq.info/faqdb.php?q=153). Stop Money Express. Change your toolbar stuff. Exit Money. Restart Money. Restart Money Express. "Sock" <sock@wideopenwest.com> wrote in message news:8205f05b.04101407...

Prevent users from saving music and pictures to their hard drives without folder redirection?
Hi there. I'm wondering if there is a way via GPO or anything else to prevent users from saving music and pictures to their local hard drives without using any type of profile or folder redirection. Thanks. ...

E-mail box sizes. Echange System Manger.
Hi. Now and then I need to find out the size of the various e-mail boxes in Exchange2000. The problem is that the size indicated in the Exchange System Manager do not reflect the same size when you look into Outlook. Is the a way to figure out the correct e-mail size? If not. Is this better in Exchange2003? Thank you in advance. DagN I'd consider the Exchange value to be the most important given this is what will be used for mailbox quotas, etc. Nue "Dag N" <skier@start.no> wrote in message news:OjCaWfjLGHA.2320@TK2MSFTNGP11.phx.gbl... > Hi. > Now and then ...

Setting the default font and font size for Excel comments
Hi, Do you know how to set the default font and font size in Excel for the cell 'Comments'? I have looked in Options as well as in the registry to see if I can change the default from Tahoma (size 8) to another (i.e. Arial size 12). Your help would really be appreciated. Thanks, Clint - UK ...