1 // MfcControlCtl.cpp : Implementation of the CMfcControlCtrl ActiveX Control class.
4 #include "MfcControl.h"
5 #include "MfcControlCtl.h"
6 #include "MfcControlPpg.h"
12 static char THIS_FILE
[] = __FILE__
;
16 IMPLEMENT_DYNCREATE(CMfcControlCtrl
, COleControl
)
19 /////////////////////////////////////////////////////////////////////////////
22 BEGIN_MESSAGE_MAP(CMfcControlCtrl
, COleControl
)
23 //{{AFX_MSG_MAP(CMfcControlCtrl)
24 // NOTE - ClassWizard will add and remove message map entries
25 // DO NOT EDIT what you see in these blocks of generated code !
27 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES
, OnProperties
)
31 /////////////////////////////////////////////////////////////////////////////
34 BEGIN_DISPATCH_MAP(CMfcControlCtrl
, COleControl
)
35 //{{AFX_DISPATCH_MAP(CMfcControlCtrl)
36 DISP_FUNCTION(CMfcControlCtrl
, "inShort", inShort
, VT_I2
, VTS_I2
)
37 DISP_FUNCTION(CMfcControlCtrl
, "inLong", inLong
, VT_I4
, VTS_I4
)
38 DISP_FUNCTION(CMfcControlCtrl
, "inString", inString
, VT_BSTR
, VTS_PBSTR
)
39 DISP_FUNCTION(CMfcControlCtrl
, "inFloat", inFloat
, VT_R4
, VTS_R4
)
40 DISP_FUNCTION(CMfcControlCtrl
, "inDouble", inDouble
, VT_R8
, VTS_R8
)
41 DISP_FUNCTION(CMfcControlCtrl
, "inVariant", inVariant
, VT_VARIANT
, VTS_VARIANT
)
42 DISP_FUNCTION(CMfcControlCtrl
, "inObject", inObject
, VT_DISPATCH
, VTS_DISPATCH
)
43 DISP_FUNCTION(CMfcControlCtrl
, "outShort", outShort
, VT_EMPTY
, VTS_PI2
)
44 DISP_FUNCTION(CMfcControlCtrl
, "outLong", outLong
, VT_EMPTY
, VTS_PI4
)
45 DISP_FUNCTION(CMfcControlCtrl
, "outString", outString
, VT_EMPTY
, VTS_PBSTR
)
46 DISP_FUNCTION(CMfcControlCtrl
, "outFloat", outFloat
, VT_EMPTY
, VTS_PR4
)
47 DISP_FUNCTION(CMfcControlCtrl
, "outDouble", outDouble
, VT_EMPTY
, VTS_PR8
)
48 DISP_FUNCTION(CMfcControlCtrl
, "outVariant", outVariant
, VT_EMPTY
, VTS_PVARIANT
)
49 DISP_FUNCTION(CMfcControlCtrl
, "outObject", outObject
, VT_EMPTY
, VTS_PDISPATCH
)
54 /////////////////////////////////////////////////////////////////////////////
57 BEGIN_EVENT_MAP(CMfcControlCtrl
, COleControl
)
58 //{{AFX_EVENT_MAP(CMfcControlCtrl)
59 // NOTE - ClassWizard will add and remove event map entries
60 // DO NOT EDIT what you see in these blocks of generated code !
65 /////////////////////////////////////////////////////////////////////////////
68 // TODO: Add more property pages as needed. Remember to increase the count!
69 BEGIN_PROPPAGEIDS(CMfcControlCtrl
, 1)
70 PROPPAGEID(CMfcControlPropPage::guid
)
71 END_PROPPAGEIDS(CMfcControlCtrl
)
74 /////////////////////////////////////////////////////////////////////////////
75 // Initialize class factory and guid
77 IMPLEMENT_OLECREATE_EX(CMfcControlCtrl
, "MFCCONTROL.MfcControlCtrl.1",
78 0xac221fb6, 0xa0d8, 0x11d4, 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4)
81 /////////////////////////////////////////////////////////////////////////////
82 // Type library ID and version
84 IMPLEMENT_OLETYPELIB(CMfcControlCtrl
, _tlid
, _wVerMajor
, _wVerMinor
)
87 /////////////////////////////////////////////////////////////////////////////
90 const IID BASED_CODE IID_DMfcControl
=
91 { 0xac221fb4, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
92 const IID BASED_CODE IID_DMfcControlEvents
=
93 { 0xac221fb5, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
96 /////////////////////////////////////////////////////////////////////////////
97 // Control type information
99 static const DWORD BASED_CODE _dwMfcControlOleMisc
=
100 OLEMISC_ACTIVATEWHENVISIBLE
|
101 OLEMISC_SETCLIENTSITEFIRST
|
103 OLEMISC_CANTLINKINSIDE
|
104 OLEMISC_RECOMPOSEONRESIZE
;
106 IMPLEMENT_OLECTLTYPE(CMfcControlCtrl
, IDS_MFCCONTROL
, _dwMfcControlOleMisc
)
109 /////////////////////////////////////////////////////////////////////////////
110 // CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry -
111 // Adds or removes system registry entries for CMfcControlCtrl
113 BOOL
CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry(BOOL bRegister
)
115 // TODO: Verify that your control follows apartment-model threading rules.
116 // Refer to MFC TechNote 64 for more information.
117 // If your control does not conform to the apartment-model rules, then
118 // you must modify the code below, changing the 6th parameter from
119 // afxRegApartmentThreading to 0.
122 return AfxOleRegisterControlClass(
123 AfxGetInstanceHandle(),
128 afxRegApartmentThreading
,
129 _dwMfcControlOleMisc
,
134 return AfxOleUnregisterClass(m_clsid
, m_lpszProgID
);
138 /////////////////////////////////////////////////////////////////////////////
139 // CMfcControlCtrl::CMfcControlCtrl - Constructor
141 CMfcControlCtrl::CMfcControlCtrl()
143 InitializeIIDs(&IID_DMfcControl
, &IID_DMfcControlEvents
);
145 // TODO: Initialize your control's instance data here.
149 /////////////////////////////////////////////////////////////////////////////
150 // CMfcControlCtrl::~CMfcControlCtrl - Destructor
152 CMfcControlCtrl::~CMfcControlCtrl()
154 // TODO: Cleanup your control's instance data here.
158 /////////////////////////////////////////////////////////////////////////////
159 // CMfcControlCtrl::OnDraw - Drawing function
161 void CMfcControlCtrl::OnDraw(
162 CDC
* pdc
, const CRect
& rcBounds
, const CRect
& rcInvalid
)
164 // TODO: Replace the following code with your own drawing code.
165 pdc
->FillRect(rcBounds
, CBrush::FromHandle((HBRUSH
)GetStockObject(WHITE_BRUSH
)));
166 pdc
->Ellipse(rcBounds
);
170 /////////////////////////////////////////////////////////////////////////////
171 // CMfcControlCtrl::DoPropExchange - Persistence support
173 void CMfcControlCtrl::DoPropExchange(CPropExchange
* pPX
)
175 ExchangeVersion(pPX
, MAKELONG(_wVerMinor
, _wVerMajor
));
176 COleControl::DoPropExchange(pPX
);
178 // TODO: Call PX_ functions for each persistent custom property.
183 /////////////////////////////////////////////////////////////////////////////
184 // CMfcControlCtrl::OnResetState - Reset control to default state
186 void CMfcControlCtrl::OnResetState()
188 COleControl::OnResetState(); // Resets defaults found in DoPropExchange
190 // TODO: Reset any other control state here.
194 /////////////////////////////////////////////////////////////////////////////
195 // CMfcControlCtrl message handlers
198 short CMfcControlCtrl::inShort(short val
)
201 sprintf( buf
, "inByte: value= %d", val
);
202 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
206 long CMfcControlCtrl::inLong(long val
)
209 sprintf( buf
, "inLong: value= %d", val
);
210 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
214 BSTR
CMfcControlCtrl::inString(BSTR
* val
)
219 sprintf( buf
, "inString: value= %S", *val
);
220 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
221 strResult
+= L
" an appended string";
222 return strResult
.AllocSysString();
225 float CMfcControlCtrl::inFloat(float val
)
228 sprintf( buf
, "inFloat: value= %f", val
);
229 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
233 double CMfcControlCtrl::inDouble(double val
)
236 sprintf( buf
, "inDouble: value= %g", val
);
237 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
241 VARIANT
CMfcControlCtrl::inVariant(const VARIANT FAR
& val
)
244 VariantInit(&vaResult
);
245 VariantCopyInd( &vaResult
, const_cast<VARIANT
*>(&val
));
246 if( vaResult
.vt
== VT_BSTR
)
249 sprintf( buf
, "inVariant: value= %S", vaResult
.bstrVal
);
250 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
253 return _variant_t( L
" a string from CMfcControlCtrl::inVariant");
256 LPDISPATCH
CMfcControlCtrl::inObject(LPDISPATCH val
)
263 OLECHAR
* name
=L
"prpString";
264 if( SUCCEEDED(hr
= val
->GetIDsOfNames( IID_NULL
, &name
, 1, LOCALE_USER_DEFAULT
, &id
)))
266 DISPPARAMS params
={0,0,0,0};
267 hr
= val
->Invoke( id
, IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
, ¶ms
, &var
,0,0);
271 if( var
.vt
== VT_BSTR
)
273 sprintf( buf
, "inObject: value= %S", (wchar_t*)bstr
);
274 ::MessageBoxA( NULL
, buf
, "MFCCONTROL.MfcControl", MB_OK
);
280 void CMfcControlCtrl::outShort(short* val
)
285 void CMfcControlCtrl::outLong(long* val
)
290 void CMfcControlCtrl::outString(BSTR FAR
* val
)
292 *val
= SysAllocString(L
"A string from CMfcControlCtrl::outString ");
295 void CMfcControlCtrl::outFloat(float* val
)
300 void CMfcControlCtrl::outDouble(double* val
)
305 void CMfcControlCtrl::outVariant(VARIANT FAR
* val
)
309 val
->bstrVal
= SysAllocString( L
"a string in a VARIANT");
312 void CMfcControlCtrl::outObject(LPDISPATCH FAR
* val
)
314 //{BFE10EBE-8584-11D4-005004526AB4}
316 CLSID clsTestControl
;
317 hr
= CLSIDFromProgID( L
"AxTestComponents.Basic", &clsTestControl
);
319 IDispatch
* pDisp
= NULL
;
320 hr
= CoCreateInstance( clsTestControl
, NULL
, CLSCTX_ALL
, __uuidof(IDispatch
), (void**)&pDisp
);
322 if( SUCCEEDED( hr
) && val
)
326 OLECHAR
* name
=L
"prpString";
327 if( SUCCEEDED(hr
= pDisp
->GetIDsOfNames( IID_NULL
, &name
, 1, LOCALE_USER_DEFAULT
, &id
)))
329 COleVariant
vaParam1(_T("this is property prpString of AxTestComponents.Basic"));
330 DISPID dispidPut
= DISPID_PROPERTYPUT
;
333 params
.cNamedArgs
= 1;
334 params
.rgdispidNamedArgs
= &dispidPut
;
335 params
.rgvarg
= &vaParam1
;
337 hr
= pDisp
->Invoke( id
, IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
, ¶ms
, &var
,0,0);