Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

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 …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

618 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