#include /********************* Prototypes ***********************/ LRESULT WINAPI MainWndProc( HWND, UINT, WPARAM, LPARAM ); /******************* Global Variables ********************/ HANDLE ghInstance; int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow ) { WNDCLASS wc; MSG msg; HWND hWnd; wc.lpszClassName = "ControlAppClass"; wc.lpfnWndProc = MainWndProc; wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; wc.hInstance = hInstance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)( COLOR_WINDOW+1 ); wc.lpszMenuName = NULL; wc.cbClsExtra = 0; wc.cbWndExtra = 0; RegisterClass( &wc ); ghInstance = hInstance; hWnd = CreateWindow( "ControlAppClass", "Control Application", WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, 0, 0, 300, 300, NULL, NULL, hInstance, NULL ); ShowWindow( hWnd, nCmdShow ); UpdateWindow (hWnd) ; 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 message, WPARAM wParam, LPARAM lParam) { static HWND hwndButton[3], hwndEdit ; char buffer[255]; char bhwnd[10], bhwnd2[10]; CHAR lpszTrouble[] = "When in the Course of human Events " "it becomes necessary for one People " "to dissolve the Political Bands which " "have connected them with another, and " "to assume among the Powers of the " "Earth, the separate and equal Station " "to which the Laws of Nature and of " "Nature's God entitle them, a decent " "Respect to the Opinions of Mankind " "requires that they should declare the " "causes which impel them to the " "Separation. "; switch (message) { case WM_CREATE : hwndButton[0] = CreateWindow ( TEXT("button"), "This is a button", WS_CHILD | WS_VISIBLE | BS_DEFPUSHBUTTON, 70, 10, 160, 30, hwnd, (HMENU) 0, ghInstance, NULL); hwndButton[1] = CreateWindow ( TEXT("button"), "This is a check box", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, 70, 50, 160, 30, hwnd, (HMENU) 1, ghInstance, NULL); hwndButton[2] = CreateWindow ( TEXT("button"), "This is a radio button", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON, 70, 90, 160, 30, hwnd, (HMENU) 2, ghInstance, NULL); hwndEdit = CreateWindow(TEXT("EDIT"), NULL, WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_LEFT | ES_MULTILINE | ES_AUTOVSCROLL, 50, 130, 200, 100, hwnd, (HMENU) 3, ghInstance, NULL); SendMessage(hwndEdit, WM_SETTEXT, 0, (LPARAM) lpszTrouble); return 0 ; case WM_COMMAND : switch (wParam) { // case 0: // case 1: case 2: itoa((int) LOWORD(wParam), buffer, 10); itoa((int) hwndButton[(int) LOWORD(wParam)], bhwnd, 10); itoa((int) lParam, bhwnd2, 10); strcat(buffer, " control was pressed with lParam "); strcat(buffer, bhwnd2); strcat(buffer, " : hwnd "); strcat(buffer, bhwnd); MessageBox(NULL, buffer, "Control pressed", 0); } break; case WM_DESTROY : PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }