C# 虚拟键盘无边界Win 10

C# 虚拟键盘无边界Win 10,c#,unity3d,keyboard,virtual,borderless,C#,Unity3d,Keyboard,Virtual,Borderless,我想把Win 10的虚拟键盘变成无边界的 但我不知道为什么它不起作用 我试过用记事本,它能用 (我做了一个Debug.log来检查IntPtr是否为null,并且在这两种情况下都返回true) 这就是我所做的 using UnityEngine; using System; using System.Runtime.InteropServices; public class test : MonoBehaviour { [DllImport("user32.dll")] public sta

我想把Win 10的虚拟键盘变成无边界的 但我不知道为什么它不起作用

我试过用记事本,它能用

(我做了一个Debug.log来检查IntPtr是否为null,并且在这两种情况下都返回true)

这就是我所做的

using UnityEngine;
using System;
using System.Runtime.InteropServices;

public class test : MonoBehaviour 
{
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string className, string windowName);

[DllImport("USER32.DLL")]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("USER32.DLL")]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true, ExactSpelling = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);

const int WS_BORDER = 8388608;
const int WS_DLGFRAME = 4194304;
const int WS_CAPTION = WS_BORDER | WS_DLGFRAME;
const int WS_SYSMENU = 524288;
const int WS_THICKFRAME = 262144;
const int WS_MINIMIZE = 536870912;
const int WS_MAXIMIZEBOX = 65536;
const int GWL_STYLE = -16;
const int GWL_EXSTYLE = -20;
const int WS_EX_DLGMODALFRAME = 0x1;
const int SWP_NOMOVE = 0x2;
const int SWP_NOSIZE = 0x1;
const int SWP_FRAMECHANGED = 0x20;
const uint MF_BYPOSITION = 0x400;
const uint MF_REMOVE = 0x1000;

private void Borderless() {

   // IntPtr hWnd = FindWindow(null,"On-Screen Keyboard"); // <----- Not Working
    IntPtr hWnd = FindWindow(null,"Untitled - NotePad"); // <----- Working

    if (hWnd != IntPtr.Zero) 
    {
        int Style = 0;

        Style = GetWindowLong(hWnd, GWL_STYLE);
        Style = Style & ~WS_CAPTION;
        Style = Style & ~WS_SYSMENU;
        Style = Style & ~WS_THICKFRAME;
        Style = Style & ~WS_MINIMIZE;
        Style = Style & ~WS_MAXIMIZEBOX;

        SetWindowLong(hWnd, GWL_STYLE, Style);
        Style = GetWindowLong(hWnd, GWL_EXSTYLE);
        SetWindowLong(hWnd, GWL_EXSTYLE, Style | WS_EX_DLGMODALFRAME);
        SetWindowPos(hWnd, new IntPtr(0), 50, 0, 150, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED);
    }
     else 
    {
        Debug.LogWarning("Borderless() failed, hWnd is 0!");
    }
}

void Start()
{
    Borderless();
}
使用UnityEngine;
使用制度;
使用System.Runtime.InteropServices;
公共课堂测试:单一行为
{
[DllImport(“user32.dll”)]
公共静态外部IntPtr FindWindow(字符串类名称、字符串窗口名称);
[DllImport(“USER32.DLL”)]
公共静态外部intsetWindowLong(IntPtr hWnd、intnindex、intdwnewlong);
[DllImport(“USER32.DLL”)]
公共静态外部intgetWindowLong(IntPtr hWnd,intnindex);
[DllImport(“user32.dll”,CharSet=CharSet.Auto,SetLastError=true,ExactSpelling=true)]
公共静态外部bool SetWindowPos(IntPtr hWnd、IntPtr hwninsertafter、intx、inty、intcx、intcy、intuflags);
const int WS_BORDER=8388608;
常量int WS_DLGFRAME=4194304;
const int WS_CAPTION=WS_BORDER | WS_DLGFRAME;
const int WS_SYSMENU=524288;
const int WS_THICKFRAME=262144;
const int WS_MINIMIZE=536870912;
const int WS_max=65536;
const int GWL_STYLE=-16;
const int GWL_EXSTYLE=-20;
常量int WS_EX_DLGMODALFRAME=0x1;
常数int SWP_NOMOVE=0x2;
常数int SWP_NOSIZE=0x1;
常量int SWP_FRAMECHANGED=0x20;
常数MF_BYPOSITION=0x400;
常数MF_REMOVE=0x1000;
私有无效无边界(){

//IntPtr hWnd=FindWindow(null,“屏幕键盘”);//好的,我有另一个解决方案,可能更好


我知道这不是一个真正的答案,所以如果有人知道上面的代码为什么不起作用,我会很高兴地了解;)

好的,我得到了另一个解决方案,也许是更好的

我知道这不是一个真正的答案,所以如果有人知道上面的代码为什么不起作用,我很乐意学习;)