See: http://www.vccode.com/file_show.php? Id = 2226
I have done similar programs myself in the past. The principle is the same. What's different is that the hexadecimal value of each of my array elements is 10, and this program uses 1,000,000 as the hexadecimal value, okay !!
Below is a preliminary discussion. Don't laugh. I don't know much about MFC.
I want to make this program play the same role as pressing the press button in the text box. This is a natural idea. According to the VB idea, I found the available event of this text box, and there was no such thing as onkeypress. I thought: no such basic things will happen.
Find the half-day materials to know that there are two ways to go:
1. Rewrite onok () because it is in any text box (? If you press enter, this method is executed. In this example, there is only one text box that can receive the carriage return. You can directly call the method. But if there are multiple, what is the difference? The answer is: getfocus () will return the current focus element. You just need to identify it. Code:
Void cbigdatedlg: onok ()
{
If (getfocus () = getdlgitem (idc_value ))
This-> oncalculate ();
}
2. The previous method is not generic, so it is not recommended to use it. It is best to use the following method: override pretranslatemessage (MSG * PMSG )!! The Code is as follows:
Bool cbigdatedlg: pretranslatemessage (MSG * PMSG)
{
// Process the idc_value message
If (PMSG-> hwnd = getdlgitem (idc_value)-> getsafehwnd ())
{
// Avoid context menu
If (PMSG-> message = wm_rbuttonup | PMSG-> message = wm_contextmenu)
Return true;
// Consider the case where you press enter in the text box
If (PMSG-> message = wm_keydown & PMSG-> wparam = vk_return)
{
Cwnd * aw = This-> getfocus ();
(Cedit *) AW)-> setsel (0,-1); // select all text in the text box for ease of use !!
This-> oncalculate ();
}
}
Return cdialog: pretranslatemessage (PMSG );
}
In this example, I started to understand the meaning of the message loop.
Good luck !!