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

@ -70,7 +70,9 @@ INT_PTR CALLBACK About (HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK EventDetails(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,
LPTSTR lpCmdLine,
int nCmdShow)
@ -114,11 +116,15 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
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 };
FILETIME ftLocal;
union {
union
{
FILETIME ft;
ULONGLONG ll;
} u1970, uUCT;
@ -131,6 +137,7 @@ VOID EventTimeToSystemTime (DWORD EventTime, SYSTEMTIME *pSystemTime)
FileTimeToSystemTime(&ftLocal, pSystemTime);
}
void
TrimNulls(LPSTR s)
{
@ -145,8 +152,9 @@ TrimNulls ( LPSTR s )
}
}
BOOL GetEventMessageFileDLL(
IN LPCTSTR lpLogName,
BOOL
GetEventMessageFileDLL(IN LPCTSTR lpLogName,
IN LPCTSTR SourceName,
IN LPCTSTR EntryName,
OUT LPSTR ExpandedName)
@ -162,23 +170,20 @@ BOOL GetEventMessageFileDLL(
_tcscat(szKeyName, _T("\\"));
_tcscat(szKeyName, lpLogName);
if (RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,
szKeyName,
0,
KEY_READ,
&hAppKey) == ERROR_SUCCESS)
{
if (RegOpenKeyEx(
hAppKey,
if (RegOpenKeyEx(hAppKey,
SourceName,
0,
KEY_READ,
&hSourceKey) == ERROR_SUCCESS)
{
dwSize = MAX_PATH;
if (RegQueryValueEx(
hSourceKey,
if (RegQueryValueEx(hSourceKey,
EntryName,
NULL,
NULL,
@ -210,8 +215,9 @@ BOOL GetEventMessageFileDLL(
return bReturn;
}
BOOL GetEventCategory(
IN LPCTSTR KeyName,
BOOL
GetEventCategory(IN LPCTSTR KeyName,
IN LPCTSTR SourceName,
IN EVENTLOGRECORD *pevlr,
OUT LPTSTR CategoryName)
@ -222,16 +228,13 @@ BOOL GetEventCategory(
if (GetEventMessageFileDLL (KeyName, SourceName, EVENT_CATEGORY_MESSAGE_FILE , szMessageDLL))
{
hLibrary = LoadLibraryEx(
szMessageDLL,
hLibrary = LoadLibraryEx(szMessageDLL,
NULL,
DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if (hLibrary != NULL)
{
// Retrieve the message string.
if(FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_ARGUMENT_ARRAY,
hLibrary,
pevlr->EventCategory,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
@ -251,7 +254,9 @@ BOOL GetEventCategory(
{
strcpy(CategoryName, (LPCTSTR)lpMsgBuf);
}
}else{
}
else
{
strcpy(CategoryName, "None");
}
@ -271,8 +276,9 @@ BOOL GetEventCategory(
return FALSE;
}
BOOL GetEventMessage(
IN LPCTSTR KeyName,
BOOL
GetEventMessage(IN LPCTSTR KeyName,
IN LPCTSTR SourceName,
IN EVENTLOGRECORD *pevlr,
OUT LPTSTR EventText)
@ -323,11 +329,9 @@ BOOL GetEventMessage(
szDll = strtok(SourceModuleName, EVENT_DLL_SEPARATOR);
while ((szDll != NULL) && (!bDone))
{
hLibrary = LoadLibraryEx(
szDll,
hLibrary = LoadLibraryEx(szDll,
NULL,
DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if (hLibrary == NULL)
{
// The DLL could not be loaded try the next one (if any)
@ -336,8 +340,7 @@ BOOL GetEventMessage(
else
{
// Retrieve the message string.
if(FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM |
if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_HMODULE |
FORMAT_MESSAGE_ARGUMENT_ARRAY,
@ -388,8 +391,10 @@ BOOL GetEventMessage(
return FALSE;
}
VOID
GetEventType (WORD dwEventType, OUT LPSTR eventTypeText)
GetEventType(IN WORD dwEventType,
OUT LPSTR eventTypeText)
{
switch (dwEventType)
{
@ -433,8 +438,7 @@ GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
// User SID
if (pelr->UserSidLength > 0)
{
if (LookupAccountSid(
NULL,
if (LookupAccountSid(NULL,
lpSid,
szName,
&cbName,
@ -450,22 +454,22 @@ GetEventUserName (EVENTLOGRECORD *pelr, OUT LPSTR pszUser)
return FALSE;
}
static DWORD WINAPI
ShowStatusMessageThread(
IN LPVOID lpParameter)
ShowStatusMessageThread(IN LPVOID lpParameter)
{
HWND *phWnd = (HWND *)lpParameter;
HWND hWnd;
MSG Msg;
hWnd = CreateDialogParam(
hInst,
hWnd = CreateDialogParam(hInst,
MAKEINTRESOURCE(IDD_PROGRESSBOX),
GetDesktopWindow(),
StatusMessageWindowProc,
(LPARAM)NULL);
if (!hWnd)
return 0;
*phWnd = hWnd;
ShowWindow(hWnd, SW_SHOW);
@ -480,8 +484,9 @@ ShowStatusMessageThread(
return 0;
}
VOID QueryEventMessages (
LPTSTR lpMachineName ,
VOID
QueryEventMessages(LPTSTR lpMachineName,
LPTSTR lpLogName)
{
HWND hwndDlg;
@ -515,10 +520,8 @@ VOID QueryEventMessages (
lpComputerName = lpMachineName;
// Open the event log.
hEventLog = OpenEventLog(
lpMachineName,
hEventLog = OpenEventLog(lpMachineName,
lpLogName);
if (hEventLog == NULL)
{
MessageBox(NULL,
@ -546,8 +549,7 @@ VOID QueryEventMessages (
//If we have at least 1000 records show the waiting dialog
if (dwTotalRecords > 1000)
{
CreateThread(
NULL,
CreateThread(NULL,
0,
ShowStatusMessageThread,
(LPVOID)&hwndDlg,
@ -559,21 +561,18 @@ VOID QueryEventMessages (
{
pevlr = (EVENTLOGRECORD*)malloc(MAX_PATH);
bResult = ReadEventLog(
hEventLog, // Event log handle
bResult = ReadEventLog(hEventLog, // Event log handle
dwFlags, // Sequential read
0, // Ignored for sequential read
pevlr, // Pointer to buffer
MAX_PATH, // Size of buffer
&dwRead, // Number of bytes read
&dwNeeded); // Bytes in the next record
if((!bResult) && (GetLastError () == ERROR_INSUFFICIENT_BUFFER))
{
pevlr = (EVENTLOGRECORD*)malloc (dwNeeded);
ReadEventLog(
hEventLog, // event log handle
ReadEventLog(hEventLog, // event log handle
dwFlags, // read flags
0, // offset; default is 0
pevlr, // pointer to buffer
@ -626,18 +625,23 @@ VOID QueryEventMessages (
case EVENTLOG_ERROR_TYPE:
lviEventItem.iImage = 2;
break;
case EVENTLOG_AUDIT_FAILURE:
lviEventItem.iImage = 2;
break;
case EVENTLOG_WARNING_TYPE:
lviEventItem.iImage = 1;
break;
case EVENTLOG_INFORMATION_TYPE:
lviEventItem.iImage = 0;
break;
case EVENTLOG_AUDIT_SUCCESS:
lviEventItem.iImage = 0;
break;
case EVENTLOG_SUCCESS:
lviEventItem.iImage = 0;
break;
@ -683,14 +687,15 @@ VOID QueryEventMessages (
CloseEventLog(hEventLog);
}
VOID
Refresh(VOID)
{
QueryEventMessages(
lpComputerName ,
QueryEventMessages(lpComputerName,
lpSourceLogName);
}
//
// FUNCTION: MyRegisterClass()
//
@ -704,7 +709,8 @@ Refresh (VOID)
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
ATOM
MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
@ -725,6 +731,7 @@ ATOM MyRegisterClass(HINSTANCE hInstance)
return RegisterClassEx(&wcex);
}
//
// 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
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
BOOL
InitInstance(HINSTANCE hInstance,
int nCmdShow)
{
HIMAGELIST hSmall;
LVCOLUMN lvc = {0};
hInst = hInstance; // Store instance handle in our global variable
hwndMainWindow = CreateWindow(
szWindowClass,
hwndMainWindow = CreateWindow(szWindowClass,
szTitle,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
@ -751,14 +759,12 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
NULL,
hInstance,
NULL);
if (!hwndMainWindow)
{
return FALSE;
}
hwndStatus = CreateWindowEx(
0, // no extended styles
hwndStatus = CreateWindowEx(0, // no extended styles
STATUSCLASSNAME, // status bar
"Done.", // no text
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
// and WS_BORDER to create the normal "sunken" look. Also note that
// LVS_EX_ styles cannot be set in CreateWindowEx().
hwndListView = CreateWindowEx(
WS_EX_CLIENTEDGE,
hwndListView = CreateWindowEx(WS_EX_CLIENTEDGE,
WC_LISTVIEW,
_T(""),
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);
// Create the ImageList
hSmall = ImageList_Create(
GetSystemMetrics(SM_CXSMICON),
hSmall = ImageList_Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
ILC_MASK,
1,
@ -845,13 +849,13 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
ShowWindow(hwndMainWindow, nCmdShow);
UpdateWindow(hwndMainWindow);
QueryEventMessages (
lpComputerName, // Use the local computer.
QueryEventMessages(lpComputerName, // Use the local computer.
EVENT_SOURCE_APPLICATION); // The event log category
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
@ -862,7 +866,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
// 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;
RECT rect;
@ -888,6 +893,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
@ -912,48 +918,51 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
switch (wmId)
{
case ID_LOG_APPLICATION:
QueryEventMessages (
lpComputerName, // Use the local computer.
QueryEventMessages(lpComputerName, // Use the local computer.
EVENT_SOURCE_APPLICATION); // The event log category
break;
case ID_LOG_SYSTEM:
QueryEventMessages (
lpComputerName, // Use the local computer.
QueryEventMessages(lpComputerName, // Use the local computer.
EVENT_SOURCE_SYSTEM); // The event log category
break;
case ID_LOG_SECURITY:
QueryEventMessages (
lpComputerName, // Use the local computer.
QueryEventMessages(lpComputerName, // Use the local computer.
EVENT_SOURCE_SECURITY); // The event log category
break;
case IDM_REFRESH:
Refresh();
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_HELP:
MessageBox (
NULL ,
MessageBox(NULL,
_TEXT("Help not implemented yet!"),
_TEXT("Event Log"),
MB_OK | MB_ICONINFORMATION);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_SIZE:
{
// Gets the window rectangle
GetClientRect(hWnd, &rect);
// Relocate the listview
MoveWindow(
hwndListView,
MoveWindow(hwndListView,
0,
0,
rect.right,
@ -964,17 +973,22 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
SendMessage(hwndStatus, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// 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);
switch (message)
@ -983,15 +997,16 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
return (INT_PTR)TRUE;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
@ -1011,9 +1026,10 @@ DisplayEvent (HWND hDlg)
BOOL bEventData = FALSE;
LVITEM li;
EVENTLOGRECORD* pevlr;
int iIndex;
// 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.iItem = iIndex;
@ -1055,17 +1071,17 @@ DisplayEvent (HWND hDlg)
}
else
{
MessageBox(
NULL,
MessageBox(NULL,
"No Items in ListView",
"Error",
MB_OK | MB_ICONINFORMATION);
}
}
static
INT_PTR CALLBACK StatusMessageWindowProc(
IN HWND hwndDlg,
INT_PTR CALLBACK
StatusMessageWindowProc(IN HWND hwndDlg,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam)
@ -1082,18 +1098,19 @@ INT_PTR CALLBACK StatusMessageWindowProc(
return FALSE;
}
// 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);
switch (message)
{
case WM_INITDIALOG:
{
// Show event info on dialog box
DisplayEvent(hDlg);
return (INT_PTR)TRUE;
}
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
@ -1101,6 +1118,7 @@ INT_PTR CALLBACK EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
if (LOWORD(wParam) == IDPREVIOUS)
{
SendMessage(hwndListView, WM_KEYDOWN, VK_UP, 0);
@ -1139,5 +1157,6 @@ INT_PTR CALLBACK EventDetails(HWND hDlg, UINT message, WPARAM wParam, LPARAM lPa
}
break;
}
return (INT_PTR)FALSE;
}