QDemo之HWND

一个简单的调用外部键盘的例子:

#include <windows.h> //头文件不要忘了

void LetterKeyboardController::toggleLetterKeyboard(const bool status, const int x, const int y)
{
    try{
        HWND letterKeyboard = NULL;
        letterKeyboard = FindWindow(L"LetterKeyboard",NULL);
        if(letterKeyboard == NULL){
            qWarning() << "LetterKeyboard未启动...请检查";
            //return;

            if(status){
                WinExec("LetterKeyboard.exe", SW_HIDE);
                letterKeyboard = FindWindow(L"LetterKeyboard", NULL);

                SetWindowPos(letterKeyboard, HWND_TOPMOST, x, y, 0, 0, SWP_NOSIZE);
                ShowWindow(letterKeyboard, SW_SHOW);
            }
            else{
                ShowWindow(letterKeyboard, SW_HIDE);
            }

        }

        if(status){
            SetWindowPos(letterKeyboard, HWND_TOPMOST, x, y, 0, 0, SWP_NOSIZE);
            ShowWindow(letterKeyboard, SW_SHOW);
        }
        else{
           ShowWindow(letterKeyboard, SW_HIDE);
        }

    }
    catch(...){
        qWarning() << "切换LetterKeyboard异常...请检查";
    }

}



你可能感兴趣的:(qt,hwnd,QDemo,窗口句柄)