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.

181 lines
5.2 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: TemplatePropertySheet.cpp
  8. //
  9. // Contents: Implementation of CTemplatePropertySheet
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include "TemplatePropertySheet.h"
  14. #include "SecurityPropertyPage.h"
  15. #define WM_ADDSECURITYPAGE WM_APP + 2000
  16. #define WM_SETOKDEFAULT WM_APP + 2001
  17. //////////////////////////////////////////////////////////////////////
  18. // Construction/Destruction
  19. //////////////////////////////////////////////////////////////////////
  20. CTemplatePropertySheet::CTemplatePropertySheet(
  21. LPCTSTR pszCaption,
  22. CCertTemplate& rCertTemplate,
  23. CWnd *pParentWnd,
  24. UINT iSelectPage)
  25. : CPropertySheet (pszCaption, pParentWnd, iSelectPage),
  26. m_rCertTemplate (rCertTemplate),
  27. m_pReleaseMe (0)
  28. {
  29. m_rCertTemplate.AddRef ();
  30. }
  31. CTemplatePropertySheet::~CTemplatePropertySheet()
  32. {
  33. m_rCertTemplate.Release ();
  34. if ( m_pReleaseMe )
  35. m_pReleaseMe->Release ();
  36. }
  37. BEGIN_MESSAGE_MAP(CTemplatePropertySheet, CPropertySheet)
  38. ON_MESSAGE (WM_ADDSECURITYPAGE, OnAddSecurityPage)
  39. ON_MESSAGE(WM_HELP, OnHelp)
  40. ON_MESSAGE (WM_SETOKDEFAULT, OnSetOKDefault)
  41. END_MESSAGE_MAP()
  42. LRESULT CTemplatePropertySheet::OnAddSecurityPage (WPARAM, LPARAM)
  43. {
  44. _TRACE (1, L"Entering CTemplatePropertySheet::OnAddSecurityPage\n");
  45. LPSECURITYINFO pCertTemplateSecurity = NULL;
  46. HRESULT hr = CreateCertTemplateSecurityInfo (&m_rCertTemplate,
  47. &pCertTemplateSecurity);
  48. if ( SUCCEEDED (hr) )
  49. {
  50. HPROPSHEETPAGE hPage = CreateSecurityPage (pCertTemplateSecurity);
  51. if ( hPage )
  52. {
  53. if ( SendMessage (PSM_ADDPAGE, 0, (LPARAM) hPage) )
  54. {
  55. SendMessage (PSM_RECALCPAGESIZES, 0, 0);
  56. }
  57. else
  58. {
  59. DestroyPropertySheetPage (hPage);
  60. pCertTemplateSecurity->Release ();
  61. pCertTemplateSecurity = 0;
  62. }
  63. }
  64. else
  65. {
  66. hr = HRESULT_FROM_WIN32 (GetLastError());
  67. _TRACE (0, L"CreateSecurityPage () failed: 0x%x\n", hr);
  68. pCertTemplateSecurity->Release ();
  69. pCertTemplateSecurity = 0;
  70. }
  71. _ASSERT (SUCCEEDED (hr));
  72. }
  73. m_pReleaseMe = pCertTemplateSecurity;
  74. _TRACE (-1, L"Leaving CTemplatePropertySheet::OnAddSecurityPage\n");
  75. return 0;
  76. }
  77. BOOL CTemplatePropertySheet::OnInitDialog()
  78. {
  79. _TRACE (1, L"Entering CTemplatePropertySheet::OnInitDialog ()\n");
  80. CPropertySheet::OnInitDialog();
  81. LONG dwStyle = GetWindowLong (m_hWnd, GWL_STYLE);
  82. dwStyle |= DS_CONTEXTHELP;
  83. SetWindowLong (m_hWnd, GWL_STYLE, dwStyle);
  84. dwStyle = GetWindowLong (m_hWnd, GWL_EXSTYLE);
  85. dwStyle |= /*WS_EX_DLGMODALFRAME |*/ WS_EX_CONTEXTHELP;
  86. SetWindowLong (m_hWnd, GWL_EXSTYLE, dwStyle);
  87. // Add security page
  88. PostMessage (WM_ADDSECURITYPAGE, 0, 0);
  89. // Make the OK button the default
  90. PostMessage (WM_SETOKDEFAULT, 0, 0);
  91. _TRACE (-1, L"Leaving CTemplatePropertySheet::OnInitDialog ()\n");
  92. return TRUE; // return TRUE unless you set the focus to a control
  93. // EXCEPTION: OCX Property Pages should return FALSE
  94. }
  95. LRESULT CTemplatePropertySheet::OnSetOKDefault (WPARAM, LPARAM)
  96. {
  97. // Make the OK button the default
  98. SendMessage (DM_SETDEFID, MAKEWPARAM (IDOK, 0), 0);
  99. SendDlgItemMessage (IDOK, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  100. SendDlgItemMessage (IDCANCEL, BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  101. return 0;
  102. }
  103. BOOL CTemplatePropertySheet::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  104. {
  105. _TRACE(1, L"Entering CTemplatePropertySheet::OnHelp\n");
  106. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  107. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  108. {
  109. DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  110. }
  111. _TRACE(-1, L"Leaving CTemplatePropertySheet::OnHelp\n");
  112. return TRUE;
  113. }
  114. void CTemplatePropertySheet::DoContextHelp (HWND hWndControl)
  115. {
  116. _TRACE(1, L"Entering CTemplatePropertySheet::DoContextHelp\n");
  117. const int IDC_COMM_APPLYNOW = 12321;
  118. const int IDH_COMM_APPLYNOW = 28447;
  119. const DWORD aHelpIDs_PropSheet[]=
  120. {
  121. IDC_COMM_APPLYNOW, IDH_COMM_APPLYNOW,
  122. 0, 0
  123. };
  124. PWSTR pszHelpFile = 0;
  125. switch (::GetDlgCtrlID (hWndControl))
  126. {
  127. case IDC_COMM_APPLYNOW:
  128. pszHelpFile = L"windows.hlp";
  129. break;
  130. default:
  131. // Display context help for a control
  132. pszHelpFile = const_cast<PWSTR> (GetContextHelpFile ());
  133. break;
  134. }
  135. if ( !::WinHelp (
  136. hWndControl,
  137. pszHelpFile,
  138. HELP_WM_HELP,
  139. (DWORD_PTR) aHelpIDs_PropSheet) )
  140. {
  141. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  142. }
  143. _TRACE(-1, L"Leaving CTemplatePropertySheet::DoContextHelp\n");
  144. }