private const int WS_EX_TRANSPARENT = 0x20; private const int GWL_EXSTYLE = -20; /// <summary> /// window 扩展样式 分层显示 /// </summary> private const int WS_EX_LAYERED = 0x00080000;//取消鼠标穿透的 [DllImport("user32", EntryPoint = "SetWindowLong")] private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong); [DllImport("user32", EntryPoint = "GetWindowLong")] private static extern uint GetWindowLong(IntPtr hwnd, int nIndex); [DllImport("user32.dll", CharSet = CharSet.Auto)] private static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int Width, int Height, int flags); public static void SetTranMouseWind(Window window) { try { IntPtr hwnd = new WindowInteropHelper(window).Handle; uint extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE); SetWindowLong(hwnd, GWL_EXSTYLE, extendedStyle | WS_EX_TRANSPARENT); } catch { } } public static void ReSetNormalWind(Window window) { try { IntPtr hwnd = new WindowInteropHelper(window).Handle; uint extendedStyle = GetWindowLong(hwnd, GWL_EXSTYLE| WS_EX_LAYERED); SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_LAYERED); } catch { } }
标签:窗口,鼠标,int,hwnd,private,穿透,WS,EXSTYLE,GWL From: https://www.cnblogs.com/wgscd/p/17475277.html