2 * ReactOS Win32 Applications
3 * Copyright (C) 2007 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT : See COPYING in the top level directory
21 * PROJECT : Event Log Viewer
23 * PROGRAMMER: Marc Piulachs (marc.piulachs at codexchange [dot] net)
27 #include <windows.h> // Standard windows include file
28 #include <commctrl.h> // For ListView control APIs
29 #include <tchar.h> // For TCHAR and string functions.
34 #pragma warning(disable: 4996) // 'strdup' was declared deprecated
35 #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions
38 static const LPSTR EVENT_SOURCE_APPLICATION
= "Application";
39 static const LPSTR EVENT_SOURCE_SECURITY
= "Security";
40 static const LPSTR EVENT_SOURCE_SYSTEM
= "System";
41 static const TCHAR szWindowClass
[] = _T("EVENTVWR"); // the main window class name
43 //MessageFile message buffer size
44 #define EVENT_MESSAGE_EVENTTEXT_BUFFER 1024*10
45 #define EVENT_MESSAGE_FILE_BUFFER 1024*10
46 #define EVENT_DLL_SEPARATOR ";"
47 #define EVENT_MESSAGE_FILE "EventMessageFile"
48 #define EVENT_CATEGORY_MESSAGE_FILE "CategoryMessageFile"
49 #define EVENT_PARAMETER_MESSAGE_FILE "ParameterMessageFile"
51 #define MAX_LOADSTRING 255
54 HINSTANCE hInst
; // current instance
55 TCHAR szTitle
[MAX_LOADSTRING
]; // The title bar text
58 HWND hwndMainWindow
; // Main window
59 HWND hwndListView
; // ListView control
60 HWND hwndStatus
; // Status bar
62 LPTSTR lpSourceLogName
= NULL
;
63 LPTSTR lpComputerName
= NULL
;
65 // Forward declarations of functions included in this code module:
66 ATOM
MyRegisterClass(HINSTANCE hInstance
);
67 BOOL
InitInstance(HINSTANCE
, int);
68 LRESULT CALLBACK
WndProc (HWND
, UINT
, WPARAM
, LPARAM
);
69 INT_PTR CALLBACK
About (HWND
, UINT
, WPARAM
, LPARAM
);
70 INT_PTR CALLBACK
EventDetails (HWND
, UINT
, WPARAM
, LPARAM
);
71 static INT_PTR CALLBACK
StatusMessageWindowProc (HWND
, UINT
, WPARAM
, LPARAM
);
73 int APIENTRY
_tWinMain(HINSTANCE hInstance
,
74 HINSTANCE hPrevInstance
,
80 INITCOMMONCONTROLSEX iccx
;
82 UNREFERENCED_PARAMETER(hPrevInstance
);
83 UNREFERENCED_PARAMETER(lpCmdLine
);
85 // Whenever any of the common controls are used in your app,
86 // you must call InitCommonControlsEx() to register the classes
87 // for those controls.
88 iccx
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
89 iccx
.dwICC
= ICC_LISTVIEW_CLASSES
;
90 InitCommonControlsEx(&iccx
);
92 // Initialize global strings
93 LoadString(hInstance
, IDS_APP_TITLE
, szTitle
, MAX_LOADSTRING
);
94 MyRegisterClass(hInstance
);
96 // Perform application initialization:
97 if (!InitInstance (hInstance
, nCmdShow
))
102 hAccelTable
= LoadAccelerators(hInstance
, MAKEINTRESOURCE(IDC_EVENTVWR
));
104 // Main message loop:
105 while (GetMessage(&msg
, NULL
, 0, 0))
107 if (!TranslateAccelerator(msg
.hwnd
, hAccelTable
, &msg
))
109 TranslateMessage(&msg
);
110 DispatchMessage(&msg
);
114 return (int) msg
.wParam
;
117 VOID
EventTimeToSystemTime (DWORD EventTime
, SYSTEMTIME
*pSystemTime
)
119 SYSTEMTIME st1970
= { 1970, 1, 0, 1, 0, 0, 0, 0 };
126 uUCT
.ft
.dwHighDateTime
= 0;
127 uUCT
.ft
.dwLowDateTime
= EventTime
;
128 SystemTimeToFileTime(&st1970
, &u1970
.ft
);
129 uUCT
.ll
= uUCT
.ll
* 10000000 + u1970
.ll
;
130 FileTimeToLocalFileTime(&uUCT
.ft
, &ftLocal
);
131 FileTimeToSystemTime(&ftLocal
, pSystemTime
);
135 TrimNulls ( LPSTR s
)
139 if ( s
!= (char *) NULL
)
141 c
= s
+ strlen ( s
) - 1;
142 while ( c
>= s
&& isspace ( *c
) )
148 BOOL
GetEventMessageFileDLL(
149 IN LPCTSTR lpLogName
,
150 IN LPCTSTR SourceName
,
151 IN LPCTSTR EntryName
,
152 OUT LPSTR ExpandedName
)
155 BYTE szModuleName
[MAX_PATH
];
156 TCHAR szKeyName
[MAX_PATH
];
158 HKEY hSourceKey
= NULL
;
159 BOOL bReturn
= FALSE
; // Return
161 _tcscpy(szKeyName
, TEXT("SYSTEM\\CurrentControlSet\\Services\\EventLog"));
162 _tcscat(szKeyName
, _T("\\"));
163 _tcscat(szKeyName
, lpLogName
);
170 &hAppKey
) == ERROR_SUCCESS
)
177 &hSourceKey
) == ERROR_SUCCESS
)
185 (LPBYTE
)szModuleName
,
186 &dwSize
) == ERROR_SUCCESS
)
188 // Returns a string containing the requested substituted environment variable.
189 ExpandEnvironmentStrings ((LPCTSTR
)szModuleName
, ExpandedName
, MAX_PATH
);
199 _TEXT("Registry access failed!") ,
201 MB_OK
| MB_ICONINFORMATION
);
204 if (hSourceKey
!= NULL
)
205 RegCloseKey(hSourceKey
);
208 RegCloseKey(hAppKey
);
213 BOOL
GetEventCategory(
215 IN LPCTSTR SourceName
,
216 IN EVENTLOGRECORD
*pevlr
,
217 OUT LPTSTR CategoryName
)
219 HANDLE hLibrary
= NULL
;
220 TCHAR szMessageDLL
[MAX_PATH
];
221 LPVOID lpMsgBuf
= NULL
;
223 if(GetEventMessageFileDLL (KeyName
, SourceName
, EVENT_CATEGORY_MESSAGE_FILE
, szMessageDLL
))
225 hLibrary
= LoadLibraryEx(
228 DONT_RESOLVE_DLL_REFERENCES
| LOAD_LIBRARY_AS_DATAFILE
);
232 // Retrieve the message string.
234 FORMAT_MESSAGE_FROM_SYSTEM
| FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_HMODULE
| FORMAT_MESSAGE_ARGUMENT_ARRAY
,
236 pevlr
->EventCategory
,
237 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
239 EVENT_MESSAGE_FILE_BUFFER
,
245 TrimNulls ((LPSTR
)lpMsgBuf
);
247 // Copy the category name
248 strcpy (CategoryName
, (LPCTSTR
)lpMsgBuf
);
252 strcpy (CategoryName
, (LPCTSTR
)lpMsgBuf
);
255 strcpy (CategoryName
, "None");
259 FreeLibrary(hLibrary
);
261 // Free the buffer allocated by FormatMessage
269 strcpy (CategoryName
, "None");
274 BOOL
GetEventMessage(
276 IN LPCTSTR SourceName
,
277 IN EVENTLOGRECORD
*pevlr
,
278 OUT LPTSTR EventText
)
281 HANDLE hLibrary
= NULL
;
282 char SourceModuleName
[1000];
283 char ParameterModuleName
[1000];
284 LPTSTR lpMsgBuf
= NULL
;
285 TCHAR szStringIDNotFound
[MAX_LOADSTRING
];
291 /* TODO : GetEventMessageFileDLL can return a comma separated list of DLLs */
292 if (GetEventMessageFileDLL (KeyName
, SourceName
, EVENT_MESSAGE_FILE
, SourceModuleName
))
294 // Get the event message
295 szMessage
= (LPTSTR
)((LPBYTE
)pevlr
+ pevlr
->StringOffset
);
297 // Allocate space for parameters
298 szArguments
= (LPTSTR
*)malloc(sizeof(LPVOID
)* pevlr
->NumStrings
);
304 for (i
= 0; i
< pevlr
->NumStrings
; i
++)
306 if (strstr(szMessage
, "%%"))
308 if (GetEventMessageFileDLL (KeyName
, SourceName
, EVENT_PARAMETER_MESSAGE_FILE
, ParameterModuleName
))
310 //Not yet support for reading messages from parameter message DLL
313 szArguments
[i
] = szMessage
;
314 szMessage
+= strlen(szMessage
) + 1;
318 szArguments
[i
] = szMessage
;
319 szMessage
+= strlen(szMessage
) + 1;
323 szDll
= strtok(SourceModuleName
, EVENT_DLL_SEPARATOR
);
324 while ((szDll
!= NULL
) && (!bDone
))
326 hLibrary
= LoadLibraryEx(
329 DONT_RESOLVE_DLL_REFERENCES
| LOAD_LIBRARY_AS_DATAFILE
);
331 if (hLibrary
== NULL
)
333 // The DLL could not be loaded try the next one (if any)
334 szDll
= strtok (NULL
, EVENT_DLL_SEPARATOR
);
338 // Retrieve the message string.
340 FORMAT_MESSAGE_FROM_SYSTEM
|
341 FORMAT_MESSAGE_ALLOCATE_BUFFER
|
342 FORMAT_MESSAGE_FROM_HMODULE
|
343 FORMAT_MESSAGE_ARGUMENT_ARRAY
,
346 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
351 // We haven't found the string , get next DLL (if any)
352 szDll
= strtok (NULL
, EVENT_DLL_SEPARATOR
);
358 // The ID was found and the message was formated
362 TrimNulls ((LPSTR
)lpMsgBuf
);
364 // Copy the event text
365 strcpy (EventText
,lpMsgBuf
);
369 FreeLibrary (hLibrary
);
375 LoadString(hInst
, IDC_EVENTSTRINGIDNOTFOUND
, szStringIDNotFound
, MAX_LOADSTRING
);
376 wsprintf (EventText
, szStringIDNotFound
, (DWORD
)(pevlr
->EventID
& 0xFFFF) , SourceName
);
381 // No more dlls to try , return result
385 LoadString(hInst
, IDC_EVENTSTRINGIDNOTFOUND
, szStringIDNotFound
, MAX_LOADSTRING
);
386 wsprintf (EventText
, szStringIDNotFound
, (DWORD
)(pevlr
->EventID
& 0xFFFF) , SourceName
);
392 GetEventType (WORD dwEventType
, OUT LPSTR eventTypeText
)
396 case EVENTLOG_ERROR_TYPE
:
397 LoadString(hInst
, IDC_EVENTLOG_ERROR_TYPE
, eventTypeText
, MAX_LOADSTRING
);
399 case EVENTLOG_WARNING_TYPE
:
400 LoadString(hInst
, IDC_EVENTLOG_WARNING_TYPE
, eventTypeText
, MAX_LOADSTRING
);
402 case EVENTLOG_INFORMATION_TYPE
:
403 LoadString(hInst
, IDC_EVENTLOG_INFORMATION_TYPE
, eventTypeText
, MAX_LOADSTRING
);
405 case EVENTLOG_AUDIT_SUCCESS
:
406 LoadString(hInst
, IDC_EVENTLOG_AUDIT_SUCCESS
, eventTypeText
, MAX_LOADSTRING
);
408 case EVENTLOG_AUDIT_FAILURE
:
409 LoadString(hInst
, IDC_EVENTLOG_AUDIT_FAILURE
, eventTypeText
, MAX_LOADSTRING
);
411 case EVENTLOG_SUCCESS
:
412 LoadString(hInst
, IDC_EVENTLOG_SUCCESS
, eventTypeText
, MAX_LOADSTRING
);
415 LoadString(hInst
, IDC_EVENTLOG_UNKNOWN_TYPE
, eventTypeText
, MAX_LOADSTRING
);
421 GetEventUserName (EVENTLOGRECORD
*pelr
, OUT LPSTR pszUser
)
428 DWORD cbDomain
= 1024;
431 lpSid
= (PSID
)((LPBYTE
) pelr
+ pelr
->UserSidOffset
);
434 if(pelr
->UserSidLength
> 0)
436 if (LookupAccountSid(
445 strcpy (pszUser
, szName
);
454 ShowStatusMessageThread(
455 IN LPVOID lpParameter
)
457 HWND
*phWnd
= (HWND
*)lpParameter
;
461 hWnd
= CreateDialogParam(
463 MAKEINTRESOURCE(IDD_PROGRESSBOX
),
465 StatusMessageWindowProc
,
471 ShowWindow(hWnd
, SW_SHOW
);
473 /* Message loop for the Status window */
474 while (GetMessage(&Msg
, NULL
, 0, 0))
476 TranslateMessage(&Msg
);
477 DispatchMessage(&Msg
);
483 VOID
QueryEventMessages (
484 LPTSTR lpMachineName
,
489 EVENTLOGRECORD
*pevlr
;
490 BYTE bBuffer
[MAX_PATH
];
491 DWORD dwRead
, dwNeeded
, dwThisRecord
, dwTotalRecords
, dwCurrentRecord
= 1 , dwRecordsToRead
= 0 , dwFlags
;
493 LPSTR lpComputerName
;
496 BOOL bResult
= TRUE
; // Read succeeded.
498 char szWindowTitle
[MAX_PATH
];
499 char szStatusText
[MAX_PATH
];
500 char szLocalDate
[MAX_PATH
];
501 char szLocalTime
[MAX_PATH
];
502 char szEventID
[MAX_PATH
];
503 char szEventTypeText
[MAX_PATH
];
504 char szCategoryID
[MAX_PATH
];
505 char szUsername
[MAX_PATH
];
506 char szEventText
[EVENT_MESSAGE_FILE_BUFFER
];
507 char szCategory
[MAX_PATH
];
512 dwFlags
= EVENTLOG_FORWARDS_READ
| EVENTLOG_SEQUENTIAL_READ
;
514 lpSourceLogName
= lpLogName
;
515 lpComputerName
= lpMachineName
;
517 // Open the event log.
518 hEventLog
= OpenEventLog(
522 if (hEventLog
== NULL
)
525 _TEXT("Could not open the event log.") ,
527 MB_OK
| MB_ICONINFORMATION
);
531 //Disable listview redraw
532 SendMessage(hwndListView
, WM_SETREDRAW
, FALSE
, 0);
534 // Clear the list view
535 (void)ListView_DeleteAllItems (hwndListView
);
537 // Initialize the event record buffer.
538 pevlr
= (EVENTLOGRECORD
*)&bBuffer
;
540 // Get the record number of the oldest event log record.
541 GetOldestEventLogRecord(hEventLog
, &dwThisRecord
);
543 // Get the total number of event log records.
544 GetNumberOfEventLogRecords (hEventLog
, &dwTotalRecords
);
546 //If we have at least 1000 records show the waiting dialog
547 if (dwTotalRecords
> 1000)
552 ShowStatusMessageThread
,
558 while (dwCurrentRecord
< dwTotalRecords
)
560 pevlr
= (EVENTLOGRECORD
*)malloc(MAX_PATH
);
562 bResult
= ReadEventLog(
563 hEventLog
, // Event log handle
564 dwFlags
, // Sequential read
565 0, // Ignored for sequential read
566 pevlr
, // Pointer to buffer
567 MAX_PATH
, // Size of buffer
568 &dwRead
, // Number of bytes read
569 &dwNeeded
); // Bytes in the next record
571 if((!bResult
) && (GetLastError () == ERROR_INSUFFICIENT_BUFFER
))
573 pevlr
= (EVENTLOGRECORD
*)malloc (dwNeeded
);
576 hEventLog
, // event log handle
577 dwFlags
, // read flags
578 0, // offset; default is 0
579 pevlr
, // pointer to buffer
580 dwNeeded
, // size of buffer
581 &dwRead
, // number of bytes read
582 &dwNeeded
); // bytes in next record
587 strcpy (szUsername
, "N/A");
588 strcpy (szEventText
, "N/A");
589 strcpy (szCategory
, "None");
591 // Get the event source name.
592 lpSourceName
= (LPSTR
) ((LPBYTE
) pevlr
+ sizeof(EVENTLOGRECORD
));
594 // Get the computer name
595 lpComputerName
= (LPSTR
) ((LPBYTE
) pevlr
+ sizeof(EVENTLOGRECORD
) + lstrlen(lpSourceName
) + 1);
597 // This ist the data section of the current event
598 lpData
= (LPSTR
) ((LPBYTE
)pevlr
+ pevlr
->DataOffset
);
600 // This is the text of the current event
601 lpEventStr
= (LPSTR
) ((LPBYTE
) pevlr
+ pevlr
->StringOffset
);
603 // Compute the event type
604 EventTimeToSystemTime(pevlr
->TimeWritten
, &time
);
606 // Get the username that generated the event
607 GetEventUserName (pevlr
, szUsername
);
609 GetDateFormat( LOCALE_USER_DEFAULT
, DATE_SHORTDATE
, &time
, NULL
, szLocalDate
, MAX_PATH
);
610 GetTimeFormat( LOCALE_USER_DEFAULT
, TIME_NOSECONDS
, &time
, NULL
, szLocalTime
, MAX_PATH
);
612 GetEventType (pevlr
->EventType
, szEventTypeText
);
613 GetEventCategory (lpLogName
, lpSourceName
, pevlr
, szCategory
);
615 wsprintf (szEventID
, "%u", (DWORD
)(pevlr
->EventID
& 0xFFFF));
616 wsprintf (szCategoryID
, "%u", (DWORD
)(pevlr
->EventCategory
));
618 lviEventItem
.mask
= LVIF_IMAGE
| LVIF_TEXT
| LVIF_PARAM
;
619 lviEventItem
.iItem
= 0;
620 lviEventItem
.iSubItem
= 0;
621 lviEventItem
.lParam
= (LPARAM
)pevlr
;
622 lviEventItem
.pszText
= szEventTypeText
;
624 switch(pevlr
->EventType
)
626 case EVENTLOG_ERROR_TYPE
:
627 lviEventItem
.iImage
= 2;
629 case EVENTLOG_AUDIT_FAILURE
:
630 lviEventItem
.iImage
= 2;
632 case EVENTLOG_WARNING_TYPE
:
633 lviEventItem
.iImage
= 1;
635 case EVENTLOG_INFORMATION_TYPE
:
636 lviEventItem
.iImage
= 0;
638 case EVENTLOG_AUDIT_SUCCESS
:
639 lviEventItem
.iImage
= 0;
641 case EVENTLOG_SUCCESS
:
642 lviEventItem
.iImage
= 0;
646 lviEventItem
.iItem
= ListView_InsertItem(hwndListView
, &lviEventItem
);
648 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 1, szLocalDate
);
649 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 2, szLocalTime
);
650 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 3, lpSourceName
);
651 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 4, szCategory
);
652 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 5, szEventID
);
653 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 6, szUsername
); //User
654 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 7, lpComputerName
); //Computer
655 ListView_SetItemText(hwndListView
, lviEventItem
.iItem
, 8, lpData
); //Event Text
657 dwRead
-= pevlr
->Length
;
658 pevlr
= (EVENTLOGRECORD
*) ((LPBYTE
) pevlr
+ pevlr
->Length
);
664 pevlr
= (EVENTLOGRECORD
*) &bBuffer
;
668 EndDialog(hwndDlg
, 0);
670 wsprintf (szWindowTitle
, "%s - %s Log on \\\\%s", szTitle
, lpLogName
, lpComputerName
);
671 wsprintf (szStatusText
, "%s has %d event(s)", lpLogName
, dwTotalRecords
);
673 //Update the status bar
674 SendMessage (hwndStatus
, SB_SETTEXT
, (WPARAM
)0, (LPARAM
)szStatusText
);
676 //Set the window title
677 SetWindowText ( hwndMainWindow
, szWindowTitle
);
679 //Resume list view redraw
680 SendMessage(hwndListView
, WM_SETREDRAW
, TRUE
, 0);
682 // Close the event log.
683 CloseEventLog(hEventLog
);
695 // FUNCTION: MyRegisterClass()
697 // PURPOSE: Registers the window class.
701 // This function and its usage are only necessary if you want this code
702 // to be compatible with Win32 systems prior to the 'RegisterClassEx'
703 // function that was added to Windows 95. It is important to call this function
704 // so that the application will get 'well formed' small icons associated
707 ATOM
MyRegisterClass(HINSTANCE hInstance
)
711 wcex
.cbSize
= sizeof(WNDCLASSEX
);
713 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
714 wcex
.lpfnWndProc
= WndProc
;
717 wcex
.hInstance
= hInstance
;
718 wcex
.hIcon
= LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_EVENTVWR
));
719 wcex
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
720 wcex
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
721 wcex
.lpszMenuName
= MAKEINTRESOURCE(IDC_EVENTVWR
);
722 wcex
.lpszClassName
= szWindowClass
;
723 wcex
.hIconSm
= LoadIcon(wcex
.hInstance
, MAKEINTRESOURCE(IDI_SMALL
));
725 return RegisterClassEx(&wcex
);
729 // FUNCTION: InitInstance(HINSTANCE, int)
731 // PURPOSE: Saves instance handle and creates main window
735 // In this function, we save the instance handle in a global variable and
736 // create and display the main program window.
738 BOOL
InitInstance(HINSTANCE hInstance
, int nCmdShow
)
743 hInst
= hInstance
; // Store instance handle in our global variable
745 hwndMainWindow
= CreateWindow(
749 CW_USEDEFAULT
, 0, CW_USEDEFAULT
, 0,
760 hwndStatus
= CreateWindowEx(
761 0, // no extended styles
762 STATUSCLASSNAME
, // status bar
764 WS_CHILD
| WS_BORDER
| WS_VISIBLE
, // styles
765 0, 0, 0, 0, // x, y, cx, cy
766 hwndMainWindow
, // parent window
767 (HMENU
)100, // window ID
768 hInstance
, // instance
769 NULL
); // window data
771 // Create our listview child window. Note that I use WS_EX_CLIENTEDGE
772 // and WS_BORDER to create the normal "sunken" look. Also note that
773 // LVS_EX_ styles cannot be set in CreateWindowEx().
774 hwndListView
= CreateWindowEx(
778 LVS_SHOWSELALWAYS
| WS_CHILD
| WS_VISIBLE
| LVS_REPORT
,
788 // After the ListView is created, we can add extended list view styles.
789 (void)ListView_SetExtendedListViewStyle (hwndListView
, LVS_EX_FULLROWSELECT
);
791 // Create the ImageList
792 hSmall
= ImageList_Create(
793 GetSystemMetrics(SM_CXSMICON
),
794 GetSystemMetrics(SM_CYSMICON
),
799 // Add event type icons to ImageList
800 ImageList_AddIcon (hSmall
, LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_INFORMATIONICON
)));
801 ImageList_AddIcon (hSmall
, LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_WARNINGICON
)));
802 ImageList_AddIcon (hSmall
, LoadIcon(hInstance
, MAKEINTRESOURCE(IDI_ERRORICON
)));
804 // Assign ImageList to List View
805 (void)ListView_SetImageList (hwndListView
, hSmall
, LVSIL_SMALL
);
807 // Now set up the listview with its columns.
808 lvc
.mask
= LVCF_TEXT
| LVCF_WIDTH
;
810 lvc
.pszText
= _T("Type");
811 (void)ListView_InsertColumn(hwndListView
, 0, &lvc
);
814 lvc
.pszText
= _T("Date");
815 (void)ListView_InsertColumn(hwndListView
, 1, &lvc
);
818 lvc
.pszText
= _T("Time");
819 (void)ListView_InsertColumn(hwndListView
, 2, &lvc
);
822 lvc
.pszText
= _T("Source");
823 (void)ListView_InsertColumn(hwndListView
, 3, &lvc
);
826 lvc
.pszText
= _T("Category");
827 (void)ListView_InsertColumn(hwndListView
, 4, &lvc
);
830 lvc
.pszText
= _T("Event");
831 (void)ListView_InsertColumn(hwndListView
, 5, &lvc
);
834 lvc
.pszText
= _T("User");
835 (void)ListView_InsertColumn(hwndListView
, 6, &lvc
);
838 lvc
.pszText
= _T("Computer");
839 (void)ListView_InsertColumn(hwndListView
, 7, &lvc
);
842 lvc
.pszText
= _T("Event Data");
843 (void)ListView_InsertColumn(hwndListView
, 8, &lvc
);
845 ShowWindow(hwndMainWindow
, nCmdShow
);
846 UpdateWindow(hwndMainWindow
);
849 lpComputerName
, // Use the local computer.
850 EVENT_SOURCE_APPLICATION
); // The event log category
856 // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
858 // PURPOSE: Processes messages for the main window.
860 // WM_COMMAND - process the application menu
861 // WM_PAINT - Paint the main window
862 // WM_DESTROY - post a quit message and return
865 LRESULT CALLBACK
WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
875 switch(((LPNMHDR
)lParam
)->code
)
878 hdr
= (NMHDR FAR
*)lParam
;
879 if(hdr
->hwndFrom
== hwndListView
)
881 LPNMITEMACTIVATE lpnmitem
= (LPNMITEMACTIVATE
)lParam
;
883 if(lpnmitem
->iItem
!= -1)
885 DialogBox (hInst
, MAKEINTRESOURCE(IDD_EVENTDETAILDIALOG
), hWnd
, EventDetails
);
892 wmId
= LOWORD(wParam
);
893 wmEvent
= HIWORD(wParam
);
895 if ((wmId
== ID_LOG_APPLICATION
) ||
896 (wmId
== ID_LOG_SYSTEM
) ||
897 (wmId
== ID_LOG_SECURITY
))
899 hMenu
= GetMenu (hWnd
) ; // get the menu handle. Use it below
901 CheckMenuItem (hMenu
, ID_LOG_APPLICATION
, MF_UNCHECKED
) ;
902 CheckMenuItem (hMenu
, ID_LOG_SYSTEM
, MF_UNCHECKED
) ;
903 CheckMenuItem (hMenu
, ID_LOG_SECURITY
, MF_UNCHECKED
) ;
907 CheckMenuItem (hMenu
, wmId
, MF_CHECKED
) ;
911 // Parse the menu selections:
914 case ID_LOG_APPLICATION
:
916 lpComputerName
, // Use the local computer.
917 EVENT_SOURCE_APPLICATION
); // The event log category
921 lpComputerName
, // Use the local computer.
922 EVENT_SOURCE_SYSTEM
); // The event log category
924 case ID_LOG_SECURITY
:
926 lpComputerName
, // Use the local computer.
927 EVENT_SOURCE_SECURITY
); // The event log category
933 DialogBox(hInst
, MAKEINTRESOURCE(IDD_ABOUTBOX
), hWnd
, About
);
938 _TEXT("Help not implemented yet!") ,
940 MB_OK
| MB_ICONINFORMATION
);
946 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
951 //Gets the window rectangle
952 GetClientRect(hWnd
, &rect
);
954 //Relocate the listview
963 // Resize the statusbar;
964 SendMessage (hwndStatus
, message
, wParam
, lParam
);
971 return DefWindowProc(hWnd
, message
, wParam
, lParam
);
976 // Message handler for about box.
977 INT_PTR CALLBACK
About(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
979 UNREFERENCED_PARAMETER(lParam
);
984 return (INT_PTR
)TRUE
;
987 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
989 EndDialog(hDlg
, LOWORD(wParam
));
990 return (INT_PTR
)TRUE
;
995 return (INT_PTR
)FALSE
;
999 DisplayEvent (HWND hDlg
)
1001 char szEventType
[MAX_PATH
];
1002 char szTime
[MAX_PATH
];
1003 char szDate
[MAX_PATH
];
1004 char szUser
[MAX_PATH
];
1005 char szComputer
[MAX_PATH
];
1006 char szSource
[MAX_PATH
];
1007 char szCategory
[MAX_PATH
];
1008 char szEventID
[MAX_PATH
];
1009 char szEventText
[EVENT_MESSAGE_EVENTTEXT_BUFFER
];
1010 char szEventData
[MAX_PATH
];
1011 BOOL bEventData
= FALSE
;
1013 EVENTLOGRECORD
* pevlr
;
1015 // Get index of selected item
1016 int iIndex
= (int)SendMessage (hwndListView
,LVM_GETNEXTITEM
, -1 , LVNI_SELECTED
| LVNI_FOCUSED
);
1018 li
.mask
= LVIF_PARAM
;
1022 (void)ListView_GetItem(hwndListView
, &li
);
1024 pevlr
= (EVENTLOGRECORD
*)li
.lParam
;
1028 ListView_GetItemText (hwndListView
, iIndex
, 0 , szEventType
, sizeof( szEventType
));
1029 ListView_GetItemText (hwndListView
, iIndex
, 1 , szDate
, sizeof( szDate
));
1030 ListView_GetItemText (hwndListView
, iIndex
, 2 , szTime
, sizeof( szTime
));
1031 ListView_GetItemText (hwndListView
, iIndex
, 3 , szSource
, sizeof( szSource
));
1032 ListView_GetItemText (hwndListView
, iIndex
, 4 , szCategory
, sizeof( szCategory
));
1033 ListView_GetItemText (hwndListView
, iIndex
, 5 , szEventID
, sizeof( szEventID
));
1034 ListView_GetItemText (hwndListView
, iIndex
, 6 , szUser
, sizeof( szUser
));
1035 ListView_GetItemText (hwndListView
, iIndex
, 7 , szComputer
, sizeof( szComputer
));
1036 ListView_GetItemText (hwndListView
, iIndex
, 8 , szEventData
, sizeof( szEventData
));
1038 bEventData
= !(strlen(szEventData
) == 0);
1040 GetEventMessage (lpSourceLogName
, szSource
, pevlr
, szEventText
);
1042 EnableWindow(GetDlgItem(hDlg
, IDC_BYTESRADIO
) , bEventData
);
1043 EnableWindow(GetDlgItem(hDlg
, IDC_WORDRADIO
) , bEventData
);
1045 SetDlgItemText (hDlg
, IDC_EVENTDATESTATIC
, szDate
);
1046 SetDlgItemText (hDlg
, IDC_EVENTTIMESTATIC
, szTime
);
1047 SetDlgItemText (hDlg
, IDC_EVENTUSERSTATIC
, szUser
);
1048 SetDlgItemText (hDlg
, IDC_EVENTSOURCESTATIC
, szSource
);
1049 SetDlgItemText (hDlg
, IDC_EVENTCOMPUTERSTATIC
, szComputer
);
1050 SetDlgItemText (hDlg
, IDC_EVENTCATEGORYSTATIC
, szCategory
);
1051 SetDlgItemText (hDlg
, IDC_EVENTIDSTATIC
, szEventID
);
1052 SetDlgItemText (hDlg
, IDC_EVENTTYPESTATIC
, szEventType
);
1053 SetDlgItemText (hDlg
, IDC_EVENTTEXTEDIT
, szEventText
);
1054 SetDlgItemText (hDlg
, IDC_EVENTDATAEDIT
, szEventData
);
1060 "No Items in ListView",
1062 MB_OK
| MB_ICONINFORMATION
);
1067 INT_PTR CALLBACK
StatusMessageWindowProc(
1073 UNREFERENCED_PARAMETER(wParam
);
1085 // Message handler for event details box.
1086 INT_PTR CALLBACK
EventDetails(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1088 UNREFERENCED_PARAMETER(lParam
);
1093 // Show event info on dialog box
1094 DisplayEvent (hDlg
);
1095 return (INT_PTR
)TRUE
;
1099 if (LOWORD(wParam
) == IDOK
|| LOWORD(wParam
) == IDCANCEL
)
1101 EndDialog(hDlg
, LOWORD(wParam
));
1102 return (INT_PTR
)TRUE
;
1104 if (LOWORD(wParam
) == IDPREVIOUS
)
1106 SendMessage (hwndListView
, WM_KEYDOWN
, VK_UP
, 0);
1108 // Show event info on dialog box
1109 DisplayEvent (hDlg
);
1110 return (INT_PTR
)TRUE
;
1113 if (LOWORD(wParam
) == IDNEXT
)
1115 SendMessage (hwndListView
, WM_KEYDOWN
, VK_DOWN
, 0);
1117 // Show event info on dialog box
1118 DisplayEvent (hDlg
);
1119 return (INT_PTR
)TRUE
;
1122 if (LOWORD(wParam
) == IDC_BYTESRADIO
)
1124 return (INT_PTR
)TRUE
;
1127 if (LOWORD(wParam
) == IDC_WORDRADIO
)
1129 return (INT_PTR
)TRUE
;
1132 if (LOWORD(wParam
) == IDHELP
)
1135 _TEXT("Help not implemented yet!") ,
1136 _TEXT("Event Log") ,
1137 MB_OK
| MB_ICONINFORMATION
);
1138 return (INT_PTR
)TRUE
;
1142 return (INT_PTR
)FALSE
;