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.

212 lines
5.0 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: error.cpp
  7. //
  8. // Contents: Digital Signitures property page
  9. //
  10. // Classes: CErrorInfo
  11. //
  12. // History: 07-10-2000 stevebl Created
  13. //
  14. //---------------------------------------------------------------------------
  15. #include "precomp.hxx"
  16. #include "wincrypt.h"
  17. #include "cryptui.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CErrorInfo property page
  25. IMPLEMENT_DYNCREATE(CErrorInfo, CPropertyPage)
  26. CErrorInfo::CErrorInfo() : CPropertyPage(CErrorInfo::IDD)
  27. {
  28. //{{AFX_DATA_INIT(CErrorInfo)
  29. // NOTE: the ClassWizard will add member initialization here
  30. //}}AFX_DATA_INIT
  31. }
  32. CErrorInfo::~CErrorInfo()
  33. {
  34. *m_ppThis = NULL;
  35. }
  36. void CErrorInfo::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CPropertyPage::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CErrorInfo)
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CErrorInfo, CPropertyPage)
  43. //{{AFX_MSG_MAP(CErrorInfo)
  44. ON_BN_CLICKED(IDC_BUTTON1, OnSaveAs)
  45. ON_WM_CONTEXTMENU()
  46. //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CErrorInfo message handlers
  50. void CErrorInfo::OnSaveAs()
  51. {
  52. OPENFILENAME ofn;
  53. CString szExtension;
  54. CString szFilter;
  55. szExtension.LoadString(IDS_TEXT_DEF_EXT);
  56. szFilter.LoadString(IDS_TEXT_EXT_FILT);
  57. LPTSTR lpTemp;
  58. TCHAR szFile[2*MAX_PATH];
  59. HANDLE hFile;
  60. DWORD dwSize, dwBytesWritten;
  61. //
  62. // Call the Save common dialog
  63. //
  64. szFile[0] = TEXT('\0');
  65. ZeroMemory (&ofn, sizeof(ofn));
  66. ofn.lStructSize = sizeof(ofn);
  67. ofn.hwndOwner = m_hWnd;
  68. ofn.lpstrFilter = szFilter;
  69. lpTemp = (LPTSTR)ofn.lpstrFilter;
  70. int iBreak = 0;
  71. while (lpTemp[iBreak])
  72. {
  73. if (lpTemp[iBreak] == TEXT('|'))
  74. {
  75. lpTemp[iBreak] = 0;
  76. }
  77. iBreak++;
  78. }
  79. ofn.nFilterIndex = 1;
  80. ofn.lpstrFile = szFile;
  81. ofn.nMaxFile = 2*MAX_PATH;
  82. ofn.lpstrDefExt = szExtension;
  83. ofn.Flags = OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
  84. if (!GetSaveFileName (&ofn))
  85. {
  86. return;
  87. }
  88. CHourglass hourglass;
  89. //
  90. // Create the text file
  91. //
  92. hFile = CreateFile (szFile, GENERIC_WRITE, 0, NULL,
  93. CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
  94. NULL);
  95. if (hFile == INVALID_HANDLE_VALUE)
  96. {
  97. DebugMsg((DM_WARNING, TEXT("CErrorInfo::OnSaveAs: CreateFile failed with %d"), GetLastError()));
  98. return;
  99. }
  100. //
  101. // Get the text out of the edit control
  102. //
  103. dwSize = (DWORD) SendDlgItemMessage (IDC_EDIT1, WM_GETTEXTLENGTH, 0, 0);
  104. lpTemp = (LPTSTR) LocalAlloc (LPTR, (dwSize+2) * sizeof(TCHAR));
  105. if (!lpTemp)
  106. {
  107. DebugMsg((DM_WARNING, TEXT("CErrorInfo::OnSaveAs: LocalAlloc failed with %d"), GetLastError()));
  108. CloseHandle (hFile);
  109. return;
  110. }
  111. SendDlgItemMessage (IDC_EDIT1, WM_GETTEXT, (dwSize+1), (LPARAM) lpTemp);
  112. //
  113. // Save it to the new file
  114. //
  115. if (!WriteFile (hFile, lpTemp, (dwSize * sizeof(TCHAR)), &dwBytesWritten, NULL) ||
  116. (dwBytesWritten != (dwSize * sizeof(TCHAR))))
  117. {
  118. DebugMsg((DM_WARNING, TEXT("CErrorInfo::OnSaveAs: WriteFile failed with %d"),
  119. GetLastError()));
  120. }
  121. LocalFree (lpTemp);
  122. CloseHandle (hFile);
  123. }
  124. BOOL CErrorInfo::OnInitDialog()
  125. {
  126. CPropertyPage::OnInitDialog();
  127. RefreshData();
  128. return TRUE;
  129. }
  130. BOOL CErrorInfo::OnApply()
  131. {
  132. return CPropertyPage::OnApply();
  133. }
  134. LRESULT CErrorInfo::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  135. {
  136. switch (message)
  137. {
  138. case WM_HELP:
  139. StandardHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, IDD);
  140. return 0;
  141. case WM_USER_REFRESH:
  142. RefreshData();
  143. return 0;
  144. case WM_USER_CLOSE:
  145. return GetOwner()->SendMessage(WM_CLOSE);
  146. default:
  147. return CPropertyPage::WindowProc(message, wParam, lParam);
  148. }
  149. }
  150. void CErrorInfo::RefreshData(void)
  151. {
  152. CString szTime = L"";
  153. BSTR bstr = SysAllocString(m_pData->m_szEventTime);
  154. if (bstr)
  155. {
  156. CStringFromWBEMTime(szTime, bstr, FALSE);
  157. SysFreeString(bstr);
  158. }
  159. CEdit * pEd = (CEdit *) GetDlgItem(IDC_EDIT1);
  160. pEd->Clear();
  161. CString sz;
  162. sz.Format(TEXT("%s\r\n\r\n%s"),
  163. szTime,
  164. m_pData->m_szEventLogText);
  165. pEd->ReplaceSel(sz);
  166. SetModified(FALSE);
  167. }
  168. void CErrorInfo::OnContextMenu(CWnd* pWnd, CPoint point)
  169. {
  170. StandardContextMenu(pWnd->m_hWnd, IDD_ERRORINFO);
  171. }