mfcdialogkeyboardeditbox

How would you open a Dialog when an edit box is selected? MFC 2005


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!


Solution

  • How to add commands using Visual Studio Class Wizard

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

    How to add commands manually

    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);
    }
    

    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

    not using osk.exe

    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.