Solved

Get the relative pos of the MDI window?

Posted on 1999-01-11
4
223 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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 54
repeateFront java challenge 31 95
wait notify demo infinite loop 3 137
Modbus - whats the maximum I can store in one register? 4 82
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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