Solved

MoveWindow() of a groupbox overtop another groupbox

Posted on 1998-08-29
4
580 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

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

929 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

14 Experts available now in Live!

Get 1:1 Help Now