选择编辑框后,如何打开对话框? MFC 2005 [英] How would you open a Dialog when an edit box is selected? MFC 2005

查看:210
本文介绍了选择编辑框后,如何打开对话框? MFC 2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果选择了编辑字段,我希望能够创建一个屏幕键盘来弹出。我使用MFC Visual studio 2005(基于C ++)。

I would like to be able to create an onscreen keyboard to popup whenever an edit field is selected. I am using MFC Visual studio 2005 (C++ based).

以下是我的代码:

void CTestHarnessDlg::OnEnChangeEdit3()
{
    CKeyboard Dlg;
    Dlg.DoModal();
}

当我运行对话框并点击所选字段时,打开屏幕键盘,直到我按下键盘上的一个键。有没有办法打开键盘,而不把任何东西放入文本字​​段?

When I run the Dialog box and click on the selected field, it does not open an onscreen keyboard until I press a key on the keyboard. Is there a way to open the keyboard without putting anything into the text field?

我一直在看着ON_EN_SETFOCUS,但我对MFC很新。我不知道如何使用代码中的CEDIT命令类...任何帮助是赞赏,谢谢!

I've been looking at ON_EN_SETFOCUS, but I'm very new to MFC. I'm not sure how to even use the CEDIT command classes within the code... Any help is appreciated, thanks!

推荐答案

如何使用Visual Studio类向导添加命令



Visual Studio,打开您的项目,然后在上层菜单中转到:

How to add commands using Visual Studio Class Wizard

in Visual Studio, open your project, then in the upper menu go to:


  • 项目>类向导

  • 选择您的项目和您的类名称(在您的情况下
    CTestHarnessDlg

  • code>命令选项卡在搜索字段中键入您的编辑ID

  • 选择它,列表框称为消息将填充该控件的所有消息

  • 选择 EN_SETFOCUS ,然后按添加处理程序并键入您想要的名称或离开默认名称

  • ,然后按OK或编辑代码和您应该在方法实现上。

  • 所有应该由类向导自动设置和创建:方法声明,方法实现,消息映射

  • Project>Class Wizard
  • select your project and your class name(in your case CTestHarnessDlg)
  • on the Commands tab in the search field type your Edit ID
  • Select it and the ListBox called Messages will be filled with all the messages from that control
  • Select EN_SETFOCUS and press Add Handler and type a name that you want or leave the default one
  • then press OK or Edit Code and you should be right there on the method implementation
  • everything should be set and created automatically by the class wizard: Method declaration, Method Implementation, Message Map

  • 转到你的类声明(通常在.h文件中)并添加方法声明,你必须知道您需要添加的功能的类型

  • Go to your class declaration(usually in the .h file) and add the method declaration, you will have to know the type of the function you need to add

afx_msg void OnSetfocusEdit();

转到消息映射(通常在cpp文件中)并添加映射,您将必须知道必须使用的宏,在这种情况下为ON_EN_SETFOCUS

go to the message map (usually in the cpp file) and add the mapping, you will have to know the macro that you have to use, in this case ON_EN_SETFOCUS

ON_EN_SETFOCUS(IDC_YOUR_EDIT_ID,& CTestHarnessDlg :: OnSetfocusEdit)

去你的cpp(通常在cpp文件中)并添加方法实现

go to your cpp (usually in the cpp file) and add the method implementation

void CTestHarnessDlg::OnSetfocusEdit()
{
    TCHAR sysDir[MAX_PATH];
    if( !GetSystemDirectory( sysDir,  MAX_PATH) )
    {
        ASSERT(FALSE);
        return;
    }
    ShellExecute(NULL, NULL, L"osk.exe", _T("") , sysDir, SW_SHOW);
}





使用osk.exe



命令 ShellExecute(NULL,NULL,Losk.exe,_T(),sysDir,SW_SHOW); 将打开窗口的屏幕虚拟键盘,您不需要创建自己的键盘对话框,默认情况下已经有一个在Windows上

using osk.exe

the command ShellExecute(NULL, NULL, L"osk.exe", _T("") , sysDir, SW_SHOW); will open window's on screen virtual keyboard, you don't ahve to create your own keyboard dialog there is already one by default on windows

您将必须创建自己的对话框(CKeyboard),但IMO不应使用 CDialog :: DoModal 方法,你应该使用 CDialog :: Create ,然后使用 CWnd :: ShowWindow ,然后使用 CWnd :: SetWindowPos 将对话框移动到您想要的位置。

you will have to create your own dialog (CKeyboard) but IMO you shouldn't use CDialog::DoModal method, you should make the dialog modeless using CDialog::Create then use CWnd::ShowWindow and then use CWnd::SetWindowPos to move your dialog where you want.

这篇关于选择编辑框后,如何打开对话框? MFC 2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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