Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!udel!haven.umd.edu!uflorida!novavax!raab From: raab@novavax.UUCP (Moshe Raab) Newsgroups: comp.windows.ms.programmer Subject: Windows Subclassing Keywords: Subclassing edit Message-ID: <2368@novavax.UUCP> Date: 28 Apr 91 04:56:45 GMT Organization: Nova University, Fort Lauderdale, FL Lines: 93 i would appreciate someone's help with the following windows problem (i wish there was better windows documentation). i am trying to create my own windows subclass. i created a dialog box using the sdk dialog editor. the diaolg actually contains 12 edit controls. i want some of those controls to accept only numeric characters. i need to trap te WM_CHAR messages and to accept only those with numeric character values. i created NumericProc to handle this: FARPROC lpfnNumericProc; FARPROC lpfnOldEdit; long FAR PASCAL NumericProc(HWND hwnd, WORD message, WORD wParam, LONG lParam) { extern FARPROC lpfnOldEdit; switch(message) { case WM_CHAR: if (!isdigit(wParam)) MessageBeep(0); break; } return CallWindowProc(lpfnOldEdit,hwnd,message,wParam,lParam); } i get the instance of the proc in WinMain as follows: lpfnNumericProc = MakeProcInstance((FARPROC)NumericProc, hInstance); i call "DialogBox". The following is the dialog box code. BOOL FAR PASCAL DlgProc(HWND hDlg, WORD message, WORD wParam, LONG lParam) { static int iCurrentFieldType; extern FARPROC lpfnNumericProc; switch(message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: switch(wParam) { case IDOK: EndDialog(hDlg,TRUE); return TRUE; case IDCANCEL: EndDialog(hDlg,FALSE); return TRUE; default: if (HIWORD(lParam) == EN_SETFOCUS) { // get field type iCurrentFieldType = FieldType(GoldCosts, NUM_GOLD_COSTS, iCurrentControl); switch(iCurrentFieldType) { case NUMERIC: // use numeric control lpfnOldEdit = (FARPROC)GetWindowLong(hDlg,GWL_WNDPROC); SetWindowLong(hDlg, GWL_WNDPROC,(LONG) lpfnNumericProc); break; default: break; } } if (HIWORD(lParam) == EN_KILLFOCUS) { // reset to original edit control SetWindowLong(hDlg, GWL_WNDPROC,(LONG) lpfnOldEdit); } return FALSE; } } return FALSE; } The above code doesn't work. i think it is because i am not passing the proper handle of the edit control. ( i am passing the address of the current dialog box). if i understand things correctly, i need to pass the address of the edit control. is that right? if so, how do i obtain the handle of the original (or current) edit control handle? if not, what am i doing wrong? thanks for your help moshe raab raab@novavax