Thread: Edit

  1. #1
    Unregistered
    Guest

    Edit

    I have data in one edit box and want to display this data in another edit box when one presses Enter rather than having to click a button. Thanks in advance.

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Unless you have specified the ES_WANTRETURN style for the edit box, pressing enter has the same effect as pressing the default button on a dialog etc., so set the default button to enact the copy operation you want.

    Look in the help at edit control styles.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You could use SetWindowLong on one of the edit boxes to give it a new window process that filters enter presses and sends its info to another edit box.........like this

    Code:
    #include <windows.h>
    
    LRESULT CALLBACK WindowProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK EditProc(HWND, UINT, WPARAM, LPARAM);
    
    char szClassName[] = "WindowsApp";
    HINSTANCE g_hInst;
    char buf[500];
    HWND hEdit1,hEdit2;//the 2 edits
    WNDPROC MainWindProc;//for the subclassing
    
    
    int WINAPI WinMain(HINSTANCE hThisInstance,
     HINSTANCE hPrevInstance, LPSTR lpszArgument,
     int nFunsterStil)
    
    {
        HWND hwnd;               
    	MSG messages;            
    	WNDCLASSEX wincl; 
    	
    	g_hInst = hThisInstance;
    
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProc;      
        wincl.style = CS_DBLCLKS;               
        wincl.cbSize = sizeof(WNDCLASSEX);
        wincl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
        wincl.hCursor = LoadCursor(NULL, IDC_ARROW);
        wincl.lpszMenuName = NULL;
        wincl.cbClsExtra = 0; 
        wincl.cbWndExtra = 0; 
        wincl.hbrBackground = (HBRUSH) GetStockObject(LTGRAY_BRUSH);
    
        
        if(!RegisterClassEx(&wincl)) return 0;
    
       
        hwnd = CreateWindowEx(0,szClassName, "Windows App",
    		WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,	200,130, HWND_DESKTOP,NULL,            
               hThisInstance,NULL );    
    
       
        ShowWindow(hwnd, nFunsterStil);
    	UpdateWindow(hwnd);
       
        while(GetMessage(&messages, NULL, 0, 0))
        {
              TranslateMessage(&messages);
              DispatchMessage(&messages);
        }
    
        return messages.wParam;
    }
    
    
    LRESULT CALLBACK WindowProc(HWND hwnd, 
    UINT msg, WPARAM wParam, LPARAM lParam)
    {
    
    	
        switch (msg)                
        {
               case WM_CREATE:    
    			   hEdit1 = CreateWindowEx(0,"EDIT","",
    				   WS_BORDER | WS_VISIBLE | WS_CHILD,
    				   10,20,170,30,hwnd,NULL,g_hInst,NULL);//edit 1
    
    			   hEdit2 = CreateWindowEx(0,"EDIT","",
    				   WS_BORDER | WS_VISIBLE | WS_CHILD,
    				   10,60,170,30,hwnd,NULL,g_hInst,NULL);//edit2
    
    			  MainWindProc =  (WNDPROC)SetWindowLong(hEdit1,
    				   GWL_WNDPROC,(DWORD)EditProc);//set now wnd func
               
               break;
               
               
    		   case WM_DESTROY:
               PostQuitMessage(0);        
               break;
               default:                   
               return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    
    LRESULT CALLBACK EditProc(HWND hwnd,//The new edit proc
     UINT msg, WPARAM wParam, LPARAM lParam){
    
    
    
    	switch(msg){
    		case WM_CHAR:
    			if((int) wParam == VK_RETURN){
    				GetWindowText(hwnd, buf, 500);
    				SetWindowText(hEdit2,buf);
    			break;
    			}
    	else 
                return CallWindowProc(MainWindProc,
    hwnd,msg,wParam, lParam);
    		break;
    	}
    	return CallWindowProc(MainWindProc,hwnd, msg, wParam, lParam);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. (Multiline) Edit Control Limit
    By P4R4N01D in forum Windows Programming
    Replies: 9
    Last Post: 05-17-2008, 11:56 AM
  2. line number on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-18-2008, 07:58 AM
  3. WS_HSCROLL in ES_READONLY edit box error
    By Homunculus in forum Windows Programming
    Replies: 4
    Last Post: 02-13-2006, 08:46 AM
  4. Multiline Edit Box Parser
    By The Brain in forum Windows Programming
    Replies: 6
    Last Post: 11-01-2005, 07:15 PM
  5. Replies: 3
    Last Post: 07-23-2005, 08:00 AM