?
Solved

Edit Boxes, pressing Return to process.

Posted on 2002-03-14
10
Medium Priority
?
296 Views
Last Modified: 2013-12-03
Hi,

I'm in my stupid mode again, and don't see what I am doing wrong.

In my app, I have an edit box - single line.  I need to be able to enter text and then press the Return key to "submit" the text (kinda like a chat program)

I found in the MSDN a little thing about setting the default button and all, but that didn't seem to help.

every time I press Enter all I get is a ding sound.

In spy, it appears that when I press Enter - the message is going to the edit box, but isn't being passed on to the main dialog box in any way.

Can anyone give some tips on this rather simple issue.

Short and sweet again:
1 edit box.
Needs to notify the main program when Enter is pressed (auto push on a default button would be fine if I can get it to work)

What it's doing:
When enter is pressed, the program (actually windows AFAIK) dings
0
Comment
Question by:navigator010897
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 22

Expert Comment

by:cookre
ID: 6867333
Where's the focus after the ding?
Does it stay in the box?
Any other controls present?
0
 
LVL 1

Author Comment

by:navigator010897
ID: 6867368
Focus remains within the edit box.

There are 4 buttons, 3 functional, 1 hidden and disabled - in place for future functionality, an edit box, and a list box (listbox acts as display window for output).

I have set the default button action to the "speak" button, which is how I have to tell the program right now to process what is in the edit box.

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 6867374
Derive a class from CEdit, Use its OnKeyDown function, from there u can post message to the parent window. ie PostMessage to Dialog.

GOOD LUCK
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 1

Author Comment

by:navigator010897
ID: 6867422
Roshmon:  I am not using C++, nor MFC - this is pure win32 =(  I don't know enough about MFC to even attempt such a feat anyway
0
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 300 total points
ID: 6867427
Then subclass edit window and use PostMessage..

GOOD LUCK
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6887615
1) To prevent the messagebeep you have to set the keypress to character 0 in the appropriate handler.

2) To activate some other event handler (such as a button click) you need to call it explicitly in the keypress handler of the edit control. The Default property of the button will not come into play when an edit control has focus.

In Delphi this process would look something like this:

procedure TForm1.Edit1KeyPress(Sender: TObject;
  var Key: Char);
begin
  If (Key = #13) then begin
    if Button1.Enabled then Button1Click(Sender);
    Key := #0;
  end
  else inherited;
end;

If you want help converting this code into some other language then let me know.
0
 

Expert Comment

by:lanceedmonds
ID: 6922825
Subclass the edit control.  

In response to WM_GETDLGCODE, return DLGC_WANTALLKEYS.

Now handle WM_CHAR normally, and intercept VK_RETURN, or what have you.  In your case, when VK_RETURN is received, you probably want to do a SendMessage(BM_CLICK) to your "speak" button.

In PowerBASIC (DDT style), the subclass callback this could look something like this:

CALLBACK FUNCTION SubClassEditProc
    IF CBMSG = %WM_GETDLGCODE THEN
        FUNCTION = %DLGC_WANTALLKEYS
        EXIT FUNCTION
    ELSEIF CBMSG = %WM_CHAR THEN
        IF CBWPARAM = %VK_TAB THEN
            '... process TAB CONTROL here
        ELSEIF CBWPARAM = %VK_RETURN THEN
            '... process ENTER here or swallow with EXIT FUNCTION
        END IF
    END IF
    ' Pass the message to the original window procedure
    FUNCTION = CallWindowProc(oldProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
END FUNCTION



0
 

Expert Comment

by:lanceedmonds
ID: 6922826
Er, probably better to make that a PostMessage(BM_CLICK) rather than a SendMessage().  <smile>
0
 
LVL 1

Author Comment

by:navigator010897
ID: 7012911
I am still working on a program that needs this - I haven't been able to do a conversion yet from the PB to C, but hope to in the next few days - assuming your answer is correct, I'll leave a grade then.  I'm sorry for the delay, unfortunately your post came during a family emergency and I'm running a bit behind.
0
 
LVL 1

Author Comment

by:navigator010897
ID: 7979385
This did provide the information I needed in order to create my answer.  A little more info on subclassing would have made it a bit easier, but I was able to fix my problem.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question