[comp.windows.ms.programmer] Sensing focus in a dialog box

goble@cs.washington.edu (Brian Goble) (06/26/91)

I have a dialog box with a bunch of edit windows (single-line).  
When the user enters info into the first edit box and then tabs to
the next edit box I want to know that something is in that first
edit box and use it to load in some other info.

Right now, I have the user press return and I can determine if they
have only entered info into the first box.  But I want it to be so
they just hit tab or click somewhere else.

How do I have the edit window alert my Dialog Box window function
when it has gained or lost the input focus?  I know there exist messages
that have this info in one of the Params but I can't figure out how to
access the edit control message from the dialog box function.  

Thanx for any help!!!


Brian Goble	|	goble@wolf.cs.washington.edu

press@venice.SEDD.TRW.COM (Barry Press) (06/26/91)

In article <1991Jun25.210210.3046@beaver.cs.washington.edu> goble@cs.washington.edu (Brian Goble) writes:
>I have a dialog box with a bunch of edit windows (single-line).  
>When the user enters info into the first edit box and then tabs to
>the next edit box I want to know that something is in that first
>edit box and use it to load in some other info.

You should look at the messages related to change of selection in the 
dialog box.  If I recall right, it's EN_SELCHANGE, or something like that.
When you get it, then you can do whatever.  The actual message you get is
the control's ID (forgive me if this is not quite right; I'm doing it from
memory) with  the notification message in a parameter.  Or maybe it's
WM_COMMAND with the ID in wParam and the notification in lParam.  In any
event, it's the standard notification message, and the selection change
notification is the ticket.

-- 
Barry Press                                 Internet: press@venice.sedd.trw.com

mjl@lccma.bos.locus.com (Mike Leibensperger) (06/29/91)

In article <1991Jun25.210210.3046@beaver.cs.washington.edu> goble@cs.washington.edu (Brian Goble) writes:
>I have a dialog box with a bunch of edit windows (single-line).  
>When the user enters info into the first edit box and then tabs to
>the next edit box I want to know that something is in that first
>edit box and use it to load in some other info.

When your edit control loses focus, it gets a WM_KILLFOCUS message.
(Likewise, a window receiving the focus gets WM_SETFOCUS.)  You can
capture WM_KILLFOCUS, check the data typed into the edit control, and
do whatever's appropriate---send messages to other windows, keep the
focus using SetFocus() if the data is invalid, etc.  You'll need to
subclass the edit control to do this.

At least, I *think* that's how it's supposed to work....

Press on....

>
>Brian Goble	|	goble@wolf.cs.washington.edu


--
Michael J. Leibensperger <mjl@locus.com>       "None are so deeply enslaved
Locus Computing Corp./Boston			as those who falsely believe
25 Burlington Mall Road				they are free."
Burlington MA 01803, (617)229-4980 x169			-- J. W. von Goethe

bonneau@hyper.hyper.com (Paul Bonneau) (06/29/91)

In article <1132@venice.SEDD.TRW.COM> press@venice.sedd.trw.com (Barry Press) writes:
>In article <1991Jun25.210210.3046@beaver.cs.washington.edu> goble@cs.washington.edu (Brian Goble) writes:
>>I have a dialog box with a bunch of edit windows (single-line).  
>>When the user enters info into the first edit box and then tabs to
>>the next edit box I want to know that something is in that first
>>edit box and use it to load in some other info.
>
>You should look at the messages related to change of selection in the 
>dialog box.  If I recall right, it's EN_SELCHANGE, or something like that.
>When you get it, then you can do whatever.  The actual message you get is
>the control's ID (forgive me if this is not quite right; I'm doing it from
>memory) with  the notification message in a parameter.  Or maybe it's
>WM_COMMAND with the ID in wParam and the notification in lParam.  In any
>event, it's the standard notification message, and the selection change
>notification is the ticket.
>
The EN_CHANGE message is used to notify the owner that the
contents of an EditItem have been changed.  If a user is
typing away, it will be send with *every* keystroke.

I think the original question was how to detect that the
contents have changed after the focus has left the edit.  It
can be done with the following code fragment (put it in your
DialogProc):

if (message == WM_COMMAND && wParam == idEditInQuestion)
	switch (HIWORD(lParam))
		{
	default:
		break;

	case EN_SETFOCUS:
		SendMessage(LOWORD(lParam), EM_SETMODIFY, 0, 0L);
		break;

	case EN_KILLFOCUS:
		if ((BOOL)SendMessage(LOWORD(lParam), EM_GETMODIFY, 0, 0L))
			{
			/* Do whatever updates here. */
			}
		break;
		}

cheers - Paul Bonneau.

press@venice.SEDD.TRW.COM (Barry Press) (06/29/91)

In article <1991Jun28.180952.6556@hyper.hyper.com> bonneau@hyper.UUCP (Paul Bonneau,,) writes:
>In article <1132@venice.SEDD.TRW.COM> press@venice.sedd.trw.com (Barry Press) writes:
>>In article <1991Jun25.210210.3046@beaver.cs.washington.edu> goble@cs.washington.edu (Brian Goble) writes:
>>>the next edit box I want to know that something is in that first
>>dialog box.  If I recall right, it's EN_SELCHANGE, or something like that.
>The EN_CHANGE message is used to notify the owner that the

(Apologies for not looking up the details, but ...)

Paul, if I remember right I really did mean EN_SELCHANGE.  There is
a notification that says that the selection has changed, and I thought
that it was there in general as well as for list boxes and combo
boxes.  Your method works, however.

-- 
Barry Press                                 Internet: press@venice.sedd.trw.com