MFC 专注于我的输入框的第一个字段
我是MFC的初学者,我只想默认选择我的输入框,准备在输入框弹出时用键盘输入文本。
这是我的类的 C++ .cpp 文件:
testInputBox::testInputBox(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_INPUT_BOX, pParent)
, warning(_T(""))
{
}
testInputBox::~testInputBox()
{
}
void testInputBox::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_INPUT_BOX, editcedit);
DDX_Text(pDX, IDC_STATIC_MESSAGE, warning);
DDV_MaxChars(pDX, warning, 100);
}
BEGIN_MESSAGE_MAP(testInputBox, CDialogEx)
ON_EN_CHANGE(IDC_EDIT_INPUT_BOX, &testInputBox::OnEnChangeEdit1)
ON_BN_CLICKED(IDOK, &testInputBox::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &testInputBox::OnBnClickedCancel)
ON_STN_CLICKED(IDC_STATIC_MESSAGE, &testInputBox::OnStnClickedStaticMessage)
END_MESSAGE_MAP()
I'm a beginner in MFC and I just want my input box selected by default, ready to input text with the keyboard when the input box pops up.
Here is my C++ .cpp file of the class:
testInputBox::testInputBox(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_INPUT_BOX, pParent)
, warning(_T(""))
{
}
testInputBox::~testInputBox()
{
}
void testInputBox::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_EDIT_INPUT_BOX, editcedit);
DDX_Text(pDX, IDC_STATIC_MESSAGE, warning);
DDV_MaxChars(pDX, warning, 100);
}
BEGIN_MESSAGE_MAP(testInputBox, CDialogEx)
ON_EN_CHANGE(IDC_EDIT_INPUT_BOX, &testInputBox::OnEnChangeEdit1)
ON_BN_CLICKED(IDOK, &testInputBox::OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, &testInputBox::OnBnClickedCancel)
ON_STN_CLICKED(IDC_STATIC_MESSAGE, &testInputBox::OnStnClickedStaticMessage)
END_MESSAGE_MAP()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要覆盖 < code>OnInitDialog() 是
CDialogEx
类的成员,并在该重写中将焦点设置到所需的控件。然后,因为您已经显式设置了焦点,所以您的覆盖函数应该返回零(或FALSE
)。假设您的
editcedit
是指向您希望获得焦点的控件的指针,那么您的重写将如下所示:您的重写应在类中声明,如下所示:
You need to override the
OnInitDialog()
member of theCDialogEx
class and, in that override, set the focus to the desired control. Then, because you have explicitly set the focus, your override function should return zero (orFALSE
).Assuming your
editcedit
is a pointer to the control you wish to have the focus, then your override will look something like this:Your override should be declared in the class like this:
CDialog:: GotoDlgCtrl
是您搜索的内容。}
CDialog::GotoDlgCtrl
is what you search.}