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).
Below is my code so far:
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?
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!
in Visual Studio, open your project, then in the upper menu go to:
CTestHarnessDlg
)Commands
tab in the search field type your Edit IDMessages
will be filled with all the messages from that controlEN_SETFOCUS
and press Add Handler
and type a name that you want or leave the default oneEdit Code
and you should be right there on the method implementationGo 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();
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)
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);
}
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
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.