Microsoft Knowledge Base Email Alertz

KBAlertz.com: (242002) - An ATL ActiveX Control does not appear or appears incorrectly when added to a Microsoft Access Report. The same control displays correctly when the Report is in design mode or if the control is added to an Access Form.

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 242002 - Last Review: January 25, 2007 - Revision: 5.2

PRB: ATL Control Appears Incorrect in Access Report

This article was previously published under Q242002

On This Page

SYMPTOMS

An ATL ActiveX Control does not appear or appears incorrectly when added to a Microsoft Access Report. The same control displays correctly when the Report is in design mode or if the control is added to an Access Form.

CAUSE

Microsoft Access uses different drawing methods for rendering a control on a Report and rendering it on a Form. When placed on a Report, the control is asked for a metafile presentation that Access uses to render the control when previewing or printing the report. The control itself (that is, the control window) is only displayed when in design mode. The problem is that the metafile being rendered by the ATL control is incorrect.

When Access requests that the control draw itself (through IViewObject::Draw), ATL uses the GetDeviceCaps API and the TECHNOLOGY index to determine whether the HDC passed as a parameter to the function is a metafile device context. Under certain circumstances, this call does not succeed in detecting that a metafile is indeed being used, so ATL treats the bounding RECT coordinates as screen coordinates instead of HIMETRIC units.

RESOLUTION

To resolve the problem, change the code that checks the device context so that it also checks if the bounding window RECT passed in from IViewObject::Draw is NULL. If the parameter is NULL, a metafile is not being drawn. See the sample below to demonstrate the workaround.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start Visual C++ and create a new ATL COM AppWizard project. Name the project AccessTest. Accept the default settings for the wizard.
  2. Using Insert|New ATL Object, add a Full Control object to the project. Name the control AccessTestCtrl, and on the Miscellaneous tab, check the Windowed Only check box. From the Stock Properties tab, select Caption and Enabled. Click OK.
  3. Press the F7 key to build and register the control.
  4. Open Microsoft Access (create a new database if necessary), and add a new Report.
  5. With the report in design mode, select More Controls from the Toolbox toolbar and find the AccessTestCtrl item. Add an instance of the ATL control to the report.
  6. Save the report and close.
  7. Now re-open the Report in preview mode and note that the control does not appear or appears incorrectly.

Building a Workaround

  1. Close down Microsoft Access and go back to your ATL project.
  2. The check for the metafile is in OnDrawAdvanced. To fix the problem, override this function by adding the following to the control class (in AccessTestCtrl.h) just before the OnDraw function:
    HRESULT OnDrawAdvanced(ATL_DRAWINFO& di)
    {
       BOOL bDeleteDC = FALSE;
       if (di.hicTargetDev == NULL)
       {
          di.hicTargetDev = AtlCreateTargetDC(di.hdcDraw, di.ptd);
          bDeleteDC = (di.hicTargetDev != di.hdcDraw);
       }
       RECTL rectBoundsDP = *di.prcBounds;
    
    // Check for a metafile...
       BOOL bMetafile = GetDeviceCaps(di.hdcDraw, TECHNOLOGY) == DT_METAFILE;
    
    // Changed "if" clause to check both the metafile flag and
    // bounding window RECT passed to IViewObject::Draw...
       if ((!bMetafile) && (di.prcWBounds == NULL))
       {
          ::LPtoDP(di.hicTargetDev, (LPPOINT)&rectBoundsDP, 2);
          SaveDC(di.hdcDraw);
          SetMapMode(di.hdcDraw, MM_TEXT);
          SetWindowOrgEx(di.hdcDraw, 0, 0, NULL);
          SetViewportOrgEx(di.hdcDraw, 0, 0, NULL);
          di.bOptimize = TRUE; //since you save the DC you can do this
       }
    
       di.prcBounds = &rectBoundsDP;
       GetZoomInfo(di);
    
       HRESULT hRes = OnDraw(di);
       if (bDeleteDC)
          ::DeleteDC(di.hicTargetDev);
       if ((!bMetafile) && (di.prcWBounds == NULL))
          RestoreDC(di.hdcDraw, -1);
       return hRes;
    }
    					
  3. Recompile the control by pressing the F7 key. Reopen Access, preview the Report made earlier, and note that the control now appears. For example, you should be able to read the caption ("ATL 3.0 : AccessTestCtrl") that you were unable to read before.NOTE: Access might crop the border of the metafile when displaying it.

REFERENCES

For additional information regarding ATL controls in Access, click the article number below to view the article in the Microsoft Knowledge Base:
197490  (http://kbalertz.com/Feedback.aspx?kbNumber=197490/EN-US/ ) PRB: ATL Full Control Needs Enabled Stock Property for Access 97

APPLIES TO
  • Microsoft ActiveX Template Library 3.0
  • Microsoft Access 2002 Standard Edition
  • Microsoft Access 2000 Standard Edition
  • Microsoft Access 97 Standard Edition
Keywords: 
kbctrlcreate kbprb KB242002
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please