?
Solved

Detect Enter Key in EDITBOX

Posted on 2006-06-07
11
Medium Priority
?
612 Views
Last Modified: 2012-06-21
Hi, I have created a textbox with using CreateWindowEX(), and #defind ID_EDITT at global. I would like to ask how can i detect user pressing enter/return key in the textbox, i would like to popup a messagebox when user finish enter words and press enter.
0
Comment
Question by:iphone
  • 5
  • 4
  • 2
11 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 16859243
0
 

Author Comment

by:iphone
ID: 16859301
but my edit control is not in a dialog box....

HWND hEdit = CreateWindowEx(
            0,
            L"EDIT",
            L"warrence",
            WS_VISIBLE | WS_CHILD,
            0,
            850,
            200,
            50,
            hWnd,
            (HMENU)ID_EDITT,
            hInstance,
            NULL);

i put this code in WinMain
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16859348
Handle WM_KEYDOWN message in the window procedure. If wParam = VK_RETURN and GetFocus returns edit box handle, Enter is pressed in edit box.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:iphone
ID: 16859376
if i have 3 edit box then how i would know the getFocus return which edit box?

HWND g = GetFocus();
if(g == ????????)

??
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16859398
CreateWindowEx returns editbox handle, keep it in some variable.
0
 

Author Comment

by:iphone
ID: 16859444
   case WM_KEYDOWN:
            {                  
                        MessageBox(hWnd,L"outside",L"outside",MB_OK);
                  if(wParam==VK_RETURN) {

                        HWND hWndTest = GetFocus() ;
                        if(&hWndTest == hEditInstance) {                              
                              MessageBox(hWnd,L"yes",L"yes",MB_OK);
                              return TRUE ;
                        }
                        else {                              
                              MessageBox(hWnd,L"no",L"no",MB_OK);
                              return FALSE ;
                        }
                  }
            }
Before i focus on edit box...i press enter and the message NO come out.....so i guess this syntax is correct....but however when you focus on edit box....and press enter....nothing happen....its like not go into WM_KEYDOWN, not even the outside message
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16859476
There are two problems in your code:

1.
if(&hWndTest == hEditInstance)  
I think it should be:
if(hWndTest == hEditInstance)

2. MessageBox changes current focus, use OutputDebugString instead. You can see results of OutputDebufString in Visual Studio Output window, when program runs under debugger. Without debugger, you can see this using DbgView program from www.sysinternals.com.

If this will not work, you need to subclass edit box and handle WM_KEYDOWN in it's window procedure.
0
 
LVL 3

Expert Comment

by:jitendra_wadhwani
ID: 16860069
case WM_KEYDOWN:
          {              
                        MessageBox(hWnd,L"outside",L"outside",MB_OK);
               if(wParam==VK_RETURN) {

                    HWND hWndTest = GetFocus() ;
                    if(&hWndTest == hEditInstance) {                        
                         MessageBox(hWnd,L"yes",L"yes",MB_OK);
                         return TRUE ;
                    }
                    else {                        
                         MessageBox(hWnd,L"no",L"no",MB_OK);
                         return FALSE ;
                    }
               }
          }


Remove
//                       MessageBox(hWnd,L"outside",L"outside",MB_OK);

This show messagebox and focus is with messagebox

next statement
HWND hWndTest = GetFocus() ;
will not get focus of the original Edit...

 
0
 

Author Comment

by:iphone
ID: 16868018
what should i do to know if it is in edit box then? if getfocud is not helping in this situation
0
 
LVL 3

Expert Comment

by:jitendra_wadhwani
ID: 16868335
Can you please post here your code...
specially complete Win Proc function...
0
 

Author Comment

by:iphone
ID: 16875475
thanks for the help, i have solve the problem
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

839 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