CliConfigSheet.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /////////////////////////////////////////////////////////////////////////////
  2. // CCliConfigSheet.cpp : implementation file
  3. //
  4. #include "stdafx.h"
  5. #include "CliConfig.h"
  6. #include "CliConfigSheet.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CAboutDlg dialog used for App About
  14. class CAboutDlg : public CDialog
  15. {
  16. public:
  17. CAboutDlg();
  18. // Dialog Data
  19. //{{AFX_DATA(CAboutDlg)
  20. enum { IDD = IDD_ABOUTBOX };
  21. //}}AFX_DATA
  22. // ClassWizard generated virtual function overrides
  23. //{{AFX_VIRTUAL(CAboutDlg)
  24. protected:
  25. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  26. //}}AFX_VIRTUAL
  27. // Implementation
  28. protected:
  29. //{{AFX_MSG(CAboutDlg)
  30. //}}AFX_MSG
  31. DECLARE_MESSAGE_MAP()
  32. };
  33. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  34. {
  35. //{{AFX_DATA_INIT(CAboutDlg)
  36. //}}AFX_DATA_INIT
  37. }
  38. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CAboutDlg)
  42. //}}AFX_DATA_MAP
  43. }
  44. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  45. //{{AFX_MSG_MAP(CAboutDlg)
  46. // No message handlers
  47. //}}AFX_MSG_MAP
  48. END_MESSAGE_MAP()
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CCliConfigSheet dialog
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Message Map
  53. BEGIN_MESSAGE_MAP(CCliConfigSheet, CPropertySheet)
  54. //{{AFX_MSG_MAP(CCliConfigSheet)
  55. ON_WM_SYSCOMMAND()
  56. ON_BN_CLICKED(IDOK, OnOK)
  57. ON_BN_CLICKED(IDCANCEL, OnCancel)
  58. //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60. /////////////////////////////////////////////////////////////////////////////
  61. // Construction
  62. CCliConfigSheet::CCliConfigSheet(CWnd* pParentWnd, UINT iSelectPage)
  63. : CPropertySheet(IDS_TITLE, pParentWnd, iSelectPage)
  64. {
  65. // Add our property pages
  66. AddPage(&m_PageGeneral);
  67. AddPage(&m_PageSound);
  68. AddPage(&m_PageZoneLaunch);
  69. }
  70. BOOL CCliConfigSheet::Create()
  71. {
  72. // Declare the style of window to use
  73. static const DWORD dwStyle = WS_VISIBLE | WS_SYSMENU | WS_CAPTION |
  74. WS_POPUP | WS_MINIMIZEBOX | DS_MODALFRAME;
  75. // Perform default processing
  76. if (!CPropertySheet::Create(NULL, dwStyle))
  77. return false;
  78. // Change this flag
  79. m_nFlags &= WF_CONTINUEMODAL;
  80. // Indicate success
  81. return true;
  82. }
  83. /////////////////////////////////////////////////////////////////////////////
  84. // Implementation
  85. void CCliConfigSheet::InitSysMenu()
  86. {
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. }
  102. void CCliConfigSheet::InitIcon()
  103. {
  104. // Load and set the large icon
  105. LPCTSTR pszRes = MAKEINTRESOURCE(IDR_MAINFRAME);
  106. HICON hIcon = (HICON)::LoadImage(AfxGetResourceHandle(), pszRes,
  107. IMAGE_ICON, ::GetSystemMetrics(SM_CXICON),
  108. ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
  109. SetIcon(hIcon, true);
  110. // Load and set the small icon
  111. HICON hIconSmall = (HICON)::LoadImage(AfxGetResourceHandle(), pszRes,
  112. IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON),
  113. ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
  114. SetIcon(hIconSmall, false);
  115. }
  116. void CCliConfigSheet::InitButtons()
  117. {
  118. // Caculate the height of 7 dialog units
  119. CRect rectUnits(0, 0, 0, 7);
  120. MapDialogRect(GetSafeHwnd(), rectUnits);
  121. // Get the OK and cancel buttons
  122. CWnd* pwndOK = GetDlgItem(IDOK);
  123. CWnd* pwndCancel = GetDlgItem(IDCANCEL);
  124. CWnd* pwndHelp = GetDlgItem(IDHELP);
  125. // Get the window rectangles of the buttons
  126. CRect rectOK, rectCancel, rectHelp;
  127. pwndOK->GetWindowRect(rectOK);
  128. pwndCancel->GetWindowRect(rectCancel);
  129. pwndHelp->GetWindowRect(rectHelp);
  130. ScreenToClient(rectOK);
  131. ScreenToClient(rectCancel);
  132. ScreenToClient(rectHelp);
  133. // Compute the offset to position these buttons flush-right
  134. int cxOffset = rectHelp.right - rectCancel.right;
  135. // Move the buttons into place
  136. rectOK.OffsetRect(cxOffset, 0);
  137. rectCancel.OffsetRect(cxOffset, 0);
  138. pwndOK->MoveWindow(rectOK);
  139. pwndCancel->MoveWindow(rectCancel);
  140. // Compute the height offset of the client area
  141. int cyClient = rectCancel.Height() + rectUnits.Height();
  142. // Compute our new window rectangle
  143. CRect rectWnd;
  144. GetWindowRect(rectWnd);
  145. rectWnd.bottom += cyClient;
  146. // Resize our window
  147. MoveWindow(rectWnd);
  148. // Show the OK and Cancel buttons
  149. GetDlgItem(IDOK)->ShowWindow(SW_SHOW);
  150. GetDlgItem(IDCANCEL)->ShowWindow(SW_SHOW);
  151. // Enable the OK and Cancel buttons
  152. GetDlgItem(IDOK)->EnableWindow(true);
  153. GetDlgItem(IDCANCEL)->EnableWindow(true);
  154. }
  155. /////////////////////////////////////////////////////////////////////////////
  156. // Overrides
  157. void CCliConfigSheet::PostNcDestroy()
  158. {
  159. delete this;
  160. }
  161. /////////////////////////////////////////////////////////////////////////////
  162. // Message Handlers
  163. BOOL CCliConfigSheet::OnInitDialog()
  164. {
  165. // Perform default processing
  166. CPropertySheet::OnInitDialog();
  167. // Add "About..." menu item to system menu.
  168. InitSysMenu();
  169. // Set the icon for this dialog.
  170. InitIcon();
  171. // Initialize the OK and Cancel buttons
  172. InitButtons();
  173. // Return true to set the focus to the first tabstop control
  174. return true;
  175. }
  176. void CCliConfigSheet::OnSysCommand(UINT nID, LPARAM lParam)
  177. {
  178. // Handle the About... menu item
  179. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  180. {
  181. CAboutDlg dlgAbout;
  182. dlgAbout.DoModal();
  183. return;
  184. }
  185. // Perform default processing
  186. CPropertySheet::OnSysCommand(nID, lParam);
  187. }
  188. void CCliConfigSheet::OnOK()
  189. {
  190. // Delegate to each property page
  191. for (int i = 0; i < GetPageCount(); ++i)
  192. {
  193. CPropertyPage* pPage = GetPage(i);
  194. if (pPage->GetSafeHwnd())
  195. pPage->OnOK();
  196. }
  197. // Destroy the window
  198. DestroyWindow();
  199. }
  200. void CCliConfigSheet::OnCancel()
  201. {
  202. // Delegate to each property page
  203. for (int i = 0; i < GetPageCount(); ++i)
  204. {
  205. CPropertyPage* pPage = GetPage(i);
  206. if (pPage->GetSafeHwnd())
  207. pPage->OnCancel();
  208. }
  209. // Destroy the window
  210. DestroyWindow();
  211. }