因为现在要交课程设计,暂时没时间系统学习mfc,不太理解其中的工作原理。
做的是一个成绩统计系统,输入8个成绩,输出个分数段人数。界面如下:
现在在就是想实现在输入框输入成绩后按回车,可以完成本次输入、清空编辑框再进行下一次输入。网上说是重写PreTranslateMessage:
BOOL CGradeStatisticDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_RETURN)
{
p[i] = m_score; //m_score 为编辑框对应的cstring类型变量
m_score="0x0D";
i++;
UpdateData(true);
return true;
}
return CDialog::PreTranslateMessage(pMsg);
}
然后请问重写完后要怎么在主程序中加入它呢?
主程序为
#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)
{ BOOL szBuffer;
int a1;
short a2;
int i, b[8];
int q[6];
HICON hc;
if(uMsg == WM_CLOSE)
EndDialog(hwnd,NULL);
else if(uMsg == WM_COMMAND)
{ a1=wParam;
a2=a1;
if(a2 == B2)
EndDialog(hwnd,NULL);
else if (a2 == B1)
{
for (int j=0; j<8; j++) b[j]=89; //b为输入成绩,q为统计成绩
for(i=0;i<6;i++) q[i]=0;
__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;
return TRUE;
}
int _stdcall WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{ hInstance=GetModuleHandle(NULL);
DialogBoxParam(hInstance,(LPCTSTR)D1,NULL,(DLGPROC)_ProcDlgMain,NULL);
ExitProcess(NULL);
}