Solved

Get the relative pos of the MDI window?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 55
ODBC Connection Logging, ADO.NET 6 56
isEverywhere  challenge 19 72
scoreUp challenge 14 57
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

21 Experts available now in Live!

Get 1:1 Help Now