解决unity发布exe在win7电脑上部显示输入法的问题。

  [DllImport("user32.dll")]
    public static extern IntPtr FindWindow(string className, string windowName);

    [DllImport("user32.dll")]
    internal static extern IntPtr SetForegroundWindow(IntPtr hWnd);

    [DllImport("user32.dll")]
    internal static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

    private void GetFocusWin()
    {
        //System.Diagnostics.Process currentProcess = System.Diagnostics.Process.GetCurrentProcess();
        //IntPtr hWnd = currentProcess.MainWindowHandle;
        
        IntPtr hWnd = FindWindow(null, "TestGPU1");

        if (hWnd != IntPtr.Zero)
        {
            SetForegroundWindow(hWnd);
            ShowWindow(hWnd, 10); // SW_SHOWDEFAULT = 10, SW_MAXIMIZE = 3, SW_SHOW = 5

        }
        else
        {
            Debug.LogWarning("GetFocusWin() failed, hWnd is 0!");
        }
    }

 

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐