Solved

MoveWindow() of a groupbox overtop another groupbox

Posted on 1998-08-29
4
585 Views
Last Modified: 2008-02-01
I am performing a MoveWindow on a groupbox within a dialog such that I want one groupbox to overlay another groupbox. Both groupboxes are defined on the dialog with the exact same dimensions. However, when I perform the MoveWindow() command, the groupbox I wish to move actually appears about 1/4 inch below the groupbox I am trying to overlay.

Here is the code I am using:

m_wndGroupToOverlay = a CButton assigned control to the groupbox. (I don't know why ClassWizard only gave me this choice for a member variable assignment...but...)

m_wndOtherGroupBox = another groupbox member variable for a groupbox defined elsewhere in the dialog.

In OnInitDialog():
(..after calling the default ::OnInitDialog)
m_wndGroupToOverlay.GetWindowRect(&m_rectGroupToOverlay);

In SomeOtherFunction:
m_wndOtherGroupBox.MoveWindow(&m_rectGroupToOverlay);

This results in the offset groupbox, when I was expecting it would be covering the original groubox completely.

Any thoughts?

Thanks
0
Comment
Question by:rascal
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 1171556
answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1171557
Its a matter of  coordinate systems. GetWindowRect() returns the window's coordinates relative to the top left corner of the screen.  MoveWindow() takes coordinates that are relative to the top-left corner of the window's parent window's client area.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1171558
The following code should fix the problem, or at least be close, I may not have the math perfect.

 m_wndGroupToOverlay.GetWindowRect(&m_rectGroupToOverlay);
CWnd *ParWndPtr = GetParent();
POINT Pnt = {0,0};
ParWndPtr->ClientToScreen(0,0);
m_rectGroupToOverlay.Left -= Pnt.x;
m_rectGroupToOverlay.Right -= Pnt.x;
m_rectGroupToOverlay.Top -= Pnt.y;
m_rectGroupToOverlay.Bottom -= Pnt.y;

let me know if you have questions.
0
 
LVL 1

Author Comment

by:rascal
ID: 1171559
Thanks, I used ScreenToClient to change the coordinates and it worked as intended.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

803 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