Replace TABs by Spaces.

No code changes!

svn path=/trunk/; revision=37564
This commit is contained in:
Eric Kohl 2008-11-22 19:25:48 +00:00
parent 01f04141d9
commit db8c3e9162
2 changed files with 793 additions and 774 deletions

View file

@ -65,12 +65,14 @@ LPTSTR lpComputerName = NULL;
// Forward declarations of functions included in this code module: // Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance); ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int); BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK EventDetails (HWND, UINT, WPARAM, LPARAM); INT_PTR CALLBACK EventDetails(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK StatusMessageWindowProc (HWND, UINT, WPARAM, LPARAM); static INT_PTR CALLBACK StatusMessageWindowProc (HWND, UINT, WPARAM, LPARAM);
int APIENTRY _tWinMain(HINSTANCE hInstance,
int APIENTRY
_tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, LPTSTR lpCmdLine,
int nCmdShow) int nCmdShow)
@ -94,7 +96,7 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
MyRegisterClass(hInstance); MyRegisterClass(hInstance);
// Perform application initialization: // Perform application initialization:
if (!InitInstance (hInstance, nCmdShow)) if (!InitInstance(hInstance, nCmdShow))
{ {
return FALSE; return FALSE;
} }
@ -111,14 +113,18 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
} }
} }
return (int) msg.wParam; return (int)msg.wParam;
} }
VOID EventTimeToSystemTime (DWORD EventTime, SYSTEMTIME *pSystemTime)
VOID
EventTimeToSystemTime(DWORD EventTime,
SYSTEMTIME *pSystemTime)
{ {
SYSTEMTIME st1970 = { 1970, 1, 0, 1, 0, 0, 0, 0 }; SYSTEMTIME st1970 = { 1970, 1, 0, 1, 0, 0, 0, 0 };
FILETIME ftLocal; FILETIME ftLocal;
union { union
{
FILETIME ft; FILETIME ft;
ULONGLONG ll; ULONGLONG ll;
} u1970, uUCT; } u1970, uUCT;
@ -131,8 +137,9 @@ VOID EventTimeToSystemTime (DWORD EventTime, SYSTEMTIME *pSystemTime)
FileTimeToSystemTime(&ftLocal, pSystemTime); FileTimeToSystemTime(&ftLocal, pSystemTime);
} }
void void
TrimNulls ( LPSTR s ) TrimNulls(LPSTR s)
{ {
char *c; char *c;
@ -145,8 +152,9 @@ TrimNulls ( LPSTR s )
} }
} }
BOOL GetEventMessageFileDLL(
IN LPCTSTR lpLogName, BOOL
GetEventMessageFileDLL(IN LPCTSTR lpLogName,
IN LPCTSTR SourceName, IN LPCTSTR SourceName,
IN LPCTSTR EntryName, IN LPCTSTR EntryName,
OUT LPSTR ExpandedName) OUT LPSTR ExpandedName)
@ -162,23 +170,20 @@ BOOL GetEventMessageFileDLL(
_tcscat(szKeyName, _T("\\")); _tcscat(szKeyName, _T("\\"));
_tcscat(szKeyName, lpLogName); _tcscat(szKeyName, lpLogName);
if (RegOpenKeyEx( if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
HKEY_LOCAL_MACHINE,
szKeyName, szKeyName,
0, 0,
KEY_READ, KEY_READ,
&hAppKey) == ERROR_SUCCESS) &hAppKey) == ERROR_SUCCESS)
{ {
if (RegOpenKeyEx( if (RegOpenKeyEx(hAppKey,
hAppKey,
SourceName, SourceName,
0, 0,
KEY_READ, KEY_READ,
&hSourceKey) == ERROR_SUCCESS) &hSourceKey) == ERROR_SUCCESS)
{ {
dwSize = MAX_PATH; dwSize = MAX_PATH;
if (RegQueryValueEx( if (RegQueryValueEx(hSourceKey,
hSourceKey,
EntryName, EntryName,
NULL, NULL,
NULL, NULL,
@ -195,9 +200,9 @@ BOOL GetEventMessageFileDLL(
} }
else else
{ {
MessageBox (NULL , MessageBox(NULL,
_TEXT("Registry access failed!") , _TEXT("Registry access failed!"),
_TEXT("Event Log") , _TEXT("Event Log"),
MB_OK | MB_ICONINFORMATION); MB_OK | MB_ICONINFORMATION);
} }
@ -210,8 +215,9 @@ BOOL GetEventMessageFileDLL(
return bReturn; return bReturn;
} }
BOOL GetEventCategory(
IN LPCTSTR KeyName, BOOL
GetEventCategory(IN LPCTSTR KeyName,
IN LPCTSTR SourceName, IN LPCTSTR SourceName,
IN EVENTLOGRECORD *pevlr, IN EVENTLOGRECORD *pevlr,
OUT LPTSTR CategoryName) OUT LPTSTR CategoryName)
@ -220,18 +226,15 @@ BOOL GetEventCategory(
TCHAR szMessageDLL[MAX_PATH]; TCHAR szMessageDLL[MAX_PATH];
LPVOID lpMsgBuf = NULL; LPVOID lpMsgBuf = NULL;
if(GetEventMessageFileDLL (KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE , szMessageDLL)) if (GetEventMessageFileDLL (KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE , szMessageDLL))
{ {
hLibrary = LoadLibraryEx( hLibrary = LoadLibraryEx(szMessageDLL,
szMessageDLL,
NULL, NULL,
DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if (hLibrary != NULL)
if(hLibrary != NULL)
{ {
// Retrieve the message string. // Retrieve the message string.
if(FormatMessage( if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
hLibrary, hLibrary,
pevlr->EventCategory, pevlr->EventCategory,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
@ -241,21 +244,23 @@ BOOL GetEventCategory(
{ {
if (lpMsgBuf) if (lpMsgBuf)
{ {
//Trim the string // Trim the string
TrimNulls ((LPSTR)lpMsgBuf); TrimNulls((LPSTR)lpMsgBuf);
// Copy the category name // Copy the category name
strcpy (CategoryName, (LPCTSTR)lpMsgBuf); strcpy(CategoryName, (LPCTSTR)lpMsgBuf);
} }
else else
{ {
strcpy (CategoryName, (LPCTSTR)lpMsgBuf); strcpy(CategoryName, (LPCTSTR)lpMsgBuf);
} }
}else{ }
strcpy (CategoryName, "None"); else
{
strcpy(CategoryName, "None");
} }
if(hLibrary != NULL) if (hLibrary != NULL)
FreeLibrary(hLibrary); FreeLibrary(hLibrary);
// Free the buffer allocated by FormatMessage // Free the buffer allocated by FormatMessage
@ -266,13 +271,14 @@ BOOL GetEventCategory(
} }
} }
strcpy (CategoryName, "None"); strcpy(CategoryName, "None");
return FALSE; return FALSE;
} }
BOOL GetEventMessage(
IN LPCTSTR KeyName, BOOL
GetEventMessage(IN LPCTSTR KeyName,
IN LPCTSTR SourceName, IN LPCTSTR SourceName,
IN EVENTLOGRECORD *pevlr, IN EVENTLOGRECORD *pevlr,
OUT LPTSTR EventText) OUT LPTSTR EventText)
@ -305,9 +311,9 @@ BOOL GetEventMessage(
{ {
if (strstr(szMessage , "%%")) if (strstr(szMessage , "%%"))
{ {
if (GetEventMessageFileDLL (KeyName , SourceName, EVENT_PARAMETER_MESSAGE_FILE , ParameterModuleName)) if (GetEventMessageFileDLL(KeyName , SourceName, EVENT_PARAMETER_MESSAGE_FILE, ParameterModuleName))
{ {
//Not yet support for reading messages from parameter message DLL // Not yet support for reading messages from parameter message DLL
} }
szArguments[i] = szMessage; szArguments[i] = szMessage;
@ -323,21 +329,18 @@ BOOL GetEventMessage(
szDll = strtok(SourceModuleName, EVENT_DLL_SEPARATOR); szDll = strtok(SourceModuleName, EVENT_DLL_SEPARATOR);
while ((szDll != NULL) && (!bDone)) while ((szDll != NULL) && (!bDone))
{ {
hLibrary = LoadLibraryEx( hLibrary = LoadLibraryEx(szDll,
szDll,
NULL, NULL,
DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if (hLibrary == NULL) if (hLibrary == NULL)
{ {
// The DLL could not be loaded try the next one (if any) // The DLL could not be loaded try the next one (if any)
szDll = strtok (NULL, EVENT_DLL_SEPARATOR); szDll = strtok(NULL, EVENT_DLL_SEPARATOR);
} }
else else
{ {
// Retrieve the message string. // Retrieve the message string.
if(FormatMessage( if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ARGUMENT_ARRAY, FORMAT_MESSAGE_ARGUMENT_ARRAY,
@ -358,22 +361,22 @@ BOOL GetEventMessage(
// The ID was found and the message was formated // The ID was found and the message was formated
bDone = TRUE; bDone = TRUE;
//Trim the string // Trim the string
TrimNulls ((LPSTR)lpMsgBuf); TrimNulls((LPSTR)lpMsgBuf);
// Copy the event text // Copy the event text
strcpy (EventText ,lpMsgBuf); strcpy(EventText ,lpMsgBuf);
} }
} }
FreeLibrary (hLibrary); FreeLibrary(hLibrary);
} }
} }
if (!bDone) if (!bDone)
{ {
LoadString(hInst, IDC_EVENTSTRINGIDNOTFOUND, szStringIDNotFound, MAX_LOADSTRING); LoadString(hInst, IDC_EVENTSTRINGIDNOTFOUND, szStringIDNotFound, MAX_LOADSTRING);
wsprintf (EventText, szStringIDNotFound , (DWORD)(pevlr->EventID & 0xFFFF) , SourceName ); wsprintf(EventText, szStringIDNotFound, (DWORD)(pevlr->EventID & 0xFFFF), SourceName);
} }
free(szArguments); free(szArguments);
@ -383,15 +386,17 @@ BOOL GetEventMessage(
} }
LoadString(hInst, IDC_EVENTSTRINGIDNOTFOUND, szStringIDNotFound, MAX_LOADSTRING); LoadString(hInst, IDC_EVENTSTRINGIDNOTFOUND, szStringIDNotFound, MAX_LOADSTRING);
wsprintf (EventText, szStringIDNotFound , (DWORD)(pevlr->EventID & 0xFFFF) , SourceName ); wsprintf(EventText, szStringIDNotFound, (DWORD)(pevlr->EventID & 0xFFFF), SourceName);
return FALSE; return FALSE;
} }
VOID VOID
GetEventType (WORD dwEventType, OUT LPSTR eventTypeText) GetEventType(IN WORD dwEventType,
OUT LPSTR eventTypeText)
{ {
switch(dwEventType) switch (dwEventType)
{ {
case EVENTLOG_ERROR_TYPE: case EVENTLOG_ERROR_TYPE:
LoadString(hInst, IDC_EVENTLOG_ERROR_TYPE, eventTypeText, MAX_LOADSTRING); LoadString(hInst, IDC_EVENTLOG_ERROR_TYPE, eventTypeText, MAX_LOADSTRING);
@ -418,7 +423,7 @@ GetEventType (WORD dwEventType, OUT LPSTR eventTypeText)
} }
BOOL BOOL
GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser) GetEventUserName(EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
{ {
PSID lpSid; PSID lpSid;
char szName[1024]; char szName[1024];
@ -428,13 +433,12 @@ GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
DWORD cbDomain = 1024; DWORD cbDomain = 1024;
// Point to the SID. // Point to the SID.
lpSid = (PSID)((LPBYTE) pelr + pelr->UserSidOffset); lpSid = (PSID)((LPBYTE)pelr + pelr->UserSidOffset);
// User SID // User SID
if(pelr->UserSidLength > 0) if (pelr->UserSidLength > 0)
{ {
if (LookupAccountSid( if (LookupAccountSid(NULL,
NULL,
lpSid, lpSid,
szName, szName,
&cbName, &cbName,
@ -442,7 +446,7 @@ GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
&cbDomain, &cbDomain,
&peUse)) &peUse))
{ {
strcpy (pszUser , szName); strcpy(pszUser, szName);
return TRUE; return TRUE;
} }
} }
@ -450,22 +454,22 @@ GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
return FALSE; return FALSE;
} }
static DWORD WINAPI static DWORD WINAPI
ShowStatusMessageThread( ShowStatusMessageThread(IN LPVOID lpParameter)
IN LPVOID lpParameter)
{ {
HWND *phWnd = (HWND *)lpParameter; HWND *phWnd = (HWND *)lpParameter;
HWND hWnd; HWND hWnd;
MSG Msg; MSG Msg;
hWnd = CreateDialogParam( hWnd = CreateDialogParam(hInst,
hInst,
MAKEINTRESOURCE(IDD_PROGRESSBOX), MAKEINTRESOURCE(IDD_PROGRESSBOX),
GetDesktopWindow(), GetDesktopWindow(),
StatusMessageWindowProc, StatusMessageWindowProc,
(LPARAM)NULL); (LPARAM)NULL);
if (!hWnd) if (!hWnd)
return 0; return 0;
*phWnd = hWnd; *phWnd = hWnd;
ShowWindow(hWnd, SW_SHOW); ShowWindow(hWnd, SW_SHOW);
@ -480,15 +484,16 @@ ShowStatusMessageThread(
return 0; return 0;
} }
VOID QueryEventMessages (
LPTSTR lpMachineName , VOID
QueryEventMessages(LPTSTR lpMachineName,
LPTSTR lpLogName) LPTSTR lpLogName)
{ {
HWND hwndDlg; HWND hwndDlg;
HANDLE hEventLog; HANDLE hEventLog;
EVENTLOGRECORD *pevlr; EVENTLOGRECORD *pevlr;
BYTE bBuffer[MAX_PATH]; BYTE bBuffer[MAX_PATH];
DWORD dwRead, dwNeeded, dwThisRecord , dwTotalRecords , dwCurrentRecord = 1 , dwRecordsToRead = 0 , dwFlags; DWORD dwRead, dwNeeded, dwThisRecord, dwTotalRecords, dwCurrentRecord = 1, dwRecordsToRead = 0, dwFlags;
LPSTR lpSourceName; LPSTR lpSourceName;
LPSTR lpComputerName; LPSTR lpComputerName;
LPSTR lpEventStr; LPSTR lpEventStr;
@ -515,20 +520,18 @@ VOID QueryEventMessages (
lpComputerName = lpMachineName; lpComputerName = lpMachineName;
// Open the event log. // Open the event log.
hEventLog = OpenEventLog( hEventLog = OpenEventLog(lpMachineName,
lpMachineName,
lpLogName); lpLogName);
if (hEventLog == NULL) if (hEventLog == NULL)
{ {
MessageBox (NULL , MessageBox(NULL,
_TEXT("Could not open the event log.") , _TEXT("Could not open the event log."),
_TEXT("Event Log") , _TEXT("Event Log"),
MB_OK | MB_ICONINFORMATION); MB_OK | MB_ICONINFORMATION);
return; return;
} }
//Disable listview redraw // Disable listview redraw
SendMessage(hwndListView, WM_SETREDRAW, FALSE, 0); SendMessage(hwndListView, WM_SETREDRAW, FALSE, 0);
// Clear the list view // Clear the list view
@ -546,8 +549,7 @@ VOID QueryEventMessages (
//If we have at least 1000 records show the waiting dialog //If we have at least 1000 records show the waiting dialog
if (dwTotalRecords > 1000) if (dwTotalRecords > 1000)
{ {
CreateThread( CreateThread(NULL,
NULL,
0, 0,
ShowStatusMessageThread, ShowStatusMessageThread,
(LPVOID)&hwndDlg, (LPVOID)&hwndDlg,
@ -559,21 +561,18 @@ VOID QueryEventMessages (
{ {
pevlr = (EVENTLOGRECORD*)malloc(MAX_PATH); pevlr = (EVENTLOGRECORD*)malloc(MAX_PATH);
bResult = ReadEventLog( bResult = ReadEventLog(hEventLog, // Event log handle
hEventLog, // Event log handle
dwFlags, // Sequential read dwFlags, // Sequential read
0, // Ignored for sequential read 0, // Ignored for sequential read
pevlr, // Pointer to buffer pevlr, // Pointer to buffer
MAX_PATH, // Size of buffer MAX_PATH, // Size of buffer
&dwRead, // Number of bytes read &dwRead, // Number of bytes read
&dwNeeded); // Bytes in the next record &dwNeeded); // Bytes in the next record
if((!bResult) && (GetLastError () == ERROR_INSUFFICIENT_BUFFER)) if((!bResult) && (GetLastError () == ERROR_INSUFFICIENT_BUFFER))
{ {
pevlr = (EVENTLOGRECORD*)malloc (dwNeeded); pevlr = (EVENTLOGRECORD*)malloc (dwNeeded);
ReadEventLog( ReadEventLog(hEventLog, // event log handle
hEventLog, // event log handle
dwFlags, // read flags dwFlags, // read flags
0, // offset; default is 0 0, // offset; default is 0
pevlr, // pointer to buffer pevlr, // pointer to buffer
@ -584,36 +583,36 @@ VOID QueryEventMessages (
while (dwRead > 0) while (dwRead > 0)
{ {
strcpy (szUsername , "N/A"); strcpy(szUsername , "N/A");
strcpy (szEventText , "N/A"); strcpy(szEventText , "N/A");
strcpy (szCategory , "None"); strcpy(szCategory , "None");
// Get the event source name. // Get the event source name.
lpSourceName = (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD)); lpSourceName = (LPSTR)((LPBYTE)pevlr + sizeof(EVENTLOGRECORD));
// Get the computer name // Get the computer name
lpComputerName = (LPSTR) ((LPBYTE) pevlr + sizeof(EVENTLOGRECORD) + lstrlen(lpSourceName) + 1); lpComputerName = (LPSTR)((LPBYTE)pevlr + sizeof(EVENTLOGRECORD) + lstrlen(lpSourceName) + 1);
// This ist the data section of the current event // This ist the data section of the current event
lpData = (LPSTR) ((LPBYTE)pevlr + pevlr->DataOffset); lpData = (LPSTR)((LPBYTE)pevlr + pevlr->DataOffset);
// This is the text of the current event // This is the text of the current event
lpEventStr = (LPSTR) ((LPBYTE) pevlr + pevlr->StringOffset); lpEventStr = (LPSTR)((LPBYTE) pevlr + pevlr->StringOffset);
// Compute the event type // Compute the event type
EventTimeToSystemTime(pevlr->TimeWritten, &time); EventTimeToSystemTime(pevlr->TimeWritten, &time);
// Get the username that generated the event // Get the username that generated the event
GetEventUserName (pevlr , szUsername); GetEventUserName(pevlr, szUsername);
GetDateFormat( LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, szLocalDate, MAX_PATH ); GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &time, NULL, szLocalDate, MAX_PATH);
GetTimeFormat( LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, szLocalTime, MAX_PATH ); GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &time, NULL, szLocalTime, MAX_PATH);
GetEventType (pevlr->EventType , szEventTypeText); GetEventType(pevlr->EventType, szEventTypeText);
GetEventCategory (lpLogName , lpSourceName , pevlr , szCategory); GetEventCategory(lpLogName, lpSourceName, pevlr, szCategory);
wsprintf (szEventID, "%u", (DWORD)(pevlr->EventID & 0xFFFF)); wsprintf(szEventID, "%u", (DWORD)(pevlr->EventID & 0xFFFF));
wsprintf (szCategoryID, "%u", (DWORD)(pevlr->EventCategory)); wsprintf(szCategoryID, "%u", (DWORD)(pevlr->EventCategory));
lviEventItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM; lviEventItem.mask = LVIF_IMAGE | LVIF_TEXT | LVIF_PARAM;
lviEventItem.iItem = 0; lviEventItem.iItem = 0;
@ -621,23 +620,28 @@ VOID QueryEventMessages (
lviEventItem.lParam = (LPARAM)pevlr; lviEventItem.lParam = (LPARAM)pevlr;
lviEventItem.pszText = szEventTypeText; lviEventItem.pszText = szEventTypeText;
switch(pevlr->EventType) switch (pevlr->EventType)
{ {
case EVENTLOG_ERROR_TYPE: case EVENTLOG_ERROR_TYPE:
lviEventItem.iImage = 2; lviEventItem.iImage = 2;
break; break;
case EVENTLOG_AUDIT_FAILURE: case EVENTLOG_AUDIT_FAILURE:
lviEventItem.iImage = 2; lviEventItem.iImage = 2;
break; break;
case EVENTLOG_WARNING_TYPE: case EVENTLOG_WARNING_TYPE:
lviEventItem.iImage = 1; lviEventItem.iImage = 1;
break; break;
case EVENTLOG_INFORMATION_TYPE: case EVENTLOG_INFORMATION_TYPE:
lviEventItem.iImage = 0; lviEventItem.iImage = 0;
break; break;
case EVENTLOG_AUDIT_SUCCESS: case EVENTLOG_AUDIT_SUCCESS:
lviEventItem.iImage = 0; lviEventItem.iImage = 0;
break; break;
case EVENTLOG_SUCCESS: case EVENTLOG_SUCCESS:
lviEventItem.iImage = 0; lviEventItem.iImage = 0;
break; break;
@ -655,42 +659,43 @@ VOID QueryEventMessages (
ListView_SetItemText(hwndListView, lviEventItem.iItem, 8, lpData); //Event Text ListView_SetItemText(hwndListView, lviEventItem.iItem, 8, lpData); //Event Text
dwRead -= pevlr->Length; dwRead -= pevlr->Length;
pevlr = (EVENTLOGRECORD *) ((LPBYTE) pevlr + pevlr->Length); pevlr = (EVENTLOGRECORD *)((LPBYTE) pevlr + pevlr->Length);
} }
dwRecordsToRead--; dwRecordsToRead--;
dwCurrentRecord++; dwCurrentRecord++;
pevlr = (EVENTLOGRECORD *) &bBuffer; pevlr = (EVENTLOGRECORD *)&bBuffer;
} }
//All events loaded // All events loaded
EndDialog(hwndDlg, 0); EndDialog(hwndDlg, 0);
wsprintf (szWindowTitle, "%s - %s Log on \\\\%s", szTitle , lpLogName , lpComputerName); wsprintf(szWindowTitle, "%s - %s Log on \\\\%s", szTitle , lpLogName , lpComputerName);
wsprintf (szStatusText, "%s has %d event(s)", lpLogName , dwTotalRecords); wsprintf(szStatusText, "%s has %d event(s)", lpLogName , dwTotalRecords);
//Update the status bar // Update the status bar
SendMessage (hwndStatus, SB_SETTEXT, (WPARAM)0, (LPARAM)szStatusText); SendMessage(hwndStatus, SB_SETTEXT, (WPARAM)0, (LPARAM)szStatusText);
//Set the window title // Set the window title
SetWindowText ( hwndMainWindow , szWindowTitle); SetWindowText(hwndMainWindow, szWindowTitle);
//Resume list view redraw // Resume list view redraw
SendMessage(hwndListView, WM_SETREDRAW, TRUE, 0); SendMessage(hwndListView, WM_SETREDRAW, TRUE, 0);
// Close the event log. // Close the event log.
CloseEventLog(hEventLog); CloseEventLog(hEventLog);
} }
VOID VOID
Refresh (VOID) Refresh(VOID)
{ {
QueryEventMessages( QueryEventMessages(lpComputerName,
lpComputerName ,
lpSourceLogName); lpSourceLogName);
} }
// //
// FUNCTION: MyRegisterClass() // FUNCTION: MyRegisterClass()
// //
@ -704,7 +709,8 @@ Refresh (VOID)
// so that the application will get 'well formed' small icons associated // so that the application will get 'well formed' small icons associated
// with it. // with it.
// //
ATOM MyRegisterClass(HINSTANCE hInstance) ATOM
MyRegisterClass(HINSTANCE hInstance)
{ {
WNDCLASSEX wcex; WNDCLASSEX wcex;
@ -717,7 +723,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
wcex.hInstance = hInstance; wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EVENTVWR)); wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_EVENTVWR));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = MAKEINTRESOURCE(IDC_EVENTVWR); wcex.lpszMenuName = MAKEINTRESOURCE(IDC_EVENTVWR);
wcex.lpszClassName = szWindowClass; wcex.lpszClassName = szWindowClass;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL)); wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
@ -725,6 +731,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
return RegisterClassEx(&wcex); return RegisterClassEx(&wcex);
} }
// //
// FUNCTION: InitInstance(HINSTANCE, int) // FUNCTION: InitInstance(HINSTANCE, int)
// //
@ -735,15 +742,16 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
// In this function, we save the instance handle in a global variable and // In this function, we save the instance handle in a global variable and
// create and display the main program window. // create and display the main program window.
// //
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) BOOL
InitInstance(HINSTANCE hInstance,
int nCmdShow)
{ {
HIMAGELIST hSmall; HIMAGELIST hSmall;
LVCOLUMN lvc = {0}; LVCOLUMN lvc = {0};
hInst = hInstance; // Store instance handle in our global variable hInst = hInstance; // Store instance handle in our global variable
hwndMainWindow = CreateWindow( hwndMainWindow = CreateWindow(szWindowClass,
szWindowClass,
szTitle, szTitle,
WS_OVERLAPPEDWINDOW, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
@ -751,14 +759,12 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
NULL, NULL,
hInstance, hInstance,
NULL); NULL);
if (!hwndMainWindow) if (!hwndMainWindow)
{ {
return FALSE; return FALSE;
} }
hwndStatus = CreateWindowEx( hwndStatus = CreateWindowEx(0, // no extended styles
0, // no extended styles
STATUSCLASSNAME, // status bar STATUSCLASSNAME, // status bar
"Done.", // no text "Done.", // no text
WS_CHILD | WS_BORDER | WS_VISIBLE, // styles WS_CHILD | WS_BORDER | WS_VISIBLE, // styles
@ -771,8 +777,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
// Create our listview child window. Note that I use WS_EX_CLIENTEDGE // Create our listview child window. Note that I use WS_EX_CLIENTEDGE
// and WS_BORDER to create the normal "sunken" look. Also note that // and WS_BORDER to create the normal "sunken" look. Also note that
// LVS_EX_ styles cannot be set in CreateWindowEx(). // LVS_EX_ styles cannot be set in CreateWindowEx().
hwndListView = CreateWindowEx( hwndListView = CreateWindowEx(WS_EX_CLIENTEDGE,
WS_EX_CLIENTEDGE,
WC_LISTVIEW, WC_LISTVIEW,
_T(""), _T(""),
LVS_SHOWSELALWAYS | WS_CHILD | WS_VISIBLE | LVS_REPORT, LVS_SHOWSELALWAYS | WS_CHILD | WS_VISIBLE | LVS_REPORT,
@ -789,8 +794,7 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
(void)ListView_SetExtendedListViewStyle (hwndListView, LVS_EX_FULLROWSELECT); (void)ListView_SetExtendedListViewStyle (hwndListView, LVS_EX_FULLROWSELECT);
// Create the ImageList // Create the ImageList
hSmall = ImageList_Create( hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON), GetSystemMetrics(SM_CYSMICON),
ILC_MASK, ILC_MASK,
1, 1,
@ -845,13 +849,13 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ShowWindow(hwndMainWindow, nCmdShow); ShowWindow(hwndMainWindow, nCmdShow);
UpdateWindow(hwndMainWindow); UpdateWindow(hwndMainWindow);
QueryEventMessages ( QueryEventMessages(lpComputerName, // Use the local computer.
lpComputerName, // Use the local computer.
EVENT_SOURCE_APPLICATION); // The event log category EVENT_SOURCE_APPLICATION); // The event log category
return TRUE; return TRUE;
} }
// //
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
// //
@ -862,32 +866,34 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
// WM_DESTROY - post a quit message and return // WM_DESTROY - post a quit message and return
// //
// //
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK
WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
int wmId, wmEvent; int wmId, wmEvent;
RECT rect; RECT rect;
NMHDR *hdr; NMHDR *hdr;
HMENU hMenu ; HMENU hMenu;
switch (message) switch (message)
{ {
case WM_NOTIFY : case WM_NOTIFY:
switch(((LPNMHDR)lParam)->code) switch (((LPNMHDR)lParam)->code)
{ {
case NM_DBLCLK : case NM_DBLCLK :
hdr = (NMHDR FAR*)lParam; hdr = (NMHDR FAR*)lParam;
if(hdr->hwndFrom == hwndListView) if (hdr->hwndFrom == hwndListView)
{ {
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam; LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE)lParam;
if(lpnmitem->iItem != -1) if (lpnmitem->iItem != -1)
{ {
DialogBox (hInst, MAKEINTRESOURCE(IDD_EVENTDETAILDIALOG), hWnd, EventDetails); DialogBox(hInst, MAKEINTRESOURCE(IDD_EVENTDETAILDIALOG), hWnd, EventDetails);
} }
} }
break; break;
} }
break; break;
case WM_COMMAND: case WM_COMMAND:
wmId = LOWORD(wParam); wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam); wmEvent = HIWORD(wParam);
@ -896,15 +902,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
(wmId == ID_LOG_SYSTEM) || (wmId == ID_LOG_SYSTEM) ||
(wmId == ID_LOG_SECURITY)) (wmId == ID_LOG_SECURITY))
{ {
hMenu = GetMenu (hWnd) ; // get the menu handle. Use it below hMenu = GetMenu(hWnd); // get the menu handle. Use it below
CheckMenuItem (hMenu, ID_LOG_APPLICATION , MF_UNCHECKED) ; CheckMenuItem(hMenu, ID_LOG_APPLICATION, MF_UNCHECKED);
CheckMenuItem (hMenu, ID_LOG_SYSTEM , MF_UNCHECKED) ; CheckMenuItem(hMenu, ID_LOG_SYSTEM, MF_UNCHECKED);
CheckMenuItem (hMenu, ID_LOG_SECURITY , MF_UNCHECKED) ; CheckMenuItem (hMenu, ID_LOG_SECURITY, MF_UNCHECKED);
if (hMenu) if (hMenu)
{ {
CheckMenuItem (hMenu, wmId , MF_CHECKED) ; CheckMenuItem(hMenu, wmId, MF_CHECKED);
} }
} }
@ -912,48 +918,51 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (wmId) switch (wmId)
{ {
case ID_LOG_APPLICATION: case ID_LOG_APPLICATION:
QueryEventMessages ( QueryEventMessages(lpComputerName, // Use the local computer.
lpComputerName, // Use the local computer.
EVENT_SOURCE_APPLICATION); // The event log category EVENT_SOURCE_APPLICATION); // The event log category
break; break;
case ID_LOG_SYSTEM: case ID_LOG_SYSTEM:
QueryEventMessages ( QueryEventMessages(lpComputerName, // Use the local computer.
lpComputerName, // Use the local computer.
EVENT_SOURCE_SYSTEM); // The event log category EVENT_SOURCE_SYSTEM); // The event log category
break; break;
case ID_LOG_SECURITY: case ID_LOG_SECURITY:
QueryEventMessages ( QueryEventMessages(lpComputerName, // Use the local computer.
lpComputerName, // Use the local computer.
EVENT_SOURCE_SECURITY); // The event log category EVENT_SOURCE_SECURITY); // The event log category
break; break;
case IDM_REFRESH: case IDM_REFRESH:
Refresh (); Refresh();
break; break;
case IDM_ABOUT: case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About); DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break; break;
case IDM_HELP: case IDM_HELP:
MessageBox ( MessageBox(NULL,
NULL , _TEXT("Help not implemented yet!"),
_TEXT("Help not implemented yet!") , _TEXT("Event Log"),
_TEXT("Event Log") ,
MB_OK | MB_ICONINFORMATION); MB_OK | MB_ICONINFORMATION);
break; break;
case IDM_EXIT: case IDM_EXIT:
DestroyWindow(hWnd); DestroyWindow(hWnd);
break; break;
default: default:
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
} }
break; break;
case WM_SIZE: case WM_SIZE:
{ {
//Gets the window rectangle // Gets the window rectangle
GetClientRect(hWnd, &rect); GetClientRect(hWnd, &rect);
//Relocate the listview // Relocate the listview
MoveWindow( MoveWindow(hwndListView,
hwndListView,
0, 0,
0, 0,
rect.right, rect.right,
@ -961,20 +970,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1); 1);
// Resize the statusbar; // Resize the statusbar;
SendMessage (hwndStatus, message, wParam, lParam); SendMessage(hwndStatus, message, wParam, lParam);
} }
break; break;
case WM_DESTROY: case WM_DESTROY:
PostQuitMessage(0); PostQuitMessage(0);
break; break;
default: default:
return DefWindowProc(hWnd, message, wParam, lParam); return DefWindowProc(hWnd, message, wParam, lParam);
} }
return 0; return 0;
} }
// Message handler for about box. // Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK
About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
UNREFERENCED_PARAMETER(lParam); UNREFERENCED_PARAMETER(lParam);
switch (message) switch (message)
@ -983,20 +997,21 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
case WM_COMMAND: case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{ {
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
break; break;
} }
return (INT_PTR)FALSE; return (INT_PTR)FALSE;
} }
VOID VOID
DisplayEvent (HWND hDlg) DisplayEvent(HWND hDlg)
{ {
char szEventType[MAX_PATH]; char szEventType[MAX_PATH];
char szTime[MAX_PATH]; char szTime[MAX_PATH];
@ -1011,9 +1026,10 @@ DisplayEvent (HWND hDlg)
BOOL bEventData = FALSE; BOOL bEventData = FALSE;
LVITEM li; LVITEM li;
EVENTLOGRECORD* pevlr; EVENTLOGRECORD* pevlr;
int iIndex;
// Get index of selected item // Get index of selected item
int iIndex = (int)SendMessage (hwndListView ,LVM_GETNEXTITEM, -1 , LVNI_SELECTED | LVNI_FOCUSED); iIndex = (int)SendMessage (hwndListView ,LVM_GETNEXTITEM, -1 , LVNI_SELECTED | LVNI_FOCUSED);
li.mask = LVIF_PARAM; li.mask = LVIF_PARAM;
li.iItem = iIndex; li.iItem = iIndex;
@ -1025,47 +1041,47 @@ DisplayEvent (HWND hDlg)
if (iIndex != -1) if (iIndex != -1)
{ {
ListView_GetItemText (hwndListView , iIndex , 0 , szEventType , sizeof( szEventType )); ListView_GetItemText(hwndListView, iIndex, 0, szEventType, sizeof(szEventType));
ListView_GetItemText (hwndListView , iIndex , 1 , szDate , sizeof( szDate )); ListView_GetItemText(hwndListView, iIndex, 1, szDate, sizeof(szDate));
ListView_GetItemText (hwndListView , iIndex , 2 , szTime , sizeof( szTime )); ListView_GetItemText(hwndListView, iIndex, 2, szTime, sizeof(szTime));
ListView_GetItemText (hwndListView , iIndex , 3 , szSource , sizeof( szSource )); ListView_GetItemText(hwndListView, iIndex, 3, szSource, sizeof(szSource));
ListView_GetItemText (hwndListView , iIndex , 4 , szCategory , sizeof( szCategory )); ListView_GetItemText(hwndListView, iIndex, 4, szCategory, sizeof(szCategory));
ListView_GetItemText (hwndListView , iIndex , 5 , szEventID , sizeof( szEventID )); ListView_GetItemText(hwndListView, iIndex, 5, szEventID, sizeof(szEventID));
ListView_GetItemText (hwndListView , iIndex , 6 , szUser , sizeof( szUser )); ListView_GetItemText(hwndListView, iIndex, 6, szUser, sizeof(szUser));
ListView_GetItemText (hwndListView , iIndex , 7 , szComputer , sizeof( szComputer )); ListView_GetItemText(hwndListView, iIndex, 7, szComputer, sizeof(szComputer));
ListView_GetItemText (hwndListView , iIndex , 8 , szEventData , sizeof( szEventData )); ListView_GetItemText(hwndListView, iIndex, 8, szEventData, sizeof(szEventData));
bEventData = !(strlen(szEventData) == 0); bEventData = !(strlen(szEventData) == 0);
GetEventMessage (lpSourceLogName , szSource , pevlr , szEventText); GetEventMessage(lpSourceLogName, szSource, pevlr, szEventText);
EnableWindow(GetDlgItem(hDlg , IDC_BYTESRADIO) , bEventData); EnableWindow(GetDlgItem(hDlg, IDC_BYTESRADIO), bEventData);
EnableWindow(GetDlgItem(hDlg , IDC_WORDRADIO) , bEventData); EnableWindow(GetDlgItem(hDlg, IDC_WORDRADIO), bEventData);
SetDlgItemText (hDlg, IDC_EVENTDATESTATIC , szDate); SetDlgItemText(hDlg, IDC_EVENTDATESTATIC, szDate);
SetDlgItemText (hDlg, IDC_EVENTTIMESTATIC , szTime); SetDlgItemText(hDlg, IDC_EVENTTIMESTATIC, szTime);
SetDlgItemText (hDlg, IDC_EVENTUSERSTATIC , szUser); SetDlgItemText(hDlg, IDC_EVENTUSERSTATIC, szUser);
SetDlgItemText (hDlg, IDC_EVENTSOURCESTATIC , szSource); SetDlgItemText(hDlg, IDC_EVENTSOURCESTATIC, szSource);
SetDlgItemText (hDlg, IDC_EVENTCOMPUTERSTATIC , szComputer); SetDlgItemText(hDlg, IDC_EVENTCOMPUTERSTATIC, szComputer);
SetDlgItemText (hDlg, IDC_EVENTCATEGORYSTATIC , szCategory); SetDlgItemText(hDlg, IDC_EVENTCATEGORYSTATIC, szCategory);
SetDlgItemText (hDlg, IDC_EVENTIDSTATIC , szEventID); SetDlgItemText(hDlg, IDC_EVENTIDSTATIC, szEventID);
SetDlgItemText (hDlg, IDC_EVENTTYPESTATIC , szEventType); SetDlgItemText(hDlg, IDC_EVENTTYPESTATIC, szEventType);
SetDlgItemText (hDlg, IDC_EVENTTEXTEDIT , szEventText); SetDlgItemText(hDlg, IDC_EVENTTEXTEDIT, szEventText);
SetDlgItemText (hDlg, IDC_EVENTDATAEDIT , szEventData); SetDlgItemText(hDlg, IDC_EVENTDATAEDIT, szEventData);
} }
else else
{ {
MessageBox( MessageBox(NULL,
NULL,
"No Items in ListView", "No Items in ListView",
"Error", "Error",
MB_OK | MB_ICONINFORMATION); MB_OK | MB_ICONINFORMATION);
} }
} }
static static
INT_PTR CALLBACK StatusMessageWindowProc( INT_PTR CALLBACK
IN HWND hwndDlg, StatusMessageWindowProc(IN HWND hwndDlg,
IN UINT uMsg, IN UINT uMsg,
IN WPARAM wParam, IN WPARAM wParam,
IN LPARAM lParam) IN LPARAM lParam)
@ -1082,18 +1098,19 @@ INT_PTR CALLBACK StatusMessageWindowProc(
return FALSE; return FALSE;
} }
// Message handler for event details box. // Message handler for event details box.
INT_PTR CALLBACK EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK
EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{ {
UNREFERENCED_PARAMETER(lParam); UNREFERENCED_PARAMETER(lParam);
switch (message) switch (message)
{ {
case WM_INITDIALOG: case WM_INITDIALOG:
{
// Show event info on dialog box // Show event info on dialog box
DisplayEvent (hDlg); DisplayEvent(hDlg);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
}
case WM_COMMAND: case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
@ -1101,21 +1118,22 @@ INT_PTR CALLBACK EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
EndDialog(hDlg, LOWORD(wParam)); EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
if (LOWORD(wParam) == IDPREVIOUS) if (LOWORD(wParam) == IDPREVIOUS)
{ {
SendMessage (hwndListView, WM_KEYDOWN, VK_UP, 0); SendMessage(hwndListView, WM_KEYDOWN, VK_UP, 0);
// Show event info on dialog box // Show event info on dialog box
DisplayEvent (hDlg); DisplayEvent(hDlg);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
if (LOWORD(wParam) == IDNEXT) if (LOWORD(wParam) == IDNEXT)
{ {
SendMessage (hwndListView, WM_KEYDOWN, VK_DOWN, 0); SendMessage(hwndListView, WM_KEYDOWN, VK_DOWN, 0);
// Show event info on dialog box // Show event info on dialog box
DisplayEvent (hDlg); DisplayEvent(hDlg);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
@ -1131,13 +1149,14 @@ INT_PTR CALLBACK EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
if (LOWORD(wParam) == IDHELP) if (LOWORD(wParam) == IDHELP)
{ {
MessageBox (NULL , MessageBox(NULL,
_TEXT("Help not implemented yet!") , _TEXT("Help not implemented yet!"),
_TEXT("Event Log") , _TEXT("Event Log"),
MB_OK | MB_ICONINFORMATION); MB_OK | MB_ICONINFORMATION);
return (INT_PTR)TRUE; return (INT_PTR)TRUE;
} }
break; break;
} }
return (INT_PTR)FALSE; return (INT_PTR)FALSE;
} }