CEdit控件问题! [英] CEdit Control Question!

查看:125
本文介绍了CEdit控件问题!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CEdit控制输入文本显示到屏幕之前的最佳位置是哪里,因此我可以控制输入文本并对其进行更改,最后将其显示在屏幕上?

请给我一个示例代码!

Where is the best place to handle an CEdit control input text before it is displayed to the screen, so I can control the input text and make changes to it and finally display it to the screen ?

Give me an example code please !

推荐答案

Here are some assorted videos that show how to handle a few different scenarios.

Hope it helps

-DrB


您还可以研究从CEdit类继承并编写自己的控件.然后处理WM_CHAR消息并决定要使用它做什么.在.h文件中,您可以具有
You could also look into inheriting from a CEdit class and write your own control. Then handle the WM_CHAR message and decide what you want to do with it. In a .h file you could have
class CFloatEdit : public CEdit 
{
public:
	// Message handler for WM_CHAR message.
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);    

}



然后在您的.cpp实现文件中



Then in your .cpp implementation file

afx_msg void CFloatEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if (isdigit(nChar) || (nChar == ''.'') || (nChar < 0x20))
		CEdit::OnChar(nChar, nRepCnt, nFlags);
	else
		MessageBeep(0xFFFFFFFF);
}



但这不是一个完整的实现,但是可以为您提供总体思路.



That''s not a complete implementation, but gives you the general idea.


控件通常在对话框的OnInitDialog中初始化,该对话框在显示对话框之前执行.在显示控件之前,不必执行输入测试,因为用户无法输入任何内容.

输入验证通常在OnOK中执行.

这是相当琐碎的基础知识.但是,这是一些代码:

Controls are usually initialized in OnInitDialog of your dialog which is executed before the dialog is shown. It is not necessary to perform input tests before the control is shown, because the user can''t enter anything.

Input validation is usually performed in OnOK.

This is rather trivial and basic knowledge. However, here is some code:

void CMyDialog::OnInitDialog()
{
    CDialog::OnInitDialog();
    m_editMyInput.SetWindowText(_T("my input"));
    return TRUE;
}
void CMyDialog::OnOK()
{
    CString str;
    m_editMyInput.GetWindwText(str);
    if (str == _T("invalid"))
        return;
    CDialog::OnOK();
}


这篇关于CEdit控件问题!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆