// [!output CONTROL_IMPL] : Implementation of the [!output CONTROL_CLASS] ActiveX Control class. #include "stdafx.h" #include "[!output PROJECT_NAME].h" #include "[!output CONTROL_HEADER]" #include "[!output PROPERTY_PAGE_HEADER]" #ifdef _DEBUG #define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE([!output CONTROL_CLASS], COleControl) // Message map BEGIN_MESSAGE_MAP([!output CONTROL_CLASS], COleControl) [!if SUBCLASS_WINDOW] ON_MESSAGE(OCM_COMMAND, &[!output CONTROL_CLASS]::OnOcmCommand) [!endif] [!if INSERTABLE] ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit) [!endif] ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties) END_MESSAGE_MAP() // Dispatch map BEGIN_DISPATCH_MAP([!output CONTROL_CLASS], COleControl) [!if ASYNC_PROPERTY_LOAD] DISP_STOCKPROP_READYSTATE() [!endif] [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] [!if ABOUT_BOX] DISP_FUNCTION_ID([!output CONTROL_CLASS], "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) [!endif] [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] [!if ABOUT_BOX] DISP_FUNCTION_ID([!output CONTROL_CLASS], "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) [!endif] [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] END_DISPATCH_MAP() // Event map BEGIN_EVENT_MAP([!output CONTROL_CLASS], COleControl) [!if ASYNC_PROPERTY_LOAD] EVENT_STOCK_READYSTATECHANGE() [!endif] END_EVENT_MAP() // Property pages // TODO: Add more property pages as needed. Remember to increase the count! BEGIN_PROPPAGEIDS([!output CONTROL_CLASS], 1) PROPPAGEID([!output PROPERTY_PAGE_CLASS]::guid) END_PROPPAGEIDS([!output CONTROL_CLASS]) // Initialize class factory and guid IMPLEMENT_OLECREATE_EX([!output CONTROL_CLASS], "[!output CONTROL_TYPE_ID]", [!output CONTROL_CLSID_IMPLEMENT_OLECREATE_FORMAT]) // Type library ID and version IMPLEMENT_OLETYPELIB([!output CONTROL_CLASS], _tlid, _wVerMajor, _wVerMinor) // Interface IDs const IID BASED_CODE IID_D[!output SAFE_PROJECT_IDENTIFIER_NAME] = [!output PRIMARY_IID_STATIC_CONST_GUID_FORMAT]; const IID BASED_CODE IID_D[!output SAFE_PROJECT_IDENTIFIER_NAME]Events = [!output EVENT_IID_STATIC_CONST_GUID_FORMAT]; // Control type information static const DWORD BASED_CODE _dw[!output SAFE_PROJECT_IDENTIFIER_NAME]OleMisc = [!if SIMPLE_FRAME] OLEMISC_SIMPLEFRAME | [!endif] [!if INVISIBLE_AT_RUNTIME] OLEMISC_INVISIBLEATRUNTIME | [!endif] [!if ACTIVATE_WHEN_VISIBLE] OLEMISC_ACTIVATEWHENVISIBLE | [!if MOUSE_NOTIFICATIONS] OLEMISC_IGNOREACTIVATEWHENVISIBLE | [!endif] [!endif] OLEMISC_SETCLIENTSITEFIRST | OLEMISC_INSIDEOUT | OLEMISC_CANTLINKINSIDE | OLEMISC_RECOMPOSEONRESIZE; IMPLEMENT_OLECTLTYPE([!output CONTROL_CLASS], IDS_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], _dw[!output SAFE_PROJECT_IDENTIFIER_NAME]OleMisc) BEGIN_INTERFACE_MAP([!output CONTROL_CLASS], COleControl) INTERFACE_PART([!output CONTROL_CLASS], IID_IObjectSafety, ObjectSafety) END_INTERFACE_MAP() // [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::UpdateRegistry - // Adds or removes system registry entries for [!output CONTROL_CLASS] BOOL [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::UpdateRegistry(BOOL bRegister) { #ifndef _CE_DCOM int nRegFlags = afxRegFreeThreading; #else int nRegFlags = afxRegApartmentThreading; #endif // !_CE_DCOM if (bRegister) return AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], IDB_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], [!if INSERTABLE] afxRegInsertable | nRegFlags, [!else] nRegFlags, [!endif] _dw[!output SAFE_PROJECT_IDENTIFIER_NAME]OleMisc, _tlid, _wVerMajor, _wVerMinor); else return AfxOleUnregisterClass(m_clsid, m_lpszProgID); } [!if RUNTIME_LICENSE] // Licensing strings static const TCHAR BASED_CODE _szLicFileName[] = _T("[!output PROJECT_NAME].lic"); static const WCHAR BASED_CODE _szLicString[] = L"Copyright (c) [!output YEAR] [!output COMPANY_NAME]"; // [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::VerifyUserLicense - // Checks for existence of a user license BOOL [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::VerifyUserLicense() { return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName, _szLicString); } // [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::GetLicenseKey - // Returns a runtime licensing key BOOL [!output CONTROL_CLASS]::[!output CONTROL_CLASS]Factory::GetLicenseKey(DWORD dwReserved, BSTR FAR* pbstrKey) { if (pbstrKey == NULL) return FALSE; *pbstrKey = SysAllocString(_szLicString); return (*pbstrKey != NULL); } [!endif] // [!output CONTROL_CLASS]::[!output CONTROL_CLASS] - Constructor [!output CONTROL_CLASS]::[!output CONTROL_CLASS]() { // TODO: Set proper value for properties m_dwCurrentSafety and m_dwSupportedSafety when needed. // Could be either INTERFACESAFE_FOR_UNTRUSTED_DATA or INTERFACESAFE_FOR_UNTRUSTED_CALLER or both, // depending on the real world scenario. m_dwCurrentSafety = 0; m_dwSupportedSafety = 0; InitializeIIDs(&IID_D[!output SAFE_PROJECT_IDENTIFIER_NAME], &IID_D[!output SAFE_PROJECT_IDENTIFIER_NAME]Events); [!if SIMPLE_FRAME] EnableSimpleFrame(); [!endif] [!if ASYNC_PROPERTY_LOAD] m_lReadyState = READYSTATE_LOADING; // TODO: Call InternalSetReadyState when the readystate changes. [!endif] // TODO: Initialize your control's instance data here. } // [!output CONTROL_CLASS]::~[!output CONTROL_CLASS] - Destructor [!output CONTROL_CLASS]::~[!output CONTROL_CLASS]() { // TODO: Cleanup your control's instance data here. } // [!output CONTROL_CLASS]::OnDraw - Drawing function void [!output CONTROL_CLASS]::OnDraw( CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid) { if (!pdc) return; [!if SUBCLASS_WINDOW] DoSuperclassPaint(pdc, rcBounds); [!else] // TODO: Replace the following code with your own drawing code. pdc->FillRect(rcBounds, CBrush::FromHandle((HBRUSH)GetStockObject(WHITE_BRUSH))); pdc->Ellipse(rcBounds); [!endif] [!if OPTIMIZED_DRAW] if (!IsOptimizedDraw()) { // The container does not support optimized drawing. // TODO: if you selected any GDI objects into the device context *pdc, // restore the previously-selected objects here. } [!endif] } // [!output CONTROL_CLASS]::DoPropExchange - Persistence support void [!output CONTROL_CLASS]::DoPropExchange(CPropExchange* pPX) { ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor)); COleControl::DoPropExchange(pPX); // TODO: Call PX_ functions for each persistent custom property. } [!if WINDOWLESS || UNCLIPPED_DEVICE_CONTEXT || FLICKER_FREE || MOUSE_NOTIFICATIONS || OPTIMIZED_DRAW] // [!output CONTROL_CLASS]::GetControlFlags - // Flags to customize MFC's implementation of ActiveX controls. // DWORD [!output CONTROL_CLASS]::GetControlFlags() { DWORD dwFlags = COleControl::GetControlFlags(); [!if UNCLIPPED_DEVICE_CONTEXT] // The control's output is not being clipped. // The control guarantees that it will not paint outside its // client rectangle. dwFlags &= ~clipPaintDC; [!endif] [!if WINDOWLESS] // The control can activate without creating a window. // TODO: when writing the control's message handlers, avoid using // the m_hWnd member variable without first checking that its // value is non-NULL. dwFlags |= windowlessActivate; [!endif] [!if FLICKER_FREE] // The control will not be redrawn when making the transition // between the active and inactivate state. dwFlags |= noFlickerActivate; [!endif] [!if MOUSE_NOTIFICATIONS] // The control can receive mouse notifications when inactive. // TODO: if you write handlers for WM_SETCURSOR and WM_MOUSEMOVE, // avoid using the m_hWnd member variable without first // checking that its value is non-NULL. dwFlags |= pointerInactive; [!endif] [!if OPTIMIZED_DRAW] // The control can optimize its OnDraw method, by not restoring // the original GDI objects in the device context. dwFlags |= canOptimizeDraw; [!endif] return dwFlags; } [!endif] // [!output CONTROL_CLASS]::OnResetState - Reset control to default state void [!output CONTROL_CLASS]::OnResetState() { COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here. } [!if !MULTIPLE_PLATFORM] [!if !SMARTPHONE2003_UI_MODEL] [!if ABOUT_BOX] // [!output CONTROL_CLASS]::AboutBox - Display an "About" box to the user void [!output CONTROL_CLASS]::AboutBox() { #ifdef _DEVICE_RESOLUTION_AWARE CDialog dlgAbout(IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]_WIDE); #else CDialog dlgAbout(IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]); #endif dlgAbout.DoModal(); } [!endif] [!endif] [!else] [!if SMARTPHONE2003_UI_MODEL] #ifndef WIN32_PLATFORM_WFSP [!endif] [!if ABOUT_BOX] // [!output CONTROL_CLASS]::AboutBox - Display an "About" box to the user void [!output CONTROL_CLASS]::AboutBox() { #ifdef _DEVICE_RESOLUTION_AWARE CDialog dlgAbout(IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME], IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]_WIDE); #else CDialog dlgAbout(IDD_ABOUTBOX_[!output UPPER_CASE_SAFE_PROJECT_IDENTIFIER_NAME]); #endif dlgAbout.DoModal(); } [!endif] [!if SMARTPHONE2003_UI_MODEL] #endif // !WIN32_PLATFORM_WFSP [!endif] [!endif] [!if SUBCLASS_WINDOW] // [!output CONTROL_CLASS]::PreCreateWindow - Modify parameters for CreateWindowEx BOOL [!output CONTROL_CLASS]::PreCreateWindow(CREATESTRUCT& cs) { [!if SUBCLASS_WINDOW] cs.lpszClass = _T("[!output WINDOW_CLASS]"); [!else] // TODO: Fill in the name of the window class to be subclassed. cs.lpszClass = _T(""); [!endif] return COleControl::PreCreateWindow(cs); } // [!output CONTROL_CLASS]::IsSubclassedControl - This is a subclassed control BOOL [!output CONTROL_CLASS]::IsSubclassedControl() { return TRUE; } // [!output CONTROL_CLASS]::OnOcmCommand - Handle command messages LRESULT [!output CONTROL_CLASS]::OnOcmCommand(WPARAM wParam, LPARAM lParam) { #ifdef _WIN32 WORD wNotifyCode = HIWORD(wParam); #else WORD wNotifyCode = HIWORD(lParam); #endif // TODO: Switch on wNotifyCode here. return 0; } [!endif] // [!output CONTROL_CLASS] message handlers // [!output CONTROL_CLASS]::XObjectSafety STDMETHODIMP_(ULONG) [!output CONTROL_CLASS]::XObjectSafety::AddRef() { METHOD_PROLOGUE_EX_([!output CONTROL_CLASS], ObjectSafety) return (ULONG)pThis->ExternalAddRef(); } STDMETHODIMP_(ULONG) [!output CONTROL_CLASS]::XObjectSafety::Release() { METHOD_PROLOGUE_EX_([!output CONTROL_CLASS], ObjectSafety) return (ULONG)pThis->ExternalRelease(); } STDMETHODIMP [!output CONTROL_CLASS]::XObjectSafety::QueryInterface( REFIID iid, LPVOID* ppvObj) { METHOD_PROLOGUE_EX_([!output CONTROL_CLASS], ObjectSafety) return (HRESULT)pThis->ExternalQueryInterface(&iid, ppvObj); } STDMETHODIMP [!output CONTROL_CLASS]::XObjectSafety::GetInterfaceSafetyOptions(REFIID riid, DWORD *pdwSupportedOptions, DWORD *pdwEnabledOptions) { METHOD_PROLOGUE_EX_([!output CONTROL_CLASS], ObjectSafety) if (pdwSupportedOptions == NULL || pdwEnabledOptions == NULL) return E_POINTER; // Check if we support this interface IUnknown* pUnk; HRESULT hr = this->QueryInterface(riid, (void**)&pUnk); if (SUCCEEDED(hr)) { // We support this interface so set the safety options accordingly *pdwSupportedOptions = pThis->m_dwSupportedSafety; *pdwEnabledOptions = pThis->m_dwCurrentSafety; } else { // We don't support this interface *pdwSupportedOptions = 0; *pdwEnabledOptions = 0; } return hr; } STDMETHODIMP [!output CONTROL_CLASS]::XObjectSafety::SetInterfaceSafetyOptions(REFIID riid, DWORD dwOptionSetMask, DWORD dwEnabledOptions) { // Return S_OK if modified, and S_FALSE otherwise. METHOD_PROLOGUE_EX_([!output CONTROL_CLASS], ObjectSafety) // Check if we support the interface and return E_NOINTEFACE if we don't IUnknown* pUnk; if (FAILED(this->QueryInterface(riid, (void**)&pUnk))) return E_NOINTERFACE; // If we are asked to set options we don't support then fail if (dwOptionSetMask & ~pThis->m_dwSupportedSafety) return E_FAIL; // Set the safety options we have been asked to pThis->m_dwCurrentSafety = (pThis->m_dwCurrentSafety & ~dwOptionSetMask) | (dwOptionSetMask & dwEnabledOptions); return S_OK; }