Help and Support

DOC: GetClientRect() May Assert in OLE Controls

Article ID:138664
Last Review:November 21, 2006
Revision:2.1
This article was previously published under Q138664

SUMMARY

In chapter 4 of the Ole Control Tutorial, the section labeled Setting the CircleOffset Property Step 2, which describes how to implement the InBounds() function, incorrectly calls GetClientRect() and should read as follows instead:

1.Add the function implementation at the end of your CIRCCTL.CPP file:
      BOOL CCirc2Ctrl::InBounds(short nOffset)
      {
         int diameter;
         int length;
         int cx;
         int cy;

        // Note that GetControlSize() is called here instead of
        // GetClientRect()

         GetControlSize(&cx, &cy);

         if (cx > cy)
         {
            length = cx;
            diameter = cy;
         }
         else
         {
            length = cy;
            diameter = cx;
         }
         if (nOffset < 0)
            nOffset = (short) -nOffset;
         return (diameter / 2 + nOffset) <= (length / 2);
      }
						
This documentation error was corrected in Visual C++ version 5.0.

MORE INFORMATION

In some control containers (such as Visual Basic and Microsoft Access) in design mode, the control has no window, and therefore no hwnd, so calling GetClientRect(rc) will assert.

There are actually two solutions to this problem. The first solution is documented in the "Summary" section of this article. The second solution is to replace the call to GetClientRect() with a call to GetRectInContainer(), which will obtain the coordinates of the control's rectangle relative to the container. The size of the control can then be calculated from this rectangle.

APPLIES TO
Microsoft Foundation Class Library 4.2, when used with:
  Microsoft OLE Control Developer's Kit (CDK)
  Microsoft Visual C++ 4.0 Professional Edition
  Microsoft Visual C++ 4.1 Subscription
  Microsoft Visual C++ 4.2 Professional Edition
  Microsoft Visual C++ 4.2 Enterprise Edition
  Microsoft Visual C++ 5.0 Learning Edition
  Microsoft Visual C++ 5.0 Learning Edition

Back to the top

Keywords: 
kbbug kbctrlcreate kbdocerr kbdocfix kbfix kbprb kbvc500fix KB138664

Article Translations

 

Other Support Options

  • Contact Microsoft
    Phone Numbers, Support Options and Pricing, Online Help, and more.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.