ATL 9.0 displayed in the middle of an Activex control

Recently a customer of mine faced this issue. So he had an ActiveX control and when displaying the ActiveX control in browser a string is displayed right in the middle of the control: “ATL 9.0”.

So this issue happens because you didn’t override CComControlBase::OnDraw  function. The default code for CComControlBase::OnDraw looks like the following…

[sourcecode language=”cpp”]HRESULT CComControlBase::YourClassName::OnDraw(_In_ ATL_DRAWINFO& di)
{
  ::SetTextAlign(di.hdcDraw, TA_CENTER|TA_BASELINE);
  LPCTSTR pszText = _T("ATL ") _T(_ATL_VER_RBLD); // "ATL 9.0"
  ::TextOut(di.hdcDraw,
            di.prcBounds->left + (di.prcBounds->right – di.prcBounds->left) / 2,
            di.prcBounds->top + (di.prcBounds->bottom – di.prcBounds->top) / 2,
            pszText,
            lstrlen(pszText)); 
return S_OK;
}[/sourcecode]

MSDN documentation for CComControlBase::OnDraw function confirms this behavior. Quote…

The wizard’s default OnDraw draws a rectangle with the label “ATL 8.0”.

The solution for this is to override CComControlBase::OnDraw function in your derived class and provide your own drawing or just return S_OK.

Appreciate your comments...