Source code of Windows XP (NT5)
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.

177 lines
4.8 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. DestroyPropertySheetPage (hPage);
  56. pCertTemplateSecurity->Release ();
  57. pCertTemplateSecurity = 0;
  58. }
  59. }
  60. else
  61. {
  62. hr = HRESULT_FROM_WIN32 (GetLastError());
  63. _TRACE (0, L"CreateSecurityPage () failed: 0x%x\n", hr);
  64. pCertTemplateSecurity->Release ();
  65. pCertTemplateSecurity = 0;
  66. }
  67. _ASSERT (SUCCEEDED (hr));
  68. }
  69. m_pReleaseMe = pCertTemplateSecurity;
  70. _TRACE (-1, L"Leaving CTemplatePropertySheet::OnAddSecurityPage\n");
  71. return 0;
  72. }
  73. BOOL CTemplatePropertySheet::OnInitDialog()
  74. {
  75. _TRACE (1, L"Entering CTemplatePropertySheet::OnInitDialog ()\n");
  76. CPropertySheet::OnInitDialog();
  77. LONG dwStyle = GetWindowLong (m_hWnd, GWL_STYLE);
  78. dwStyle |= DS_CONTEXTHELP;
  79. SetWindowLong (m_hWnd, GWL_STYLE, dwStyle);
  80. dwStyle = GetWindowLong (m_hWnd, GWL_EXSTYLE);
  81. dwStyle |= /*WS_EX_DLGMODALFRAME |*/ WS_EX_CONTEXTHELP;
  82. SetWindowLong (m_hWnd, GWL_EXSTYLE, dwStyle);
  83. // Add security page
  84. PostMessage (WM_ADDSECURITYPAGE, 0, 0);
  85. // Make the OK button the default
  86. PostMessage (WM_SETOKDEFAULT, 0, 0);
  87. _TRACE (-1, L"Leaving CTemplatePropertySheet::OnInitDialog ()\n");
  88. return TRUE; // return TRUE unless you set the focus to a control
  89. // EXCEPTION: OCX Property Pages should return FALSE
  90. }
  91. LRESULT CTemplatePropertySheet::OnSetOKDefault (WPARAM, LPARAM)
  92. {
  93. // Make the OK button the default
  94. SendMessage (DM_SETDEFID, MAKEWPARAM (IDOK, 0), 0);
  95. SendDlgItemMessage (IDOK, BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  96. SendDlgItemMessage (IDCANCEL, BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  97. return 0;
  98. }
  99. BOOL CTemplatePropertySheet::OnHelp(WPARAM /*wParam*/, LPARAM lParam)
  100. {
  101. _TRACE(1, L"Entering CTemplatePropertySheet::OnHelp\n");
  102. const LPHELPINFO pHelpInfo = (LPHELPINFO)lParam;
  103. if (pHelpInfo && pHelpInfo->iContextType == HELPINFO_WINDOW)
  104. {
  105. DoContextHelp ((HWND) pHelpInfo->hItemHandle);
  106. }
  107. _TRACE(-1, L"Leaving CTemplatePropertySheet::OnHelp\n");
  108. return TRUE;
  109. }
  110. void CTemplatePropertySheet::DoContextHelp (HWND hWndControl)
  111. {
  112. _TRACE(1, L"Entering CTemplatePropertySheet::DoContextHelp\n");
  113. const int IDC_COMM_APPLYNOW = 12321;
  114. const int IDH_COMM_APPLYNOW = 28447;
  115. const DWORD aHelpIDs_PropSheet[]=
  116. {
  117. IDC_COMM_APPLYNOW, IDH_COMM_APPLYNOW,
  118. 0, 0
  119. };
  120. PWSTR pszHelpFile = 0;
  121. switch (::GetDlgCtrlID (hWndControl))
  122. {
  123. case IDC_COMM_APPLYNOW:
  124. pszHelpFile = L"windows.hlp";
  125. break;
  126. default:
  127. // Display context help for a control
  128. pszHelpFile = const_cast<PWSTR> (GetContextHelpFile ());
  129. break;
  130. }
  131. if ( !::WinHelp (
  132. hWndControl,
  133. pszHelpFile,
  134. HELP_WM_HELP,
  135. (DWORD_PTR) aHelpIDs_PropSheet) )
  136. {
  137. _TRACE(0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  138. }
  139. _TRACE(-1, L"Leaving CTemplatePropertySheet::DoContextHelp\n");
  140. }