打算写一个成绩统计系统,输入8个成绩,得出各个成绩段的人数。界面如下:
我希望是在输入框输入成绩后按回车可以将这个成绩保存,并清空输入框以进行下一次输入,所以此处的代码如下:
else if (uMsg == WM_KEYDOWN && wParam == VK_RETURN) //键入回车 { char str[4]; GetDlgItemText(hwnd, IDC_EDIT1, str, 4); SetDlgItemText(hwnd, IDC_EDIT1, ""); //清空编辑框 b[j] = _ttoi(str); //录入编辑框中数据 j++; }
但是按回车还是没有反应,是什么问题呢?要怎么正确实现回车输入呢?
完整代码如下:
#include <windows.h> #include <string.h> #include "stdafx.h" #include "resource.h" HINSTANCE hInstance; LRESULT CALLBACK _ProcDlgMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { int a1; short a2; int i, b[8]; int j = 0; int q[6]; HICON hc; if(uMsg == WM_CLOSE) EndDialog(hwnd,NULL); else if (uMsg == WM_KEYDOWN && wParam == VK_RETURN) //键入回车 { char str[4]; GetDlgItemText(hwnd, IDC_EDIT1, str, 4); SetDlgItemText(hwnd, IDC_EDIT1, ""); //清空编辑框 b[j] = _ttoi(str); //录入编辑框中数据 j++; } else if(uMsg == WM_COMMAND) { a1=wParam; a2=a1; if(a2 == B2) EndDialog(hwnd,NULL); else if (a2 == B1) { for(i=0;i<6;i++) q[i]=0; //b数组中存储成绩 //q数组中存储各分数段人数 __asm{ mov ecx, 8 mov edi, 0 again: mov edx, b[edi*4] cmp edx, 60 jb below60 cmp edx, 70 jb below70 cmp edx, 80 jb below80 cmp edx, 90 jb below90 cmp edx, 100 jb below100 equal100: inc q[5*4] jmp done below60: inc q[0*4] jmp done below70: inc q[1*4] jmp done below80: inc q[2*4] jmp done below90: inc q[3*4] jmp done below100: inc q[4*4] done: inc edi loop again } SetDlgItemInt(hwnd,E1,q[0],TRUE); SetDlgItemInt(hwnd,E2,q[1],TRUE); SetDlgItemInt(hwnd,E3,q[2],TRUE); SetDlgItemInt(hwnd,E4,q[3],TRUE); SetDlgItemInt(hwnd,E5,q[4],TRUE); SetDlgItemInt(hwnd,E6,q[5],TRUE); } } else return FALSE; } int _stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,int nCmdShow) { hInstance=GetModuleHandle(NULL); DialogBoxParam(hInstance,(LPCTSTR)D1, NULL, (DLGPROC)_ProcDlgMain,NULL); ExitProcess(NULL); return 0; }