Wenbin Geng
Wenbin Geng

Reputation: 3696

Cannot make TabTip transparent

I use the following code to make almost any program transparent

    class Program
{
    [DllImport("user32.dll")]
    private static extern bool EnumWindows(EnumWindowsProc lpEnumFunc, IntPtr lParam);

    [DllImport("user32.dll")]
    private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);

    [DllImport("user32.dll")]
    private static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

    [DllImport("user32.dll")]
    private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("user32.dll")]
    private static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);

    private const int GWL_EXSTYLE = -20;

    private const int WS_EX_LAYERED = 0x80000;

    private delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);

    private const int LWA_ALPHA = 0x2;

    static void Main(string[] args)
    {
        string processName = "TabTip"; // 替换为实际进程名称
        Process[] processes = Process.GetProcessesByName(processName);

        if (processes.Length > 0)
        {
            foreach (var process in processes)
            {
                EnumWindows((hWnd, lParam) =>
                {
                    uint processId;
                    GetWindowThreadProcessId(hWnd, out processId);
                    if (processId == (uint)process.Id)
                    {
                        // 设置透明度
                        byte transparency = 150; // 半透明
                                                 // 在设置透明度之前,先设置窗口为层叠样式
                        SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);

                        SetLayeredWindowAttributes(hWnd, 0, transparency, LWA_ALPHA);
                        InvalidateRect(hWnd, IntPtr.Zero, true);
                        Console.WriteLine($"窗口 {process.ProcessName} 的透明度已设置。");
                    }
                    return true;
                }, IntPtr.Zero);
            }
        }
        else
        {
            Console.WriteLine("未找到进程。");
        }
    }
}

However, the company has a touch-screen Windows computer, using Windows 10 Enterprise Edition. Whenever I click on the screen, a soft keyboard pops up. Now I want to make this soft keyboard transparent, but the code does not work.

enter image description here

enter image description here

Because the soft keyboard always covers most of the content, it's really annoying

I'd like to know all the ways to make the soft keyboard transparent

Upvotes: 0

Views: 35

Answers (0)

Related Questions