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.

325 lines
7.2 KiB

  1. //
  2. // Application Verifier UI
  3. // Copyright (c) Microsoft Corporation, 2001
  4. //
  5. //
  6. //
  7. // module: ChooseExe.cpp
  8. // author: CLupu
  9. // created: 04/13/2001
  10. //
  11. // Description:
  12. //
  13. // "Select individual tests" wizard page class.
  14. //
  15. #include "stdafx.h"
  16. #include "appverif.h"
  17. #include "ViewLog.h"
  18. #include "AVUtil.h"
  19. #include "AVGlobal.h"
  20. #include "Log.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. //
  27. // Help IDs
  28. //
  29. static DWORD MyHelpIds[] =
  30. {
  31. 0, 0
  32. };
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CViewLogPage property page
  35. IMPLEMENT_DYNCREATE(CViewLogPage, CAppverifPage)
  36. CViewLogPage::CViewLogPage() : CAppverifPage(CViewLogPage::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CViewLogPage)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. m_nIssues = 0;
  42. }
  43. CViewLogPage::~CViewLogPage()
  44. {
  45. }
  46. void CViewLogPage::DoDataExchange(CDataExchange* pDX)
  47. {
  48. CAppverifPage::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(CViewLogPage)
  50. DDX_Control(pDX, IDC_ISSUES, m_IssuesList);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CViewLogPage, CAppverifPage)
  54. //{{AFX_MSG_MAP(CViewLogPage)
  55. ON_MESSAGE( WM_HELP, OnHelp )
  56. ON_WM_CONTEXTMENU()
  57. ON_NOTIFY( NM_CLICK, IDC_ISSUES, OnClickIssue )
  58. ON_NOTIFY( NM_CLICK, IDC_ISSUE_DESCRIPTION, OnClickURL )
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. /////////////////////////////////////////////////////////////////////////////
  62. ULONG CViewLogPage::GetDialogId() const
  63. {
  64. return IDD_VIEWLOG_PAGE;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. void CViewLogPage::InsertIssue( DWORD dwIssueId, DWORD dwOccurenceCount )
  68. {
  69. LVITEM lvi;
  70. TCHAR szBuffer[32];
  71. TCHAR szIssue[256];
  72. wsprintf(szBuffer, _T("%d."), m_nIssues + 1);
  73. VERIFY( AVLoadString( dwIssueId, szIssue, 256) );
  74. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  75. lvi.pszText = szBuffer;
  76. lvi.iItem = m_nIssues;
  77. lvi.iSubItem = 0;
  78. lvi.lParam = dwIssueId;
  79. m_IssuesList.InsertItem(&lvi);
  80. wsprintf(szBuffer, _T("%d"), dwOccurenceCount);
  81. m_IssuesList.SetItemText(m_nIssues, COLUMN_TIMES, szBuffer);
  82. m_IssuesList.SetItemText(m_nIssues, COLUMN_DESCRIPTION, szIssue);
  83. m_nIssues++;
  84. return;
  85. }
  86. BOOL CViewLogPage::ReadLog()
  87. {
  88. HANDLE hFile = INVALID_HANDLE_VALUE;
  89. HANDLE hMap = NULL;
  90. PBYTE pMap = NULL;
  91. BOOL bReturn = FALSE;
  92. PISSUEREC pRecord;
  93. int i;
  94. hFile = CreateFile( g_szFileLog,
  95. GENERIC_READ,
  96. 0,
  97. NULL,
  98. OPEN_EXISTING,
  99. FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS,
  100. NULL );
  101. if ( hFile == INVALID_HANDLE_VALUE )
  102. {
  103. goto CleanupAndFail;
  104. }
  105. hMap = CreateFileMapping( hFile,
  106. NULL,
  107. PAGE_READONLY,
  108. 0,
  109. LOGFILESIZE,
  110. NULL );
  111. if ( hMap == NULL )
  112. {
  113. goto CleanupAndFail;
  114. }
  115. pMap = (PBYTE)MapViewOfFile( hMap, FILE_MAP_READ, 0, 0, LOGFILESIZE );
  116. if ( pMap == NULL )
  117. {
  118. goto CleanupAndFail;
  119. }
  120. pRecord = (PISSUEREC)(pMap + sizeof(LOGFILEHEADER));
  121. for ( i = 0; i < MAX_ISSUES_COUNT; i++ )
  122. {
  123. if ( pRecord->dwOccurenceCount > 0 )
  124. {
  125. InsertIssue( EVENT_FROM_IND( i ), pRecord->dwOccurenceCount );
  126. }
  127. pRecord++;
  128. }
  129. bReturn = TRUE;
  130. CleanupAndFail:
  131. if ( !bReturn )
  132. {
  133. AVErrorResourceFormat( IDS_READLOG_FAILED );
  134. }
  135. if ( pMap != NULL )
  136. {
  137. UnmapViewOfFile( pMap );
  138. }
  139. if ( hMap != NULL )
  140. {
  141. CloseHandle( hMap );
  142. }
  143. if ( hFile != INVALID_HANDLE_VALUE )
  144. {
  145. CloseHandle( hFile );
  146. }
  147. return bReturn;
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CViewLogPage message handlers
  151. /////////////////////////////////////////////////////////////
  152. LONG CViewLogPage::OnHelp( WPARAM wParam, LPARAM lParam )
  153. {
  154. LONG lResult = 0;
  155. LPHELPINFO lpHelpInfo = (LPHELPINFO)lParam;
  156. ::WinHelp(
  157. (HWND) lpHelpInfo->hItemHandle,
  158. g_szAVHelpFile,
  159. HELP_WM_HELP,
  160. (DWORD_PTR) MyHelpIds );
  161. return lResult;
  162. }
  163. void CViewLogPage::HandleSelectionChanged( int nSel )
  164. {
  165. if (nSel == -1)
  166. {
  167. return;
  168. }
  169. LVITEM lvi;
  170. TCHAR szRemedy[512];
  171. lvi.iItem = nSel;
  172. lvi.iSubItem = 0;
  173. lvi.mask = LVIF_PARAM;
  174. m_IssuesList.GetItem( &lvi );
  175. VERIFY( AVLoadString( (UINT)(lvi.lParam + 1), szRemedy, 512 ) );
  176. m_dwSelectedIssue = (DWORD)lvi.lParam;
  177. SetDlgItemText( IDC_ISSUE_DESCRIPTION, szRemedy );
  178. }
  179. void CViewLogPage::OnClickIssue( NMHDR* pNMHDR, LRESULT* pResult )
  180. {
  181. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  182. LVHITTESTINFO ht;
  183. int nSel;
  184. ::GetCursorPos(&ht.pt);
  185. m_IssuesList.ScreenToClient( &ht.pt );
  186. nSel = m_IssuesList.SubItemHitTest( &ht );
  187. if (nSel != -1)
  188. {
  189. m_IssuesList.SetItemState( nSel,
  190. LVIS_SELECTED | LVIS_FOCUSED,
  191. LVIS_SELECTED | LVIS_FOCUSED );
  192. }
  193. HandleSelectionChanged( nSel );
  194. }
  195. void CViewLogPage::OnClickURL( NMHDR* pNMHDR, LRESULT* pResult )
  196. {
  197. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  198. SHELLEXECUTEINFO sei = { 0};
  199. TCHAR szURL[256] = _T("");
  200. VERIFY( AVLoadString( m_dwSelectedIssue + 2, szURL, 256 ) );
  201. if (szURL[0] == 0)
  202. {
  203. return;
  204. }
  205. sei.cbSize = sizeof(SHELLEXECUTEINFO);
  206. sei.fMask = SEE_MASK_DOENVSUBST;
  207. sei.hwnd = m_hWnd;
  208. sei.nShow = SW_SHOWNORMAL;
  209. sei.lpFile = szURL;
  210. ShellExecuteEx(&sei);
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. void CViewLogPage::OnContextMenu(CWnd* pWnd, CPoint point)
  214. {
  215. ::WinHelp(
  216. pWnd->m_hWnd,
  217. g_szAVHelpFile,
  218. HELP_CONTEXTMENU,
  219. (DWORD_PTR) MyHelpIds );
  220. }
  221. /////////////////////////////////////////////////////////////////////////////
  222. /////////////////////////////////////////////////////////////////////////////
  223. BOOL CViewLogPage::OnSetActive()
  224. {
  225. ASSERT_VALID( m_pParentSheet );
  226. m_pParentSheet->SetWizardButtons( PSWIZB_BACK | PSWIZB_FINISH );
  227. return CAppverifPage::OnSetActive();
  228. }
  229. /////////////////////////////////////////////////////////////////////////////
  230. BOOL CViewLogPage::OnInitDialog()
  231. {
  232. CAppverifPage::OnInitDialog();
  233. m_IssuesList.SetExtendedStyle( LVS_EX_FULLROWSELECT | m_IssuesList.GetExtendedStyle() );
  234. m_IssuesList.InsertColumn( COLUMN_NUMBER, _T("No."), LVCFMT_LEFT, 40 );
  235. m_IssuesList.InsertColumn( COLUMN_TIMES, _T("Times"), LVCFMT_LEFT, 80 );
  236. m_IssuesList.InsertColumn( COLUMN_DESCRIPTION, _T("Issue description"), LVCFMT_LEFT, 250 );
  237. ReadLog();
  238. return TRUE; // return TRUE unless you set the focus to a control
  239. // EXCEPTION: OCX Property Pages should return FALSE
  240. }
  241. /////////////////////////////////////////////////////////////////////////////
  242. // CViewLogPage message handlers