mirror of https://github.com/lianthony/NT4.0
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.
240 lines
6.1 KiB
240 lines
6.1 KiB
/****************************************************************************
|
|
|
|
PROGRAM: Generic.c
|
|
|
|
PURPOSE: Generic template for Windows applications
|
|
|
|
****************************************************************************/
|
|
|
|
#include "generic.h"
|
|
|
|
|
|
HINSTANCE hInst;
|
|
HWND hwndMain;
|
|
BOOL bAutoTest;
|
|
|
|
TCHAR szAppName[] = TEXT("Generic");
|
|
TCHAR szTitle[] = TEXT("Generic Sample Application");
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
FUNCTION: WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
|
|
|
|
PURPOSE: calls initialization function, processes message loop
|
|
|
|
****************************************************************************/
|
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
LPSTR lpCmdLine, INT nCmdShow)
|
|
{
|
|
MSG msg;
|
|
HANDLE hAccelTable;
|
|
|
|
if (lpCmdLine && *lpCmdLine) {
|
|
bAutoTest = TRUE;
|
|
} else {
|
|
bAutoTest = FALSE;
|
|
}
|
|
|
|
if (!hPrevInstance)
|
|
{
|
|
if (!InitApplication(hInstance))
|
|
{
|
|
return (FALSE);
|
|
}
|
|
}
|
|
|
|
|
|
// Perform initializations that apply to a specific instance
|
|
if (!InitInstance(hInstance, nCmdShow))
|
|
{
|
|
return (FALSE);
|
|
}
|
|
|
|
hAccelTable = LoadAccelerators (hInstance, szAppName);
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
{
|
|
if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
|
|
|
|
return (msg.wParam);
|
|
|
|
lpCmdLine;
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
FUNCTION: InitApplication(HINSTANCE)
|
|
|
|
PURPOSE: Initializes window data and registers window class
|
|
|
|
****************************************************************************/
|
|
|
|
BOOL InitApplication(HINSTANCE hInstance)
|
|
{
|
|
WNDCLASS wc;
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
wc.lpfnWndProc = (WNDPROC)WndProc;
|
|
wc.cbClsExtra = 0;
|
|
wc.cbWndExtra = 0;
|
|
wc.hInstance = hInstance;
|
|
wc.hIcon = LoadIcon (hInstance, szAppName);
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
|
wc.lpszMenuName = szAppName;
|
|
wc.lpszClassName = szAppName;
|
|
|
|
return (RegisterClass(&wc));
|
|
}
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
FUNCTION: InitInstance(HINSTANCE, int)
|
|
|
|
PURPOSE: Saves instance handle and creates main window
|
|
|
|
****************************************************************************/
|
|
|
|
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
|
{
|
|
HWND hWnd;
|
|
|
|
hInst = hInstance;
|
|
|
|
hWnd = CreateWindow(szAppName,
|
|
szTitle,
|
|
WS_OVERLAPPEDWINDOW,
|
|
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
|
|
NULL,
|
|
NULL,
|
|
hInstance,
|
|
NULL);
|
|
|
|
if (!hWnd)
|
|
{
|
|
return (FALSE);
|
|
}
|
|
else
|
|
{
|
|
hwndMain = hWnd;
|
|
}
|
|
|
|
|
|
ShowWindow(hWnd, SW_SHOWDEFAULT);
|
|
UpdateWindow(hWnd);
|
|
|
|
if (bAutoTest) {
|
|
PostMessage (hWnd, WM_COMMAND, IDM_STATUS, 0);
|
|
}
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
/****************************************************************************
|
|
|
|
FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
|
|
|
|
PURPOSE: Processes messages
|
|
|
|
****************************************************************************/
|
|
|
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
DWORD dwThreadID;
|
|
HANDLE hThread;
|
|
|
|
switch (message)
|
|
{
|
|
case WM_COMMAND:
|
|
{
|
|
switch (LOWORD(wParam))
|
|
{
|
|
case IDM_STATUS:
|
|
|
|
//
|
|
// Create a thread to run the status bar tests.
|
|
//
|
|
|
|
hThread = CreateThread (NULL,
|
|
0,
|
|
(LPTHREAD_START_ROUTINE) StatusTest,
|
|
NULL,
|
|
0,
|
|
&dwThreadID);
|
|
//
|
|
// Check return value.
|
|
//
|
|
|
|
if (hThread) {
|
|
CloseHandle (hThread);
|
|
} else {
|
|
Print (TEXT("Failed to CreateThread for StatusTest"));
|
|
}
|
|
|
|
break;
|
|
|
|
case IDM_ABOUT:
|
|
DialogBox (hInst, TEXT("AboutBox"), hWnd, About);
|
|
break;
|
|
|
|
case IDM_EXIT:
|
|
DestroyWindow (hwndMain);
|
|
break;
|
|
|
|
|
|
default:
|
|
return (DefWindowProc(hWnd, message, wParam, lParam));
|
|
}
|
|
}
|
|
break;
|
|
|
|
case WM_DESTROY:
|
|
PostQuitMessage(0);
|
|
break;
|
|
|
|
default:
|
|
return (DefWindowProc(hWnd, message, wParam, lParam));
|
|
}
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
/****************************************************************************
|
|
|
|
FUNCTION: About(HWND, UINT, WPARAM, LPARAM)
|
|
|
|
PURPOSE: Processes messages for "About" dialog box
|
|
|
|
****************************************************************************/
|
|
|
|
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
|
{
|
|
|
|
switch (message)
|
|
{
|
|
case WM_INITDIALOG:
|
|
return TRUE;
|
|
|
|
case WM_COMMAND:
|
|
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
|
{
|
|
EndDialog(hDlg, TRUE);
|
|
return (TRUE);
|
|
}
|
|
break;
|
|
}
|
|
|
|
return (FALSE);
|
|
|
|
lParam;
|
|
}
|