Qt在Win下调用系统的软键盘,区分win7\win8\win10

代码如下:


#include <QOperatingSystemVersion>
#include <QDesktopServices>
#include <QUrl>
#include <QUrl>
#include <Windows.h>
#pragma comment(lib, "user32.lib")//打开屏幕键盘使用头文件

//调用系统键盘
void systemKeyboard()
{
    if(QOperatingSystemVersion::current() > QOperatingSystemVersion::Windows7)//版本大于win7
    {
        //win8.1   win10 下使用
        PVOID OldValue = nullptr;
        BOOL bRet = Wow64DisableWow64FsRedirection(&OldValue);
        QString csProcess = "C:\\Windows\\System32\\osk.exe";
        QString params="";
        ShellExecute(nullptr, L"open", (LPCWSTR)csProcess.utf16(), (LPCWSTR)params.utf16(), nullptr, SW_SHOWNORMAL);
        if (bRet)
        {
            Wow64RevertWow64FsRedirection(OldValue);
        }
    }
    else
    {
        //只能在win7下使用
        QDesktopServices::openUrl(QUrl("osk.exe", QUrl::TolerantMode));
    }
}

猜你喜欢

转载自blog.csdn.net/hss2799/article/details/111626829