Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Making An "EDIT" Box Created With Createwindow(), Listen To VK_RETURN (ENTER) Key?

Posted on 2004-04-01
4
Medium Priority
?
1,118 Views
Last Modified: 2013-12-03
Greetings Everybody

I am using Win32 API, no MFC, and on the Main Window only (ghwndAPP), I have created one Edit Box (no dialog-box) Using,

hwndeditbox=CreateWindow("EDIT",NULL,WS_VISIBLE | WS_CHILD | ES_LEFT ,240,510,316,24,ghwndApp,NULL,(HINSTANCE)GetWindowLong(ghwndApp,GWL_HINSTANCE),NULL);

I can enter text, can retrieve text etc things, using edit box messages. What right now I am doing is after the user enters the text, there is one button pressing which, the text entered goes to a txt file.
What I actually need now is in the text box even if the user presses ENTER Key, the required functionality(text going to txt file) should happen.

I am reading MSDN, using WM_KEYDOWN, WM_COMMAND etc things but not able to achieve.
Might be I am facing problem, because the TEXT Box, is not in a Dialog-Box, or might be I am not getting things right in interpreting the right Sequence of events and messages.

Please guide me, and if 10-12 lines of template code can be posted that will really great.

Thanks you for your help

Regards,
Bonns
0
Comment
Question by:bonnseye
  • 2
4 Comments
 

Expert Comment

by:narendj
ID: 10731457
Bonns,

You mentioned you don't want the user to be able to hit the "Enter" Key... So I presume you want only a single line of Input.

With that assumption, you can do the following

> Create the Edit box for single line input - you have already done this.
> Add "BS_DEFPUSHBUTTON" style to that "button".

Let me know how it goes.

Happy coding.
 
0
 
LVL 6

Expert Comment

by:joghurt
ID: 10740227
Or: Subclass the Edit window for your own edit control. It surely works, more versatily (you can capture any other keys, etc.) though a bit more complicated.

If you have only one or a few such edit controls in your dialog it may be simpler to override the WNDPROC only for that control(s). If you have more edit controls with this behaviour, it's more simple to change it for the "EDIT" window class and create all the controls afterwards.

I can supply you with an example for both methods if you want. Just tell in which are you interested.
0
 
LVL 6

Accepted Solution

by:
joghurt earned 400 total points
ID: 10753146
static WNDPROC      g_lpOldEditProc = NULL;


static long FAR PASCAL EditSubProc (HWND hWnd, UINT wMessage, WPARAM wParam, LPARAM lParam)
{
      HWND      hDlg = GetParent (hWnd);

      switch (wMessage) {
            case WM_GETDLGCODE:
//                  return (DLGC_WANTALLKEYS | CallWindowProc (g_lpOldEditProc, hWnd, wMessage, wParam, lParam));
                  return (DLGC_WANTCHARS | CallWindowProc (g_lpOldEditProc, hWnd, wMessage, wParam, lParam));
                  // break;

            case WM_CHAR: {
/*                  //Process this message to avoid message beeps.
                  if ((wParam == VK_RETURN) || (wParam == VK_TAB))
                        return 0;*/
                  break;
            }

            case WM_KEYDOWN:
/*                  if ((wParam == VK_RETURN) || (wParam == VK_TAB)) {
                        if (hDlg != NULL)
                              PostMessage (hDlg, WM_NEXTDLGCTL, 0, 0L);
                        return FALSE;
                  }*/
                  break;

            default:
                  break;
      }

      return CallWindowProc (g_lpOldEditProc, hWnd, wMessage, wParam, lParam);
}


and:
HWND      hWndEdit = CreateWindow ("Edit", "", 0, 0, 0, 20, 20, hMainWnd, NULL, hInst, NULL);
g_lpOldEditProc = reinterpret_cast<WNDPROC> (GetClassLongPtr (hWndEdit, GCLP_WNDPROC));
SetClassLongPtr (hWndEdit, GCLP_WNDPROC, reinterpret_cast<LONG_PTR> (EditSubProc));
DestroyWindow (hWndEdit);
0
 

Author Comment

by:bonnseye
ID: 10768512
Sorry, it took time, more than expected, but the tip was perfect.
Thank you
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

804 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