#include #include "resource.h" /********************* Prototypes ***********************/ LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM ); /******************* Global Variables ********************/ HANDLE ghInstance; /********************************************************************\ * Function: int PASCAL WinMain(HINSTANCE, HINSTANCE, LPSTR, int) * * * * Purpose: Initializes Application * * * * Comments: Register window class, create and display the main * * window, and enter message loop. * * * * * \********************************************************************/ int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { WNDCLASS wc; MSG msg; HWND hWnd; if( !hPrevInstance ) { wc.lpszClassName = "ControlDialogClass"; wc.lpfnWndProc = MainWndProc; wc.style = CS_VREDRAW | CS_HREDRAW; wc.hInstance = hInstance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)( COLOR_BTNFACE+1 ); wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = DLGWINDOWEXTRA; RegisterClass( &wc ); } ghInstance = hInstance; hWnd = CreateDialog(hInstance, "LoginDialog", NULL, NULL); ShowWindow( hWnd, nCmdShow ); while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } return msg.wParam; } /********************************************************************\ * Function: LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM) * * * * Purpose: Processes Application Messages * * * * Comments: The following messages are processed * * * * WM_PAINT * * WM_COMMAND * * WM_DESTROY * * * * * \********************************************************************/ LRESULT CALLBACK MainWndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { char name[255], passwd[255]; HWND hControl; switch( msg ) { /**************************************************************\ * WM_COMMAND: * \**************************************************************/ case WM_COMMAND: switch(wParam) { case IDC_LOGIN: hControl = GetDlgItem(hWnd, IDC_NAME); SendMessage(hControl, WM_GETTEXT, 255, (LPARAM)name); hControl = GetDlgItem(hWnd, IDC_PASSWD); SendMessage(hControl, WM_GETTEXT, 255, (LPARAM)passwd); if ((strcmp(name, "JonPreston") == 0) && (strcmp(passwd, "42") == 0)) MessageBox(NULL, "You're IN", "Welcome", MB_OK); else MessageBox(NULL, "Intruder", "Go Away!", MB_OK); break; case IDC_QUIT: if (MessageBox(NULL, "Are you sure you want to quit?", "Confirmation", MB_ICONQUESTION | MB_YESNO) == IDYES) SendMessage(hWnd, WM_DESTROY, 0, 0); break; } return 0; break; /**************************************************************\ * WM_DESTROY: PostQuitMessage() is called * \**************************************************************/ case WM_DESTROY: PostQuitMessage( 0 ); break; /**************************************************************\ * Let the default window proc handle all other messages * \**************************************************************/ default: return( DefWindowProc( hWnd, msg, wParam, lParam )); } return 0; }