Murugan.com
Murugan Andezuthu Dharmaratnam

  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  



VC++ Win32 Trapping Edit Enter Key Press WM_KEYDOWN VK_RETURN


Home   VC++   VC++ Win32 Trapping Edit Enter Key Press WM_KEYDOWN VK_RETURN 
       

I have created a child window of class EDIT . When I click on enter I am not able to trap it. How do I Trap the enter key . I would appreciate some help in being able to 'trap' a keydown and keyup event when text is entered in an edit control.

Solution

You can subclass  the edit control, to process the Windows messages you want to, before passing them on to the edit control.

Here's a some code for a Win32 app its an app with an edit box created in the standard window. I've sub-classed the edit control to trap the WM_KEYDOWN   and check if enter key is pressed using VK_RETURN, 


WNDPROC wpOrigEditProc;
// The sub-classed edit control's wndproc
LRESULT APIENTRY EditSubclassProc(
                                  HWND hwnd, 
                                  UINT uMsg, 
                                  WPARAM wParam, 
                                  LPARAM lParam) 
{ 
	switch(uMsg)
	{
		case VK_RETURN:
			MsgBox("Return Key Pressed");
			break;
		case WM_KEYDOWN: 
			if (wParam == VK_RETURN)
			{
				MsgBox("Enter Key Pressed");
			}
			break;

	}
   // Pass all messages on to the original wndproc. Obviously, the WM_CHAR one has been tampered with :-)
   return CallWindowProc(wpOrigEditProc, hwnd, uMsg, wParam, lParam); 
} 

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{

	INITCOMMONCONTROLSEX icex;
    
    // Ensure that the common control DLL is loaded. 
    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC  = ICC_LISTVIEW_CLASSES;
    InitCommonControlsEx(&icex); 
    InitCommonControls();	
	RECT rcl; 
	HWND hWnd;
	hInst = hInstance; // Store instance handle in our global variable

	hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);


hWndTB = CreateWindow("EDIT", 
                                "", 
                                WS_CHILDWINDOW|WS_BORDER|ES_AUTOHSCROLL|WS_CHILD|WS_VISIBLE, 
                                x, 
                                y, 
                                width, 
                                height, 
                                hWnd, 
                                NULL, 
                                hInst, 
                                NULL); 

wpOrigEditProc = (WNDPROC) SetWindowLong(hWndTB , GWL_WNDPROC, (LONG) EditSubclassProc); 

   ShowWindow(hWnd, nCmdShow);
   ShowWindow(hWndTB ,nCmdShow);
   UpdateWindow(hWnd);
   UpdateWindow(hWndTB );
   return TRUE;
}


.Net VC File IO Sample Code

activex mdb

com smartcard

COM variant Data type

DirectX Store Video as mpeg

GetLastError() in VC++ Win32 Display the Value in a MessageBox

GetWindowName() VC++ Win32 Get a Window Name Given Handle

index

multi threaded socket

shellexecute open internet explorer

VC Win32 Tree View Control Change Background color of tree

VC++ 6.0 Win32 SetParent () Add an Existing Window as child window of another or Dynamically add a child window or Assign Window to a parent

VC++ 6.0 Win32 Splitter control like SplitContainer in .Net

VC++ 6.0 Win32 What are the Different Windows Controls That are Available in Win32 Non MFC

VC++ DWORD To String

VC++ Error LNK2001 unresolved external symbol public static

VC++ Win32 compare string with empty character constant

VC++ Win32 Compress Video To Mpeg

VC++ Win32 Exit Application

VC++ Win32 FTP Sessions Client Application

VC++ WIn32 IP from domain name

VC++ win32 Listview Get Selected Item

VC++ win32 ListView or LIST Control how to scroll to a list or make sure that a list item is visible

VC++ Win32 ListView SelectedItem()

VC++ Win32 Open in Internet explorer or firefox



  |  HOME   |  BLOG   |  TWITTER   |  ARTICLES   |  8086  |  C++   |  VC++   |  ASP .NET   |  VB .NET   |  JAVA SCRIPT   |  MS SQL   |  PHP   |  MY   |  VIDEOS   |  DOWNLOADS   |  CONTACT ME   |  

Copyright 2009 @ Murugan Andezuthu Dharmaratnam