Getting the location of a CStatic object in a dlg.
Terry Wellmann -- wellmatl@cs.purdue.edu Thursday, March 28, 1996 VC++ 4.0 / Win 95 I've created a modeless dialog box in which I've created several CStatic box objects. I want to use these boxes as status lights and fill them with different colors but I can't get the correct location of the boxes. I've used Class Wizard to create CStatic control member variables for each box and then called GetClientRect to obtain the right and bottom coordinates of the box. The problem I have is calculating the top and left coordinates. I could just subtract the width and height of the boxes but that places dependancies on the box size and is bound to cause headaches down the road. I've tried calling GetWindowRect to get the upper left corner of the dialog box, and calling GetWindowRect to get the upper left corner of the CStatic box I'm looking for and then doing the subtraction but it turns out that I'm offset by the width of the dialog frame and title bar. Again I could add a compensation factor in here but it places dependencies on the window layout. How do I get the location of the box so I can fill it in? Thanks, Terry ----------------------------------------------------------------------- | Terry Wellmann | | CS Major - Purdue University | | Programmer/Systems Analyst - M.A.I.L.code Inc. | | E-Mail: wellmatl@cs.purdue.edu | | http://www.cs.purdue.edu/people/wellmatl | |=====================================================================| | | | " ..655,360 bytes is more than enough for any application we could | | ever develop." - Bill Gates in PC Monthly, Aug. 1983 | | | -----------------------------------------------------------------------
Mike Blaszczak -- mikeblas@msn.com Sunday, March 31, 1996 [Mini-digest: 2 responses] > VC++ 4.0 / Win 95 > I've created a modeless dialog box in which I've created several CStatic > box objects. I want to use these boxes as status lights and fill them with > different colors but I can't get the correct location of the boxes. I'm not sure why you care where they're located. Why don't you just write an OnCtlColor() handler and paint the control with your solid color? [Moderator's note: I made the same observation when I got the message, but, as usual, I got no response. I feel so... cheap! ;-] > [huge sig deleted] .B ekiM TCHAR sz[] = _T("That foot odor! I can't take it anymore!"); -----From: Brad Wilson>> I've tried calling GetWindowRect to get the upper left corner of the dialog >> box, and calling GetWindowRect to get the upper left corner of the CStatic >> box I'm looking for and then doing the subtraction but it turns out that >> I'm offset by the width of the dialog frame and title bar. Again I could >> add a compensation factor in here but it places dependencies on the window >> layout. Try this instead: CMyDialog :: SomeFunction() { ... CRect rect; m_MyStatic.GetWindowRect( &rect ); m_MyDialog.ScreenToClient( &rect ); ... } -- Brad Wilson, Crucial Software crucial@ix.netcom.com +1 (810) 620-9803 Custom software engineering services for Microsoft Windows NT and Windows 95 "A cultist is one who has a strong belief in the Bible and the second coming of Christ; who frequently attends Bible studies; who has a high level of financial giving to a Christian cause; who homeschools their children; who have accumulated survival foods and have a strong belief in the second amendment; and who distrusts big government." - U.S. Att Gen Janet Reno
| Вернуться в корень Архива |