// $control_impl$ : Implementation of the $control_class$ ActiveX Control class. #include "pch.h" #include "framework.h" #include "$projectname$.h" #include "$control_header$" #include "$property_page_header$" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE($control_class$, COleControl) // Message map BEGIN_MESSAGE_MAP($control_class$, COleControl) [!if SUBCLASS_WINDOW] ON_MESSAGE(OCM_COMMAND, &$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($control_class$, COleControl) [!if ASYNC_PROPERTY_LOAD] DISP_STOCKPROP_READYSTATE() [!endif] [!if ABOUT_BOX] DISP_FUNCTION_ID($control_class$, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE) [!endif] END_DISPATCH_MAP() // Event map BEGIN_EVENT_MAP($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($control_class$, 1) PROPPAGEID($property_page_class$::guid) END_PROPPAGEIDS($control_class$) // Initialize class factory and guid [!if CONTROL_TYPE_ID_SET] IMPLEMENT_OLECREATE_EX($control_class$, "$control_type_id$", $guid_control_clsid_olecreate$) [!else] IMPLEMENT_OLECREATE_NOREGNAME($control_class$, $guid_control_clsid_olecreate$) [!endif] // Type library ID and version IMPLEMENT_OLETYPELIB($control_class$, _tlid, _wVerMajor, _wVerMinor) // Interface IDs const IID IID_D$safeprojectname$ = $guid_primary_iid_staticconst$; const IID IID_D$safeprojectname$Events = $guid_event_iid_staticconst$; // Control type information static const DWORD _dw$safeprojectname$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($control_class$, IDS_$safercprojectname$, _dw$safeprojectname$OleMisc) // $control_class$::$control_class$Factory::UpdateRegistry - // Adds or removes system registry entries for $control_class$ BOOL $control_class$::$control_class$Factory::UpdateRegistry(BOOL bRegister) { // TODO: Verify that your control follows apartment-model threading rules. // Refer to MFC TechNote 64 for more information. // If your control does not conform to the apartment-model rules, then // you must modify the code below, changing the 6th parameter from [!if INSERTABLE] // afxRegInsertable | afxRegApartmentThreading to afxRegInsertable. [!else] // afxRegApartmentThreading to 0. [!endif] if (bRegister) return AfxOleRegisterControlClass( AfxGetInstanceHandle(), m_clsid, m_lpszProgID, IDS_$safercprojectname$, IDB_$safercprojectname$, [!if INSERTABLE] afxRegInsertable | afxRegApartmentThreading, [!else] afxRegApartmentThreading, [!endif] _dw$safeprojectname$OleMisc, _tlid, _wVerMajor, _wVerMinor); else return AfxOleUnregisterClass(m_clsid, m_lpszProgID); } [!if RUNTIME_LICENSE] // Licensing strings static const TCHAR _szLicFileName[] = _T("$projectname$.lic"); static const WCHAR _szLicString[] = L"Copyright (c) $year$ $registeredorganization$"; // $control_class$::$control_class$Factory::VerifyUserLicense - // Checks for existence of a user license BOOL $control_class$::$control_class$Factory::VerifyUserLicense() { return AfxVerifyLicFile(AfxGetInstanceHandle(), _szLicFileName, _szLicString); } // $control_class$::$control_class$Factory::GetLicenseKey - // Returns a runtime licensing key BOOL $control_class$::$control_class$Factory::GetLicenseKey(DWORD dwReserved, BSTR *pbstrKey) { if (pbstrKey == nullptr) return FALSE; *pbstrKey = SysAllocString(_szLicString); return (*pbstrKey != nullptr); } [!endif] // $control_class$::$control_class$ - Constructor $control_class$::$control_class$() { InitializeIIDs(&IID_D$safeprojectname$, &IID_D$safeprojectname$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. } // $control_class$::~$control_class$ - Destructor $control_class$::~$control_class$() { // TODO: Cleanup your control's instance data here. } // $control_class$::OnDraw - Drawing function void $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] } // $control_class$::DoPropExchange - Persistence support void $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] // $control_class$::GetControlFlags - // Flags to customize MFC's implementation of ActiveX controls. // DWORD $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] // $control_class$::OnResetState - Reset control to default state void $control_class$::OnResetState() { COleControl::OnResetState(); // Resets defaults found in DoPropExchange // TODO: Reset any other control state here. } [!if ABOUT_BOX] // $control_class$::AboutBox - Display an "About" box to the user void $control_class$::AboutBox() { CDialogEx dlgAbout(IDD_ABOUTBOX_$safercprojectname$); dlgAbout.DoModal(); } [!endif] [!if SUBCLASS_WINDOW] // $control_class$::PreCreateWindow - Modify parameters for CreateWindowEx BOOL $control_class$::PreCreateWindow(CREATESTRUCT& cs) { [!if SUBCLASS_WINDOW] cs.lpszClass = _T("$window_class$"); [!else] // TODO: Fill in the name of the window class to be subclassed. cs.lpszClass = _T(""); [!endif] BOOL bRet = COleControl::PreCreateWindow(cs); cs.hMenu = nullptr; return bRet; } // $control_class$::IsSubclassedControl - This is a subclassed control BOOL $control_class$::IsSubclassedControl() { return TRUE; } // $control_class$::OnOcmCommand - Handle command messages LRESULT $control_class$::OnOcmCommand(WPARAM wParam, LPARAM lParam) { WORD wNotifyCode = HIWORD(wParam); // TODO: Switch on wNotifyCode here. return 0; } [!endif] // $control_class$ message handlers