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