#include #define M_HINSTANCE (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE) LRESULT CALLBACK EditProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static WNDPROC oldProc = NULL; if (! oldProc) oldProc = (WNDPROC)GetWindowLong(hWnd, GWL_USERDATA); switch(msg) { case WM_KEYDOWN: if (wParam == VK_RETURN) { MessageBox(NULL, "Enter has been pressed", "Yeaho", MB_OK); return 0; } break; } return CallWindowProc(oldProc, hWnd, msg, wParam, lParam); } LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hWndEdit; static HINSTANCE hInstance; WNDPROC oldProc; switch(msg) { case WM_CREATE : hWndEdit = CreateWindowEx(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE, TEXT("Edit"), NULL, WS_CHILD | WS_VISIBLE | ES_AUTOHSCROLL, 2, 422, 605, 25, hWnd, NULL, M_HINSTANCE, NULL); oldProc = (WNDPROC)GetWindowLong(hWndEdit, GWL_WNDPROC); SetWindowLong(hWndEdit, GWL_WNDPROC, (LONG)EditProc); SetWindowLong(hWndEdit, GWL_USERDATA, (LONG)oldProc); return 0; case WM_SETFOCUS: SetFocus(hWndEdit); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hWnd, msg, wParam, lParam); } int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { HWND hWnd; MSG msg; WNDCLASS wndclass; wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; wndclass.lpfnWndProc = WndProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(hInstance, IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wndclass.lpszMenuName = (HMENU)NULL; wndclass.lpszClassName = "WindowClass"; if (! RegisterClass(&wndclass)) { MessageBox(NULL, TEXT("Program requires Windows NT!"), "Error",MB_ICONERROR); return 0; } hWnd = CreateWindow("WindowClass", TEXT("-- PeChat --"), WS_DLGFRAME | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, 800, 498, NULL, NULL, hInstance, NULL); ShowWindow(hWnd, iCmdShow); UpdateWindow(hWnd); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } .