MainSheet.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:5k
开发平台:

Visual C++

  1. // MainSheet.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Property.h"
  5. #include "MainSheet.h"
  6. //owner add
  7. #include "GuiRes.h"
  8. #include "acl.h"
  9. #include "systemset.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. //=============================================================================================
  16. // CMainSheet
  17. extern CAclFile m_AclFile;
  18. extern CPropertyApp theApp;
  19. IMPLEMENT_DYNAMIC(CMainSheet, CPropertySheet)
  20. CMainSheet::CMainSheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  21. :CPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  22. {
  23. }
  24. CMainSheet::CMainSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  25. :CPropertySheet(pszCaption, pParentWnd, iSelectPage)
  26. {
  27. }
  28. CMainSheet::~CMainSheet()
  29. {
  30. }
  31. BEGIN_MESSAGE_MAP(CMainSheet, CPropertySheet)
  32. //{{AFX_MSG_MAP(CMainSheet)
  33. ON_WM_PAINT()
  34. ON_WM_SYSCOMMAND()
  35. //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37. //=============================================================================================
  38. // CMainSheet message handlers
  39. BOOL CMainSheet::OnInitDialog() 
  40. {
  41. BOOL bResult = CPropertySheet::OnInitDialog();
  42. SetLogoFont("Arial");
  43. SetIcon(AfxGetApp()->LoadIcon(IDR_MAINFRAME), TRUE);
  44. InitDlgResource();
  45. ModifyStyleEx(WS_EX_TOOLWINDOW, WS_EX_APPWINDOW); 
  46. return bResult;
  47. }
  48. void CMainSheet::OnPaint() 
  49. {
  50. CPaintDC dc(this);
  51. if(m_LogoText.IsEmpty())
  52. return;
  53. CRect rectTabCtrl;
  54. CRect rectOk;
  55. CRect rectText;
  56. GetTabControl() ->GetWindowRect(rectTabCtrl);
  57. ScreenToClient(rectTabCtrl);
  58. GetDlgItem(IDOK)->GetWindowRect(rectOk);
  59. ScreenToClient(rectOk);
  60. dc.SetBkMode(TRANSPARENT);
  61. rectText.left = rectTabCtrl.left;
  62. rectText.top = rectOk.top;
  63. rectText.bottom = rectOk.bottom;
  64. rectText.right = rectOk.left;
  65. CFont* OldFont = dc.SelectObject(&m_FontLogo);
  66. COLORREF OldColor= dc.SetTextColor(GetSysColor(COLOR_3DHILIGHT));
  67. dc.DrawText (m_LogoText, rectText + CPoint(1, 1), DT_SINGLELINE | DT_LEFT | DT_VCENTER);
  68. dc.SetTextColor (GetSysColor(COLOR_3DSHADOW));
  69. dc.DrawText (m_LogoText, rectText, DT_SINGLELINE | DT_LEFT | DT_VCENTER);
  70. dc.SetTextColor (OldColor);
  71. dc.SelectObject (OldFont);
  72. }
  73. BOOL CMainSheet::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  74. {
  75. switch(nID)
  76. {
  77. case IDOK:
  78. if(OnApply())
  79. return TRUE;
  80. ShowWindow(SW_HIDE);
  81. return TRUE;
  82. case IDCANCEL:
  83. OnCancel();
  84. ShowWindow(SW_HIDE);
  85. return TRUE;
  86. case ID_APPLY_NOW:
  87. if(OnApply())
  88. return TRUE;
  89. break;
  90. case IDHELP:
  91. break;
  92. }
  93. return CPropertySheet::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  94. }
  95. BOOL CMainSheet::OnApply()
  96. {
  97. if(!GetDlgItem(ID_APPLY_NOW)->IsWindowEnabled()) //exit and not do with system
  98. return FALSE;
  99. if(m_AclFile.SaveAcl() != XERR_SUCCESS)
  100. {
  101. AfxMessageBox(GUI_ACL_MESSAGE_SAVE_ACL_ERROR);
  102. return TRUE;
  103. }
  104. theApp.SetAutoStart();
  105. if(!theApp.InitDllData())
  106. {
  107. AfxMessageBox(GUI_ACL_MESSAGE_INIT_DLL_DATA_ERROR);
  108. return TRUE;
  109. }
  110. GetDlgItem(ID_APPLY_NOW)->EnableWindow(FALSE);
  111. return FALSE;
  112. }
  113. void CMainSheet::OnCancel()
  114. {
  115. if(!GetDlgItem(ID_APPLY_NOW)->IsWindowEnabled())
  116. return;
  117. if(AfxMessageBox(GUI_ACL_MESSAGE_ACL_ASK_SAVE, MB_YESNO) == IDYES)
  118. {
  119. OnApply();
  120. return;
  121. }
  122. GetDlgItem(ID_APPLY_NOW)->EnableWindow(FALSE);
  123. if(m_AclFile.ReadAcl() != XERR_SUCCESS)
  124. {
  125. AfxMessageBox(GUI_ACL_MESSAGE_ACL_READ_ERROR);
  126. return;
  127. }
  128. CAcl *dlgAcl = (CAcl*)this->GetPage(2);
  129. dlgAcl->Refresh();
  130. CSystemSet *dlgSystemSet = (CSystemSet*)this->GetPage(3);
  131. dlgSystemSet->Refresh();
  132. }
  133. void CMainSheet::OnSysCommand(UINT nID, LPARAM lParam) 
  134. {
  135. if(nID == SC_CLOSE)
  136. {
  137. OnCancel();
  138. ShowWindow(SW_HIDE);
  139. return;
  140. }
  141. CPropertySheet::OnSysCommand(nID, lParam);
  142. }
  143. //---------------------------------------------------------------------------------------------
  144. //set logo text
  145. void CMainSheet::SetLogoText(CString Text)
  146. {
  147. m_LogoText = Text;
  148. }
  149. //---------------------------------------------------------------------------------------------
  150. //set logo font
  151. void CMainSheet::SetLogoFont(
  152. CString Name,
  153. int nHeight,
  154. int nWeight,
  155. BYTE bItalic,
  156. BYTE bUnderline
  157. )
  158. {
  159. if(m_FontLogo.m_hObject)
  160. m_FontLogo.Detach();
  161. m_FontLogo.CreateFont(0,0,0,0,nWeight,bItalic,bUnderline,0,0,0,0,0,0,Name);
  162. }
  163. //---------------------------------------------------------------------------------------------
  164. //initialize dialog's resource
  165. void CMainSheet::InitDlgResource()
  166. {
  167. SetDlgItemText(IDOK,GUI_BUTTON_OK);
  168. SetDlgItemText(IDCANCEL,GUI_BUTTON_CANCEL);
  169. SetDlgItemText(IDHELP,GUI_BUTTON_HELP);
  170. SetDlgItemText(ID_APPLY_NOW,GUI_BUTTON_APPLY);
  171. }