[comp.windows.ms] A basic edit control question

jfbruno@rodan.acs.syr.edu (John Bruno) (09/12/90)

I'm just starting to play around with the MultiPad sample code that came with
the SDK and have some basic questions on edit controls:

 1) Where is the processing done that puts an 'e' in the window when I hit
    the 'e' key??
 2) Is it possible to intercept events before being passed to this procedure?
    (i.e., could I have the 'e' key make a 'w' in the window when pressed? If
    so, how?) Real code would be nice, but I just need a general push in the
    right direction.

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 
this topic is covered in the SDK manuals, I don't see anything other than 
descriptions on what an edit control is and how to create one.  Are there any
good Windows 3.0 programming books that go beyond the scope of the SDK manuals
and include stuff like the above?

Many thanks in advance,
---jb

brianf@umd5.umd.edu (Brian Farmer) (09/12/90)

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