Solved

Edit Boxes, pressing Return to process.

Posted on 2002-03-14
10
288 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
  • 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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 100 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now