Advertisement

09.17.2008 at 12:49PM PDT, ID: 23740128 | Points: 500
[x]
Attachment Details

Use of GetClientRect in activeX - inconsistent results

Asked by charles_gilley in Windows MFC Programming, Windows OLE Programming

Tags:

I've inherited some activeX controls that I have been endeavoring to extend.  Much to my annoyance, the changes are becoming a career path.  I will preface my question with the warning that the control in question may have never worked correctly to begin with....

As with all activeX controls, there are two modes of operation - design mode and user mode.  Design mode seems to work fine.  User mode seems to be the braindead path.  I've attached the code below.  Basically, the control redraws itself incorrectly, not filling in the entire window region.  If you look at the code below, we have two handlers - OnPaint does the drawing in user mode, OnDraw handles design mode.  Design mode always works, and I've tracked it down to the GetClientRect call.

In design mode, when I resize things, GetClientRect returns the new size of the control.  So, all of my centering, etc plays correctly.  In user mode, the GetClientRect returns only the first window size.  Resizing is ignored.  I should point out that my test results are from using the activeX control test container, but the results seem to play out in actual use.

My conclusion is that this behavior has been there for many years.  Because we don't resize or do serious drawing at runtime, we never ran into this issue.  I'd like someone to tell me if GetclientRect is being used correctly, or shine some light on this issue maybe with some additional questions.

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
void CMyButton::OnPaint() 
{
   CPaintDC dc(this); // device context for painting
	
   // Get client rect.
   CRect rc;
   GetClientRect(rc);
 
   DrawButton(&dc, rc, some_app_data, GetState());
 
   // Do not call CButton::OnPaint() for painting messages
}
 
void CMyButton::OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
   DoSuperclassPaint(pdc, rcBounds);
 
   if (AmbientUserMode())
   {
      // Control is in run-mode.
      // If control window has not been created, then create it.
      if (!IsWindow(m_NButton.m_hWnd))
      {
         CRect rc;
         GetClientRect(rc);
 
         // A class 'CMyButton' is derived from the standard Microsoft
         // CButton class.  The CMyButton class is the control when in
         // run-mode.
         m_MyButton.Create(_T("MyButton"),
	   WS_CHILD | WS_VISIBLE | BS_OWNERDRAW | GetStyle(),
           rc, this, 0);
 
         m_MyButton.EnableWindow(m_buttonData.bEnabled);
      }
 
      // The button will be drawn in the CMyButton object.
   }
   else
   {
      // Control is in design-mode.
      DrawButton(pdc, rcBounds, m_buttonData, 0x00);
   }
}
[+][-]09.18.2008 at 03:32AM PDT, ID: 22509369

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.19.2008 at 04:30AM PDT, ID: 22519912

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.21.2008 at 05:35AM PDT, ID: 22534182

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.21.2008 at 05:43AM PDT, ID: 22534216

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.21.2008 at 10:50AM PDT, ID: 22535512

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628