Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. appdlg.cpp
  5. Abstract:
  6. CAppDialog dialog class implementation. This is the base clas for
  7. the main dialog. This class resposible for adding "about.." to
  8. system menu and application icon.
  9. CAboutDialog dialog class declaration/implementation.
  10. Author:
  11. Michael Cheuk (mcheuk)
  12. Project:
  13. Link Checker
  14. Revision History:
  15. --*/
  16. #include "stdafx.h"
  17. #include "resource.h"
  18. #include "appdlg.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. //---------------------------------------------------------------------------
  25. // CAboutDlg dialog
  26. //
  27. // About dialog class
  28. class CAboutDlg : public CDialog
  29. {
  30. public:
  31. CAboutDlg();
  32. // Dialog Data
  33. //{{AFX_DATA(CAboutDlg)
  34. enum { IDD = IDD_ABOUTBOX };
  35. //}}AFX_DATA
  36. // ClassWizard generated virtual function overrides
  37. //{{AFX_VIRTUAL(CAboutDlg)
  38. protected:
  39. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  40. //}}AFX_VIRTUAL
  41. // Implementation
  42. protected:
  43. //{{AFX_MSG(CAboutDlg)
  44. //}}AFX_MSG
  45. DECLARE_MESSAGE_MAP()
  46. }; // class CAboutDlg
  47. CAboutDlg::CAboutDlg(
  48. ) :
  49. /*++
  50. Routine Description:
  51. Constructor.
  52. Arguments:
  53. pParent - Pointer to parent CWnd
  54. Return Value:
  55. N/A
  56. --*/
  57. CDialog(CAboutDlg::IDD)
  58. {
  59. //{{AFX_DATA_INIT(CAboutDlg)
  60. //}}AFX_DATA_INIT
  61. }
  62. void
  63. CAboutDlg::DoDataExchange(
  64. CDataExchange* pDX
  65. )
  66. /*++
  67. Routine Description:
  68. Called by MFC to change/retrieve dialog data
  69. Arguments:
  70. pDX -
  71. Return Value:
  72. N/A
  73. --*/
  74. {
  75. CDialog::DoDataExchange(pDX);
  76. //{{AFX_DATA_MAP(CAboutDlg)
  77. //}}AFX_DATA_MAP
  78. }
  79. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  80. //{{AFX_MSG_MAP(CAboutDlg)
  81. // No message handlers
  82. //}}AFX_MSG_MAP
  83. ON_BN_CLICKED(IDC_ABOUT_OK, CDialog::OnOK)
  84. END_MESSAGE_MAP()
  85. //---------------------------------------------------------------------------
  86. // CAppDialog dialog
  87. //
  88. CAppDialog::CAppDialog(
  89. UINT nIDTemplate,
  90. CWnd* pParent /*=NULL*/
  91. ) :
  92. /*++
  93. Routine Description:
  94. Constructor.
  95. Arguments:
  96. nIDTemplate - dialog template resource ID
  97. pParent - pointer to parent CWnd
  98. Return Value:
  99. N/A
  100. --*/
  101. CDialog(nIDTemplate, pParent)
  102. {
  103. //{{AFX_DATA_INIT(CAppDialog)
  104. //}}AFX_DATA_INIT
  105. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  106. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  107. }
  108. BEGIN_MESSAGE_MAP(CAppDialog, CDialog)
  109. //{{AFX_MSG_MAP(CAppDialog)
  110. ON_WM_SYSCOMMAND()
  111. ON_WM_PAINT()
  112. ON_WM_QUERYDRAGICON()
  113. //}}AFX_MSG_MAP
  114. END_MESSAGE_MAP()
  115. //---------------------------------------------------------------------------
  116. // CAppDialog message handlers
  117. //
  118. BOOL
  119. CAppDialog::OnInitDialog(
  120. )
  121. /*++
  122. Routine Description:
  123. WM_INITDIALOG message handler
  124. Arguments:
  125. N/A
  126. Return Value:
  127. BOOL - TRUE if sucess. FALSE otherwise.
  128. --*/
  129. {
  130. CDialog::OnInitDialog();
  131. // Add "About..." menu item to system menu.
  132. // IDM_ABOUTBOX must be in the system command range.
  133. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  134. ASSERT(IDM_ABOUTBOX < 0xF000);
  135. CMenu* pSysMenu = GetSystemMenu(FALSE);
  136. CString strAboutMenu;
  137. strAboutMenu.LoadString(IDS_ABOUTBOX);
  138. if (!strAboutMenu.IsEmpty())
  139. {
  140. pSysMenu->AppendMenu(MF_SEPARATOR);
  141. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  142. }
  143. // Set the icon for this dialog. The framework does this automatically
  144. // when the application's main window is not a dialog
  145. SetIcon(m_hIcon, TRUE); // Set big icon
  146. SetIcon(m_hIcon, FALSE); // Set small icon
  147. // TODO: Add extra initialization here
  148. return TRUE; // return TRUE unless you set the focus to a control
  149. } // CAppDialog::OnInitDialog
  150. void
  151. CAppDialog::OnSysCommand(
  152. UINT nID,
  153. LPARAM lParam
  154. )
  155. /*++
  156. Routine Description:
  157. WM_SYSCOMMAND message handler
  158. Arguments:
  159. nID -
  160. lParam -
  161. Return Value:
  162. N/A
  163. --*/
  164. {
  165. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  166. {
  167. CAboutDlg dlgAbout;
  168. dlgAbout.DoModal();
  169. }
  170. else
  171. {
  172. CDialog::OnSysCommand(nID, lParam);
  173. }
  174. } // CAppDialog::OnSysCommand
  175. void
  176. CAppDialog::OnPaint(
  177. )
  178. /*++
  179. Routine Description:
  180. WM_PAINT message handler.
  181. If you add a minimize button to your dialog, you will need the code below
  182. to draw the icon. For MFC applications using the document/view model,
  183. this is automatically done for you by the framework.
  184. Arguments:
  185. N/A
  186. Return Value:
  187. N/A
  188. --*/
  189. {
  190. if (IsIconic())
  191. {
  192. CPaintDC dc(this); // device context for painting
  193. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  194. // Center icon in client rectangle
  195. int cxIcon = GetSystemMetrics(SM_CXICON);
  196. int cyIcon = GetSystemMetrics(SM_CYICON);
  197. CRect rect;
  198. GetClientRect(&rect);
  199. int x = (rect.Width() - cxIcon + 1) / 2;
  200. int y = (rect.Height() - cyIcon + 1) / 2;
  201. // Draw the icon
  202. dc.DrawIcon(x, y, m_hIcon);
  203. }
  204. else
  205. {
  206. CDialog::OnPaint();
  207. }
  208. } // CAppDialog::OnPaint
  209. HCURSOR CAppDialog::OnQueryDragIcon()
  210. /*++
  211. Routine Description:
  212. The system calls this to obtain the cursor to display while the user drags
  213. the minimized window.
  214. Arguments:
  215. N/A
  216. Return Value:
  217. HCURSOR -
  218. --*/
  219. {
  220. return (HCURSOR) m_hIcon;
  221. } // CAppDialog::OnQueryDragIcon