【发布时间】:2019-11-07 09:37:58
【问题描述】:
我正在使用 C# WinForms 创建覆盖。叠加层需要与当前屏幕的大小相同(或大于)。但是,它不需要启用“焦点辅助”功能。
我曾尝试使用 FormWindowState.Maximized 和 P/Invoke MoveWindow,但只要表单大小与屏幕大小相同(或大于),就会启用焦点辅助。
这是我目前的代码:
覆盖表单构造函数
this.DoubleBuffered = true;
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.SupportsTransparentBackColor, true);
SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)(GetWindowLong(this.Handle, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE));
SetLayeredWindowAttributes(this.Handle, 0, 128, LWA_ALPHA);
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
移动窗口
Screen screen = Screen.FromPoint(Cursor.Position);
MoveWindow(this.Handle, screen.Bounds.X, screen.Bounds.Y, screen.Bounds.Width, screen.Bounds.Height, true);
如果有任何方法可以禁用此功能,我还没有找到。任何想法将不胜感激。
【问题讨论】:
-
没有魔术窗口选项可以覆盖该功能,您必须考虑仅覆盖活动窗口而不是整个屏幕。如果该窗口被最大化,那么覆盖也将被最大化,但这遵循用户的偏好。您要做的唯一重要的事情是让覆盖在移动时跟随窗口。使用 System.Windows.Automation 获取事件。
-
我过去曾制作过这样的叠加层,我只是想知道是否有解决方法,或者是否有类似于以前 Windows 版本中可用于 Quiet Hours 的 API。目前,如果不处理未记录的代码似乎是不可能的,我认为这在生产代码库中不是一个好主意。还是谢谢你。
标签: c# windows winforms windows-10-desktop