Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!udel!haven!umd5!brianf From: brianf@umd5.umd.edu (Brian Farmer) Newsgroups: comp.windows.ms Subject: Re: A basic edit control question Message-ID: <7275@umd5.umd.edu> Date: 11 Sep 90 21:58:16 GMT References: <1990Sep11.182127.29856@rodan.acs.syr.edu> Reply-To: brianf@umd5.umd.edu (Brian Farmer) Organization: University of Maryland, College Park Lines: 54 In article <1990Sep11.182127.29856@rodan.acs.syr.edu> jfbruno@rodan.acs.syr.edu (John Bruno) writes: >It seems that once SetFocus() is called, the application doesn't see any of the >WM_CHAR messages, so there is no opportunity to intercept them. Could message >interception work if SetFocus() is not called? I want to get messages before >they're processed by the edit control proc and do things, including modifying >the messages, then pass control on to the edit control proc. Forgive me if Someone at Microsoft thought of this first and called it subclassing. It is covered in the manuels but I'm not sure where. The 2.1 sdk told you how to do it but not why to do it. After you create your window you must get the address of the window proc that handles the messages for that window and replace it with the address of a window proc that you have written. hEdit = CreateWindow ("EDIT", ...); lpOldProc = (FARPROC)GetWindowLong (hEdit, GWL_WNDPROC); lpNewProc = MakeProcInstance (MySubclassWndProc); SetWindowLong (hEdit, GWL_WNDPROC, lpNewProc); You must keep lpOldProc around because you need to call this function later. MySubclassWndProc needs to be exported in your .def file. You could write MySubclassWndProc like this: long FAR PASCAL MySubclassWndProc (HWND hWnd, WORD msg, WORD wParam, LONG lParam) { if (msg == WM_CHAR) { if ((char)wParam == 'e') wParam = (int)'w'; if ((char)wParam == (int)'w') wParam = 'e'; } /* lpOldProc must be lobal for this to work. */ return CallWindowProc (lpOldProc, hWnd, msg, wParam, lParam); } Just about any window message if fare game for you to play with. All messages for the window will pass through MySubclassWndProc before they go onto the actual window function. You can trap messages, changes messages, add messages. Hope this helps, Brian Farmer brianf@umd5.umd.edu