Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何在c+中按enter键执行代码+;?_C++_Winapi - Fatal编程技术网

C++ 如何在c+中按enter键执行代码+;?

C++ 如何在c+中按enter键执行代码+;?,c++,winapi,C++,Winapi,在我的应用程序中,我有三个编辑框和一个提交按钮。我是 在单击submit按钮时执行一些代码,但我也希望,如果我按Enter键,代码也应该执行 我的代码是: case WM_COMMAND: switch(LOWORD(wParam)) { case IDC_MAIN_BUTTON: { SendMessage(h_Name,WM_GETTEXT,sizeof(CName)/sizeof(CName[0]),reinterpr

在我的应用程序中,我有三个编辑框和一个提交按钮。我是 在单击submit按钮时执行一些代码,但我也希望,如果我按Enter键,代码也应该执行

我的代码是:

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;
case WM_命令:
开关(LOWORD(wParam))
{
机箱IDC_主按钮:
{
SendMessage(h_Name,WM_GETTEXT,sizeof(CName)/sizeof(CName[0]),reinterpret_cast(CName));
SendMessage(h_电子邮件、WM_GETTEXT、sizeof(CName)/sizeof(CEmail[0])、reinterpret_cast(CEmail));
发送消息(h_Phone、WM_GETTEXT、sizeof(CPhone)/sizeof(CPhone[0])、重新解释(CPhone));
i=1;
启用窗口(GetDlgItem(hwnd,IDC_主按钮),错误);
启用窗口(GetDlgItem(hwnd,IDC清除按钮),false);
ShowWindow(GetDlgItem(hwnd,3),SW_SHOW);
发送消息(hwndPrgBar,PBM_设置位置,0,0);
设置计时器(hwnd,ID_计时器,10,空);
}
打破

您需要将“提交”按钮设置为默认按钮,以便按enter键与单击“提交”具有相同的效果。请阅读IDE的帮助以了解如何执行此操作。

我已将“提交”按钮作为默认按钮设置为SendMessage(hwnd,DM_SETDEFID,(WPARAM)IDC_MAIN_按钮,0),但它不起作用。您是否创建了具有BS|U def按钮样式的按钮?如果使用MFC,请在按钮的属性中将DefaultButton设置为true。我已经这样做了,但不起作用。我的按钮代码是-hWndButton=CreateWindowEx(NULL,“按钮”,“提交”,WS|TABSTOP | WS| u可见| WS| CHILD | BS| def按钮,100100,80,24,hwnd,(HMENU)IDC_MAIN_按钮,(HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),NULL);SendMessage(hWndButton,WM_SETFONT,NULL,MAKELPARAM(FALSE,0));我也尝试了这个-SendMessage(hwnd,DM_SETDEFID,(WPARAM)IDC_MAIN_按钮,0);是否在对话框中创建此按钮?我相信默认的按钮处理是通过对话框窗口过程完成的。如果按钮不在对话框中,则可以调用IsDialogMessage使窗口的行为类似于对话框。我认为Adrian McCarthy在此处的回答可能会为您提供所需的信息: