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.

120 lines
2.8 KiB

  1. /****************************************************************************
  2. Copyright (c) Microsoft Corporation 1998
  3. All rights reserved
  4. File: ERRORLOG.CPP
  5. ***************************************************************************/
  6. #include "pch.h"
  7. #include "utils.h"
  8. #include "logging.h"
  9. #include <richedit.h>
  10. DEFINE_MODULE("RIPREP");
  11. //
  12. // EditStreamCallback( )
  13. //
  14. // Callback routine used by the rich edit control to read in the log file.
  15. //
  16. // Returns: 0 - to continue.
  17. // Otherwize, Win32 error code.
  18. //
  19. DWORD CALLBACK
  20. EditStreamCallback (
  21. HANDLE hLogFile,
  22. LPBYTE Buffer,
  23. LONG cb,
  24. PULONG pcb
  25. )
  26. {
  27. DWORD error;
  28. TraceFunc( "EditStreamCallback( )\n" );
  29. if ( !ReadFile ( g_hLogFile, Buffer, cb, pcb, NULL ) ) {
  30. error = GetLastError( );
  31. DebugMsg( "Error - EditStreamCallback: GetLastError() => 0x%08x \n", error );
  32. RETURN(error);
  33. }
  34. RETURN(0);
  35. }
  36. //
  37. // ErrorsDlgProc()
  38. //
  39. INT_PTR CALLBACK
  40. ErrorsDlgProc(
  41. HWND hDlg,
  42. UINT uMsg,
  43. WPARAM wParam,
  44. LPARAM lParam )
  45. {
  46. switch (uMsg)
  47. {
  48. default:
  49. return FALSE;
  50. case WM_INITDIALOG:
  51. {
  52. HRESULT hr;
  53. HWND hWndRichEdit = GetDlgItem( hDlg, IDC_E_ERRORS );
  54. EDITSTREAM eStream; // structure used by EM_STREAMIN message
  55. Assert( hWndRichEdit );
  56. ZeroMemory( &eStream, sizeof(eStream) );
  57. hr = THR( LogOpen( ) );
  58. if ( FAILED( hr ) )
  59. {
  60. HWND hParent = GetParent( hDlg );
  61. DestroyWindow( hDlg );
  62. SetFocus( hParent );
  63. return FALSE;
  64. }
  65. // move to the beginning of the newest log
  66. SetFilePointer( g_hLogFile, g_dwLogFileStartLow, (LONG*)&g_dwLogFileStartHigh, FILE_BEGIN );
  67. eStream.pfnCallback = (EDITSTREAMCALLBACK) EditStreamCallback;
  68. SendMessage ( hWndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM) &eStream );
  69. SendMessage ( hWndRichEdit, EM_SETMODIFY, TRUE, 0 );
  70. CloseHandle( g_hLogFile );
  71. g_hLogFile = INVALID_HANDLE_VALUE;
  72. LogClose( );
  73. CenterDialog( hDlg );
  74. PostMessage( hDlg, WM_USER, 0, 0 );
  75. }
  76. break;
  77. case WM_COMMAND:
  78. switch ( wParam )
  79. {
  80. case IDCANCEL:
  81. EndDialog ( hDlg, 0 );
  82. break;
  83. default:
  84. return FALSE;
  85. }
  86. case WM_USER:
  87. {
  88. HWND hWndRichEdit = GetDlgItem( hDlg, IDC_E_ERRORS );
  89. // These have to be delayed or the Edit control will
  90. // highlight all the text.
  91. SendMessage(hWndRichEdit,EM_SETSEL,0,0);
  92. SendMessage(hWndRichEdit,EM_SCROLLCARET,0,0);
  93. }
  94. break;
  95. }
  96. return TRUE;
  97. }