1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22 // MfcControlCtl.cpp : Implementation of the CMfcControlCtrl ActiveX Control class.
23
24 #include "stdafx.h"
25 #include "MfcControl.h"
26 #include "MfcControlCtl.h"
27 #include "MfcControlPpg.h"
28
29
30 #ifdef _DEBUG
31 #define new DEBUG_NEW
32 #undef THIS_FILE
33 static char THIS_FILE[] = __FILE__;
34 #endif
35
36
37 IMPLEMENT_DYNCREATE(CMfcControlCtrl, COleControl)
38
39
40 /////////////////////////////////////////////////////////////////////////////
41 // Message map
42
43 BEGIN_MESSAGE_MAP(CMfcControlCtrl, COleControl)
44 //{{AFX_MSG_MAP(CMfcControlCtrl)
45 // NOTE - ClassWizard will add and remove message map entries
46 // DO NOT EDIT what you see in these blocks of generated code !
47 //}}AFX_MSG_MAP
48 ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
49 END_MESSAGE_MAP()
50
51
52 /////////////////////////////////////////////////////////////////////////////
53 // Dispatch map
54
55 BEGIN_DISPATCH_MAP(CMfcControlCtrl, COleControl)
56 //{{AFX_DISPATCH_MAP(CMfcControlCtrl)
57 DISP_FUNCTION(CMfcControlCtrl, "inShort", inShort, VT_I2, VTS_I2)
58 DISP_FUNCTION(CMfcControlCtrl, "inLong", inLong, VT_I4, VTS_I4)
59 DISP_FUNCTION(CMfcControlCtrl, "inString", inString, VT_BSTR, VTS_PBSTR)
60 DISP_FUNCTION(CMfcControlCtrl, "inFloat", inFloat, VT_R4, VTS_R4)
61 DISP_FUNCTION(CMfcControlCtrl, "inDouble", inDouble, VT_R8, VTS_R8)
62 DISP_FUNCTION(CMfcControlCtrl, "inVariant", inVariant, VT_VARIANT, VTS_VARIANT)
63 DISP_FUNCTION(CMfcControlCtrl, "inObject", inObject, VT_DISPATCH, VTS_DISPATCH)
64 DISP_FUNCTION(CMfcControlCtrl, "outShort", outShort, VT_EMPTY, VTS_PI2)
65 DISP_FUNCTION(CMfcControlCtrl, "outLong", outLong, VT_EMPTY, VTS_PI4)
66 DISP_FUNCTION(CMfcControlCtrl, "outString", outString, VT_EMPTY, VTS_PBSTR)
67 DISP_FUNCTION(CMfcControlCtrl, "outFloat", outFloat, VT_EMPTY, VTS_PR4)
68 DISP_FUNCTION(CMfcControlCtrl, "outDouble", outDouble, VT_EMPTY, VTS_PR8)
69 DISP_FUNCTION(CMfcControlCtrl, "outVariant", outVariant, VT_EMPTY, VTS_PVARIANT)
70 DISP_FUNCTION(CMfcControlCtrl, "outObject", outObject, VT_EMPTY, VTS_PDISPATCH)
71 //}}AFX_DISPATCH_MAP
72 END_DISPATCH_MAP()
73
74
75 /////////////////////////////////////////////////////////////////////////////
76 // Event map
77
78 BEGIN_EVENT_MAP(CMfcControlCtrl, COleControl)
79 //{{AFX_EVENT_MAP(CMfcControlCtrl)
80 // NOTE - ClassWizard will add and remove event map entries
81 // DO NOT EDIT what you see in these blocks of generated code !
82 //}}AFX_EVENT_MAP
83 END_EVENT_MAP()
84
85
86 /////////////////////////////////////////////////////////////////////////////
87 // Property pages
88
89 // TODO: Add more property pages as needed. Remember to increase the count!
90 BEGIN_PROPPAGEIDS(CMfcControlCtrl, 1)
91 PROPPAGEID(CMfcControlPropPage::guid)
92 END_PROPPAGEIDS(CMfcControlCtrl)
93
94
95 /////////////////////////////////////////////////////////////////////////////
96 // Initialize class factory and guid
97
98 IMPLEMENT_OLECREATE_EX(CMfcControlCtrl, "MFCCONTROL.MfcControlCtrl.1",
99 0xac221fb6, 0xa0d8, 0x11d4, 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4)
100
101
102 /////////////////////////////////////////////////////////////////////////////
103 // Type library ID and version
104
105 IMPLEMENT_OLETYPELIB(CMfcControlCtrl, _tlid, _wVerMajor, _wVerMinor)
106
107
108 /////////////////////////////////////////////////////////////////////////////
109 // Interface IDs
110
111 const IID BASED_CODE IID_DMfcControl =
112 { 0xac221fb4, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
113 const IID BASED_CODE IID_DMfcControlEvents =
114 { 0xac221fb5, 0xa0d8, 0x11d4, { 0x83, 0x3b, 0, 0x50, 0x4, 0x52, 0x6a, 0xb4 } };
115
116
117 /////////////////////////////////////////////////////////////////////////////
118 // Control type information
119
120 static const DWORD BASED_CODE _dwMfcControlOleMisc =
121 OLEMISC_ACTIVATEWHENVISIBLE |
122 OLEMISC_SETCLIENTSITEFIRST |
123 OLEMISC_INSIDEOUT |
124 OLEMISC_CANTLINKINSIDE |
125 OLEMISC_RECOMPOSEONRESIZE;
126
IMPLEMENT_OLECTLTYPE(CMfcControlCtrl,IDS_MFCCONTROL,_dwMfcControlOleMisc)127 IMPLEMENT_OLECTLTYPE(CMfcControlCtrl, IDS_MFCCONTROL, _dwMfcControlOleMisc)
128
129
130 /////////////////////////////////////////////////////////////////////////////
131 // CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry -
132 // Adds or removes system registry entries for CMfcControlCtrl
133
134 BOOL CMfcControlCtrl::CMfcControlCtrlFactory::UpdateRegistry(BOOL bRegister)
135 {
136 // TODO: Verify that your control follows apartment-model threading rules.
137 // Refer to MFC TechNote 64 for more information.
138 // If your control does not conform to the apartment-model rules, then
139 // you must modify the code below, changing the 6th parameter from
140 // afxRegApartmentThreading to 0.
141
142 if (bRegister)
143 return AfxOleRegisterControlClass(
144 AfxGetInstanceHandle(),
145 m_clsid,
146 m_lpszProgID,
147 IDS_MFCCONTROL,
148 IDB_MFCCONTROL,
149 afxRegApartmentThreading,
150 _dwMfcControlOleMisc,
151 _tlid,
152 _wVerMajor,
153 _wVerMinor);
154 else
155 return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
156 }
157
158
159 /////////////////////////////////////////////////////////////////////////////
160 // CMfcControlCtrl::CMfcControlCtrl - Constructor
161
CMfcControlCtrl()162 CMfcControlCtrl::CMfcControlCtrl()
163 {
164 InitializeIIDs(&IID_DMfcControl, &IID_DMfcControlEvents);
165
166 // TODO: Initialize your control's instance data here.
167 }
168
169
170 /////////////////////////////////////////////////////////////////////////////
171 // CMfcControlCtrl::~CMfcControlCtrl - Destructor
172
~CMfcControlCtrl()173 CMfcControlCtrl::~CMfcControlCtrl()
174 {
175 // TODO: Cleanup your control's instance data here.
176 }
177
178
179 /////////////////////////////////////////////////////////////////////////////
180 // CMfcControlCtrl::OnDraw - Drawing function
181
OnDraw(CDC * pdc,const CRect & rcBounds,const CRect & rcInvalid)182 void CMfcControlCtrl::OnDraw(
183 CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
184 {
185 // TODO: Replace the following code with your own drawing code.
186 pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH)));
187 pdc->Ellipse(rcBounds);
188 }
189
190
191 /////////////////////////////////////////////////////////////////////////////
192 // CMfcControlCtrl::DoPropExchange - Persistence support
193
DoPropExchange(CPropExchange * pPX)194 void CMfcControlCtrl::DoPropExchange(CPropExchange* pPX)
195 {
196 ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
197 COleControl::DoPropExchange(pPX);
198
199 // TODO: Call PX_ functions for each persistent custom property.
200
201 }
202
203
204 /////////////////////////////////////////////////////////////////////////////
205 // CMfcControlCtrl::OnResetState - Reset control to default state
206
OnResetState()207 void CMfcControlCtrl::OnResetState()
208 {
209 COleControl::OnResetState(); // Resets defaults found in DoPropExchange
210
211 // TODO: Reset any other control state here.
212 }
213
214
215 /////////////////////////////////////////////////////////////////////////////
216 // CMfcControlCtrl message handlers
217
218
inShort(short val)219 short CMfcControlCtrl::inShort(short val)
220 {
221 char buf[256];
222 sprintf( buf, "inByte: value= %d", val);
223 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
224 return val+1;
225 }
226
inLong(long val)227 long CMfcControlCtrl::inLong(long val)
228 {
229 char buf[256];
230 sprintf( buf, "inLong: value= %d", val);
231 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
232 return val+1;
233 }
234
inString(BSTR * val)235 BSTR CMfcControlCtrl::inString(BSTR* val)
236 {
237 CString strResult;
238 strResult= *val;
239 char buf[256];
240 sprintf( buf, "inString: value= %S", *val);
241 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
242 strResult += L" an appended string";
243 return strResult.AllocSysString();
244 }
245
inFloat(float val)246 float CMfcControlCtrl::inFloat(float val)
247 {
248 char buf[256];
249 sprintf( buf, "inFloat: value= %f", val);
250 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
251 return val+1;
252 }
253
inDouble(double val)254 double CMfcControlCtrl::inDouble(double val)
255 {
256 char buf[256];
257 sprintf( buf, "inDouble: value= %g", val);
258 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
259 return val+1;
260 }
261
inVariant(const VARIANT FAR & val)262 VARIANT CMfcControlCtrl::inVariant(const VARIANT FAR& val)
263 {
264 VARIANT vaResult;
265 VariantInit(&vaResult);
266 VariantCopyInd( &vaResult, const_cast<VARIANT*>(&val));
267 if( vaResult.vt == VT_BSTR)
268 {
269 char buf[256];
270 sprintf( buf, "inVariant: value= %S", vaResult.bstrVal);
271 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
272
273 }
274 return _variant_t( L" a string from CMfcControlCtrl::inVariant");
275 }
276
inObject(LPDISPATCH val)277 LPDISPATCH CMfcControlCtrl::inObject(LPDISPATCH val)
278 {
279 char buf[256];
280 _bstr_t bstr;
281 HRESULT hr= S_OK;
282 COleVariant var;
283 DISPID id;
284 OLECHAR* name=L"prpString";
285 if( SUCCEEDED(hr= val->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
286 {
287 DISPPARAMS params={0,0,0,0};
288 hr= val->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, ¶ms, &var,0,0);
289
290 }
291
292 if( var.vt== VT_BSTR)
293 bstr= var.bstrVal;
294 sprintf( buf, "inObject: value= %S", (wchar_t*)bstr);
295 ::MessageBoxA( NULL, buf, "MFCCONTROL.MfcControl", MB_OK);
296
297 return NULL;
298 }
299
300
outShort(short * val)301 void CMfcControlCtrl::outShort(short* val)
302 {
303 *val= 123;
304 }
305
outLong(long * val)306 void CMfcControlCtrl::outLong(long* val)
307 {
308 *val= 1234;
309 }
310
outString(BSTR FAR * val)311 void CMfcControlCtrl::outString(BSTR FAR* val)
312 {
313 *val= SysAllocString(L"A string from CMfcControlCtrl::outString ");
314 }
315
outFloat(float * val)316 void CMfcControlCtrl::outFloat(float* val)
317 {
318 *val= 3.14f;
319 }
320
outDouble(double * val)321 void CMfcControlCtrl::outDouble(double* val)
322 {
323 *val= 3.145;
324 }
325
outVariant(VARIANT FAR * val)326 void CMfcControlCtrl::outVariant(VARIANT FAR* val)
327 {
328 VariantInit( val);
329 val->vt= VT_BSTR;
330 val->bstrVal= SysAllocString( L"a string in a VARIANT");
331 }
332
outObject(LPDISPATCH FAR * val)333 void CMfcControlCtrl::outObject(LPDISPATCH FAR* val)
334 {
335 //{BFE10EBE-8584-11D4-005004526AB4}
336 HRESULT hr= S_OK;
337 CLSID clsTestControl;
338 hr= CLSIDFromProgID( L"AxTestComponents.Basic", &clsTestControl);
339
340 IDispatch* pDisp= NULL;
341 hr= CoCreateInstance( clsTestControl, NULL, CLSCTX_ALL, __uuidof(IDispatch), (void**)&pDisp);
342
343 if( SUCCEEDED( hr) && val)
344 {
345 COleVariant var;
346 DISPID id;
347 OLECHAR* name=L"prpString";
348 if( SUCCEEDED(hr= pDisp->GetIDsOfNames( IID_NULL, &name, 1, LOCALE_USER_DEFAULT, &id)))
349 {
350 COleVariant vaParam1(_T("this is property prpString of AxTestComponents.Basic"));
351 DISPID dispidPut= DISPID_PROPERTYPUT;
352 DISPPARAMS params;
353 params.cArgs= 1;
354 params.cNamedArgs= 1;
355 params.rgdispidNamedArgs= &dispidPut;
356 params.rgvarg= &vaParam1;
357
358 hr= pDisp->Invoke( id, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYPUT, ¶ms, &var,0,0);
359 *val= pDisp;
360 }
361
362 }
363
364 }
365 // VT_I1
366