#include #define EDIT1 11 WNDPROC g_oldproc; BOOL CALLBACK MainProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); LRESULT CALLBACK NewProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); const char g_szClassName[] = "subclassing example"; LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); HWND hEdit; HINSTANCE g_hInstance; int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX wc; HWND hwnd; MSG msg; g_hInstance=hInstance; wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; 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.lpszClassName = g_szClassName; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); if(!RegisterClassEx(&wc)) { MessageBox(NULL, "Couldn't Register Window", "Error!", MB_OK); return 0; } hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, g_szClassName, "Subclassing example", WS_OVERLAPPEDWINDOW, 190, 190,190,190, NULL, NULL, hInstance, NULL); if(hwnd == NULL) { MessageBox(NULL, "Couldn't create window", "Error!", MB_OK); return 0; } ShowWindow(hwnd, nCmdShow); UpdateWindow(hwnd); while(GetMessage(&msg, NULL, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch(msg) { case WM_CREATE: hEdit=CreateWindow("Edit", "", WS_CHILD | WS_VISIBLE| WS_BORDER | ES_AUTOHSCROLL , 30,30,60,30,hwnd, (HMENU)EDIT1,g_hInstance,NULL); g_oldproc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, (long)NewProc); break; case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); } return 0; } LRESULT CALLBACK NewProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_CHAR: if(wParam!=8 && !isdigit(wParam)) return 0; break; } return CallWindowProc (g_oldproc, hwnd, msg, wParam, lParam); }