Solved

Edit Boxes, pressing Return to process.

Posted on 2002-03-14
10
286 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

12 Experts available now in Live!

Get 1:1 Help Now