[!if RIBBON_TOOLBAR] // This MFC Samples source code demonstrates using MFC Microsoft Office Fluent User Interface // (the "Fluent UI") and is provided only as referential material to supplement the // Microsoft Foundation Classes Reference and related electronic documentation // included with the MFC C++ library software. // License terms to copy, use or distribute the Fluent UI are available separately. // To learn more about our Fluent UI licensing program, please visit // https://go.microsoft.com/fwlink/?LinkId=238214. // // Copyright (C) Microsoft Corporation // All rights reserved. [!endif] // $dialogimpl$ : implementation file // #include "pch.h" #include "framework.h" #include "$appheader$" #include "$dialogheader$" [!if AUTOMATION] #include "$dialogautoproxyheader$" [!endif] #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif [!if ABOUT_BOX] // CAboutDlg dialog used for App About [!if !NO_MFC_CONTROLS] class CAboutDlg : public CDialogEx [!else] class CAboutDlg : public CDialog [!endif] { public: CAboutDlg(); // Dialog Data #ifdef AFX_DESIGN_TIME enum { IDD = IDD_ABOUTBOX }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support // Implementation protected: DECLARE_MESSAGE_MAP() }; [!if !NO_MFC_CONTROLS] CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) [!else] CAboutDlg::CAboutDlg() : CDialog(IDD_ABOUTBOX) [!endif] { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { [!if !NO_MFC_CONTROLS] CDialogEx::DoDataExchange(pDX); [!else] CDialog::DoDataExchange(pDX); [!endif] } [!if !NO_MFC_CONTROLS] BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) [!else] BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) [!endif] END_MESSAGE_MAP() [!endif] // $dialogclass$ dialog [!if HTML_DIALOG] BEGIN_DHTML_EVENT_MAP($dialogclass$) DHTML_EVENT_ONCLICK(_T("ButtonOK"), OnButtonOK) DHTML_EVENT_ONCLICK(_T("ButtonCancel"), OnButtonCancel) END_DHTML_EVENT_MAP() [!endif] [!if AUTOMATION] IMPLEMENT_DYNAMIC($dialogclass$, $dialogbaseclass$); [!endif] $dialogclass$::$dialogclass$(CWnd* pParent /*=nullptr*/) [!if HTML_DIALOG] : CDHtmlDialog(IDD_$uppercasesafeprojectidentifiername$_DIALOG, IDR_HTML_$uppercasesafeprojectidentifiername$_DIALOG, pParent) [!else] : $dialogbaseclass$(IDD_$uppercasesafeprojectidentifiername$_DIALOG, pParent) [!endif] { [!if ACCESSIBILITY] EnableActiveAccessibility(); [!endif] m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); [!if AUTOMATION] m_pAutoProxy = nullptr; [!endif] } [!if AUTOMATION] $dialogclass$::~$dialogclass$() { // If there is an automation proxy for this dialog, set // its back pointer to this dialog to null, so it knows // the dialog has been deleted. if (m_pAutoProxy != nullptr) m_pAutoProxy->m_pDialog = nullptr; } [!endif] void $dialogclass$::DoDataExchange(CDataExchange* pDX) { $dialogbaseclass$::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP($dialogclass$, $dialogbaseclass$) [!if ABOUT_BOX] ON_WM_SYSCOMMAND() [!endif] [!if AUTOMATION] ON_WM_CLOSE() [!endif] [!if !HTML_DIALOG] ON_WM_PAINT() ON_WM_QUERYDRAGICON() [!endif] END_MESSAGE_MAP() // $dialogclass$ message handlers BOOL $dialogclass$::OnInitDialog() { $dialogbaseclass$::OnInitDialog(); [!if ABOUT_BOX] // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != nullptr) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } [!endif] // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon [!if MAIN_FRAME_MAXIMIZED] ShowWindow(SW_MAXIMIZE); [!endif] [!if MAIN_FRAME_MINIMIZED] ShowWindow(SW_MINIMIZE); [!endif] // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } [!if ABOUT_BOX] void $dialogclass$::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { $dialogbaseclass$::OnSysCommand(nID, lParam); } } [!endif] // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void $dialogclass$::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { $dialogbaseclass$::OnPaint(); } } // The system calls this function to obtain the cursor to display while the user drags // the minimized window. HCURSOR $dialogclass$::OnQueryDragIcon() { return static_cast(m_hIcon); } [!if AUTOMATION] // Automation servers should not exit when a user closes the UI // if a controller still holds on to one of its objects. These // message handlers make sure that if the proxy is still in use, // then the UI is hidden but the dialog remains around if it // is dismissed. void $dialogclass$::OnClose() { if (CanExit()) $dialogbaseclass$::OnClose(); } void $dialogclass$::OnOK() { if (CanExit()) $dialogbaseclass$::OnOK(); } void $dialogclass$::OnCancel() { if (CanExit()) $dialogbaseclass$::OnCancel(); } BOOL $dialogclass$::CanExit() { // If the proxy object is still around, then the automation // controller is still holding on to this application. Leave // the dialog around, but hide its UI. if (m_pAutoProxy != nullptr) { ShowWindow(SW_HIDE); return FALSE; } return TRUE; } [!endif] [!if HTML_DIALOG] HRESULT $dialogclass$::OnButtonOK(IHTMLElement* /*pElement*/) { OnOK(); return S_OK; } HRESULT $dialogclass$::OnButtonCancel(IHTMLElement* /*pElement*/) { OnCancel(); return S_OK; } [!endif]