#include <windows.h> #define ID_EDIT 1 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hwndEdit; static int len; static TCHAR text[30]; switch(msg) { case WM_CREATE: hwndEdit = CreateWindow(TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 65, 10, 150, 20, hwnd, (HMENU) ID_EDIT, NULL, NULL); CreateWindow( TEXT("button"), TEXT("Show file"), WS_VISIBLE | WS_CHILD, 65, 50, 150, 25, hwnd, (HMENU) 1, NULL, NULL); CreateWindow( TEXT("button"), TEXT("HELP"), WS_VISIBLE | WS_CHILD, 65, 85, 150, 25, hwnd, (HMENU) 2, NULL, NULL); CreateWindow( TEXT("button"), TEXT("QUIT"), WS_VISIBLE | WS_CHILD, 65, 120, 150, 25, hwnd, (HMENU) 3, NULL, NULL); break; case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { len = GetWindowTextLength(hwndEdit) + 1; GetWindowText(hwndEdit, text, len); SetWindowText(hwnd, text); if (LOWORD(wParam) == 3) { PostQuitMessage(0); } } break; case WM_DESTROY: PostQuitMessage(0); break; } return DefWindowProc(hwnd, msg, wParam, lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { MSG msg ; WNDCLASS wc = {0}; wc.lpszClassName = TEXT( "Edit Control" ); wc.hInstance = hInstance ; wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE); wc.lpfnWndProc = WndProc ; wc.hCursor = LoadCursor(0,IDC_ARROW); RegisterClass(&wc); CreateWindow( wc.lpszClassName, TEXT("Edit control"), WS_OVERLAPPEDWINDOW | WS_VISIBLE, 220, 220, 280, 180, 0, 0, hInstance, 0); while( GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return (int) msg.wParam; } |