[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Edit Boxes, pressing Return to process.

Posted on 2002-03-14
10
Medium Priority
?
297 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

656 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