Let the ActiveX control design status locked in the container!

zhaozj2021-02-08  229

Let the ActiveX control design status lock in the container in the container, you can use the following macro, the macro is a window-free ActiveX control, compiled successfully under VC . Net (ATL7.0).

#ifndef __control_no_window_with_icon __ # define __control_no_window_with_icon__

#include

/ * This macro implements a windowless control when the design mode shows a small icon under the design window, the window size is fixed icon size

This macro inherits the four functions of the control setObjectRects Some containers must specify this function to specify the window size GetExtent container to the control query window size onDRAW to draw icons

Parameters: ID nCx icon classControl control class name iconID icon (control window) width nCY icon (control window) height * / # define CONTROL_NO_WINDOW_WITH_ICON (classControl, iconID, nCx, nCy) / public: / STDMETHOD (SetObjectRects) (LPCRECT prcPos, LPCRect prcClip) / {/ csize size (prcpos-> right - prcpos-> left, prcpos-> bottom - prcpos-> top); / / if (size.cx! = Ncx || size.cy! = Ncy) / {/ m_spInPlaceSite-> OnPosRectChange (CRect (prcPos-> left, prcPos-> top, prcPos-> left nCx, prcPos-> top nCy)); / return S_OK; /} / / IOleInPlaceObjectWindowlessImpl :: SetObjectRects (prcPos, prcClip); / / return S_OK; /} / / STDMETHOD (getExtent) (DWORD dwDrawAspect, LONG lindex, DVTARGETDEVICE * ptd, lPSIZEL lpsizel) / {/ HRESULT hr = IViewObjectExImpl :: getExtent (dwDrawAspect, lindex , PTD, LPSIZEL); / / CSIZE SIZEPEL (NCX, NCY); / CSIZE SizeNew; / AtlpixeltoHimetric (& Sizepixel, & SizeNew); / / if (hr == s_ok) / {/ lpsizel-> cx = sizenew.cx; / LPSIZEL-> cy = Sizenew.cy; /} / return hr; /} / / stdmethod (GetExtent) (DWORD dwDrawAspect, LPSIZEL lpsizel) / {/ HRESULT hr = IOleObjectImpl :: GetExtent (dwDrawAspect, lpsizel); / / CSize sizePixel (nCx, nCy); / CSize sizeNew; / AtlPixelToHiMetric (& sizePixel, & sizeNew) ; / / If (hr == s_ok) / {/ lpsizel-> cx = sizenew.cx; / lpsizel-> cy = sizenew.cy; /} / return hr; /} / / hResult OnDRAW (ATL_DRAWINFO & DI) / { / OLE_COLOR colorOle; / GetAmbientBackColor (colorOle); / COLORREF colorRgb; / :: OleTranslateColor (colorOle, 0, & colorRgb); / HBRUSH hBrush; / hBrush = CreateSolidBrush (colorRgb); / RECT & rc =

* (RECT *) di.prcBounds; / FillRect (di.hdcDraw, & rc, hBrush); / DeleteObject (hBrush); / SetBkMode (di.hdcDraw, TRANSPARENT); hIcon / HICON = LoadIcon (_AtlBaseModule.GetResourceInstance (), MAKEINTRESOURCE (iCONID)); / Drawicon (Di.hdcdraw, rc.left, rc.top, hic); / deleteObject (hic); / / RETURN S_OK; /} #ENDIF / / __CON_NO_WINDOW_WITH_ICON__

转载请注明原文地址:https://www.9cbs.com/read-2947.html

New Post(0)