HOWTO: Define the Display Size of an MFC ActiveX ControlLast reviewed: July 31, 1997Article ID: Q168326 |
The information in this article applies to:
SUMMARYSometimes you need to limit an ActiveX control's minimum or maximum size at design time. This article explains how to do this by overriding the virtual COleControl::OnSetExtent method.
MORE INFORMATIONThe COleControl::OnSetExtent method is called by COleControl::XOleObject::SetExtent. COleControl::XOleObject is COleControl’s IOleObject implementation. A container calls IOleObject::SetExtent when it needs to dictate to an embedded object the size at which it will be displayed. COleControl::OnSetExtent takes one parameter, a pointer to a SizeL structure. The SizeL structure contains the new size that the container is requesting for the control in HIMETRIC units. If a you need to limit a control to a certain size, you need to make it override COleControl::OnSetExtent and do the following:
Sample CodeThe following code snippet shows how to override COleControl::OnSetExtent so that the height of the control will never be smaller than 20 pixels.
BOOL CTestCtrl::OnSetExtent(LPSIZEL lpSizeL) { // This function limits the height of a control to be at // least 20 pixels. // Use the desktop window to get a DC so we can use // CDC::HIMETRICtoDP and CDC::DPtoHIMETRIC CWnd *pWnd = CWnd::FromHandle(::GetDesktopWindow()); CClientDC dc(pWnd); CSize sz(lpSizeL->cx,lpSizeL->cy); dc.HIMETRICtoDP(&sz); //Convert the size to pixels if (sz.cy < 20) { TRACE("%ld\n",sz.cy); //size is less than 20, set it to 20 sz.cy = 20; dc.DPtoHIMETRIC(&sz);//re-convert to HIMETRIC lpSizeL->cy = sz.cy; } else { TRACE("%ld\n",sz.cy); //no conversion necessary } return COleControl::OnSetExtent(lpSizeL); } REFERENCESAn ActiveX control may be defined to be the size of the dialog template from which it was created. For additional information, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q155973 TITLE : SAMPLE: Create an ActiveX Control with a Dialog Resource |
Additional query words: ocx
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |