Solved

Get the relative pos of the MDI window?

Posted on 1999-01-11
4
218 Views
Last Modified: 2013-11-20
Hi,

I have used the SetWindowPos(..) function to set the size and position of the windows.

SetWindowPos(&wndTop,20,20,400,400,SWP_SHOWWINDOW);

But when I use GetClientRect to get the pos of the window,
CRect Place;
GetClientRect(&Place);

Place.left & Place.top always equal to zero.

I tried another method by using the function GetWindowRect();

CRect Place;
GetWindowRect(&Place);

It only returns the position of the window placed on the screen. Thus, the value of Place.left &Place.top is variable.

Anyone can teach me how to get the pos of the mdi window
relative to the main frame???

In this case, I want to get the window's pos will be at
(20,20) with width 400 & heigth 400.

Thanks!!!
0
Comment
Question by:kkuu
  • 2
4 Comments
 
LVL 12

Expert Comment

by:migel
Comment Utility
you must use ScreenToCllient function
for example:

CRect Place;
//pWndMDI - window which rect must be defined
pWndMDI-> GetWindowRect(&Place);
pWndMainFrame->ScreenToClient(&Place);
0
 

Author Comment

by:kkuu
Comment Utility
Dear migel,

I don't know how to get the pointer pWndMDI & pWndMainFrame.

I want to get the size & position of the MDI Window relative to the main frame in the file with the base class CMDIChildWnd.

Can you teach me how to implement your suggested solution?

Thanks you very much!
0
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hmm. As I understand you want make it unside class derived from CMDIChildWnd?
for example:
CMyChild - this class
CMyChild::On....() <- function where you done this work
{
     CWnd* pWndMainFrame = AfxGetMainWnd(); //<- get pointer to the main app window
      CRect Place;
      //pWndMDI - window which rect must be defined
       GetWindowRect(&Place);
      pWndMainFrame->ScreenToClient(&Place);
// ... use converted rectangle
}
0
 
LVL 1

Accepted Solution

by:
hbuehler earned 50 total points
Comment Utility
What's about using

CRect MyMDIWnd::GetWindowPosRelToParent()
{
  WINDOWPLACEMENT wpl;
  GetWindowPlacement(&wpl);
  return CRect(wpl.rcNormalPosition);
}

void MyMDIWnd::SetWindowPosRelToParent(CRect rectOld)
{
  WINDOWPLACEMENT wpl;
  GetWindowPlacement(&wpl);    // to retain current state
  wpl.rcNormalPosition = rectOld;
  SetWindowPlacement(&wpl);
}


0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now