?
Solved

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

Posted on 2004-04-01
4
Medium Priority
?
1,112 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
[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
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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 accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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 …
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…

764 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