Q's About Edit Controls

This is a discussion on Q's About Edit Controls within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I have a few questions about edit controls
1) I also have a single line edit control. I want ...

Q's About Edit Controls

Hi, I have a few questions about edit controls

1) I also have a single line edit control. I want to know when the user has hit the enter key when the edit control has focus. Can I recieve notification of this? Do I have to subclass the control? P.S. ES_WANTRETURN is not what I want, I want notification of the enter key being pressed in a single line edit control. Would subclassing help?

2) I have a static icon control with SS_NOTIFY enabled so I get STN_CLICKED notifications when it is clicked. I want to send the control STM_SETICON messages when I recieve a click notification and change the icon (so it looks like it's been 'clicked'). Can I count that the next WM_LBUTTON up after an STN_CLICKED will be the user unclicking the static control? Can I just recieve notifications of this so I can change the static icon control to looking unclicked? Would subclassing help?

1) I also have a single line edit control. I want to know when the user has hit the enter key when the edit control has focus. Can I recieve notification of this? Do I have to subclass the control? P.S. ES_WANTRETURN is not what I want, I want notification of the enter key being pressed in a single line edit control. Would subclassing help?

I think that any message that gets sent to a child also gets sent to the parent too. . . therefore, if you know the hwnd of the child you could look at WM_KEYDOWN/WM_KEYUP with if (hwnd == MYCHILDHWND) -- which works because of the whole pointer pointing to one location in memory. . . Then you could do whatever you wanted with the information.

2. Seems like monitoring all mouse messages is required, in which case a WH_MOUSE hook might be an option. For less overkill, subclass the static control and SetCapture/ReleaseCapture to ensure precise control over mouse messages.

1) This tutorial at The Code Project should help out. (Google search for: subclass edit control WM_CHAR)

2) I definitely agree with CornedBee, you'll have a much easier time using an owner-drawn button (Google search for: owner drawn buttons site:msdn.microsoft.com).
--This will give you a DRAWITEMSTRUCT structure that contains all of the information you're looking for).

I suppose this depends on what's needed, but there's not much to either approach. However, given the OP wants it "so it looks like it's been 'clicked'"(which I didn't see initially), then owner drawn does seem the more typical solution.

Thank you muchly for the example code. I kind of forgot about this. However, I may be reverting to the windows 'default action' approach for this, or trying to at least.

>> 1) The SDK docs say that pressing enter is equivalent to clicking the owning dialog's default button. So if your main window is or pretends to be a dialog, it would the corresponding notification.

I'm trying to find where you said that, and what might be the default action for a window. I tried making a button with what I thought might be a default action by specifying the BS_DEFPUSHBUTTON style

I do not get WM_COMMAND notification from the button pressing enter in the IDC_CHATTY single line edit control, however I do get two WM_COMMAND notifications from just clicking on the IDC_CHATTY control.