Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my application I have three edit box and a submit button I am executing some code on submit button click but I also want that if I 'll press the enter key that code should also execute.my code is-

C#
case WM_COMMAND:



           switch(LOWORD(wParam))
           {

           case IDC_MAIN_BUTTON:
               {

                   SendMessage(h_Name,WM_GETTEXT,sizeof(CName)/sizeof(CName[0]),reinterpret_cast<LPARAM>(CName));
                   SendMessage(h_Email,WM_GETTEXT,sizeof(CName)/sizeof(CEmail[0]),reinterpret_cast<LPARAM>(CEmail));
                   SendMessage(h_Phone,WM_GETTEXT,sizeof(CPhone)/sizeof(CPhone[0]),reinterpret_cast<LPARAM>(CPhone));

                         i = 1;

                         EnableWindow( GetDlgItem(hwnd, IDC_MAIN_BUTTON),false);
                         EnableWindow( GetDlgItem(hwnd, IDC_CLEAR_BUTTON),false);
                         ShowWindow(GetDlgItem(hwnd, 3), SW_SHOW);
                         SendMessage( hwndPrgBar, PBM_SETPOS, 0, 0 );
                         SetTimer(hwnd, ID_TIMER, 10, NULL);


                    

                   
               }
               break;


so please now tell me that how this code will also execute on enter key press
Posted
Updated 1-Dec-14 22:20pm
v2

1 solution

Declare your button as DEFPUSHBUTTON in your dialog resource.
 
Share this answer
 
Comments
Member 10896619 2-Dec-14 7:24am    
I already did this but that is not working my button code is-

hWndButton=CreateWindowEx(NULL,"BUTTON","Submit",WS_TABSTOP | WS_VISIBLE |WS_CHILD| BS_DEFPUSHBUTTON,100,100,80,24,hwnd,(HMENU)IDC_MAIN_BUTTON,(HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),NULL);
SendMessage(hWndButton,WM_SETFONT,NULL,MAKELPARAM(FALSE,0));

I also try this also-

SendMessage(hwnd, DM_SETDEFID, (WPARAM)IDC_MAIN_BUTTON, 0);
Richard MacCutchan 2-Dec-14 11:18am    
Where are you declaring this, obviously not in the resource script. See also http://msdn.microsoft.com/en-us/library/windows/desktop/bb775951%28v=vs.85%29.aspx.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900