Solved

Get the relative pos of the MDI window?

Posted on 1999-01-11
4
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 12

Expert Comment

by:migel
ID: 1327484
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
ID: 1327485
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
ID: 1327486
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
ID: 1327487
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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