Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Get the relative pos of the MDI window?

Posted on 1999-01-11
4
Medium Priority
?
229 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 100 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

618 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