当工作站锁定然后解锁时,如何防止窗口大小调整?
我们有一个在多显示器环境中运行的应用程序。用户通常将应用程序对话框分散到多个监视器上。
如果用户锁定工作站,然后解锁它,我们的应用程序就会被告知调整大小。
我们的用户发现这种行为令人沮丧,因为他们随后花了一些时间恢复以前的布局。
我们还不确定是图形驱动程序请求调整大小还是 Windows。希望通过这个问题,可以更清楚哪个组件负责,
(文件)资源管理器和 Firefox 等流行应用程序在此设置中的行为方式相同。只需复制:
- 打开资源管理器 (
Win+E
)- 将资源管理器窗口水平拖动到大于 1 个屏幕
- 锁定工作站(
Win+L
), - 解锁
- 应用程序现在应该调整大小以仅在一个屏幕上
将 工作站已锁定然后解锁?
我们需要编写检查(解锁)锁定的代码吗?
还有其他我们不知道的机制吗?
We have an application that is run in multi-monitor environments. Users normally have the application dialog spread out to span multiple mointors.
If the user locks the workstation, and then unlocks it, our application is told to resize.
Our users find this behavior frustrating, as they then spend some time restoring the previous layout.
We're not yet sure whether it is the graphics driver requesting the resize or Windows. Hopefully through this question, it will become clearer which component is responsible,
Popular applications like (File) Explorer and Firefox behave the same way in this setup. To replicate just:
- open Explorer (
Win+E
)- drag the Explorer window to being horizontally larger than 1 screen
- lock workstation (
Win+L
), - unlock
- the application should now resize to being solely on 1 screen
How do I prevent Window resizing when the Workstation is Locked then Unlocked?
Will we need to code in checks for (un)locking?
Is there another mechanism we're not aware of?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在调整窗口大小之前,应用程序将获得 WM_WINDOWPOSCHANGING< /a> 来自 Windows 的消息。您可以拦截该消息并更改参数,强制窗口保持不变。您需要小心,因为当用户尝试移动或调整窗口大小时,您会收到相同的消息。也可能是在最大化或最小化时。
编辑:您可以使用 WTSRegisterSessionNotification 函数 获取附加消息。这些消息旨在实现快速用户切换,但锁定屏幕在 Windows 中作为系统会话实现。
Before the window is resized, the application will get a WM_WINDOWPOSCHANGING message from Windows. You can intercept that message and change the parameters, forcing the window to stay put. You need to be careful, because you'll get the same message when the user is trying to move or resize the window. Probably when it's maximized or minimized, too.
Edit: You can use the WTSRegisterSessionNotification function to get additional messages. The messages are intended for fast user switching, but the lock screen is implemented in Windows as a system session.
类似的问题有一个答案,允许您 在 .net 应用程序中恢复窗口大小会话解锁后。
有人在 SuperUser 上问了本质上相同的问题,但从用户的角度来看: 当我锁定工作站时如何阻止大窗口调整大小?
A similar question has an answer that allows you to restore window size in a .net application after the session is unlocked.
Someone asked essentially the same question on SuperUser, but from your user's perspective: How can I stop big windows from resizing when I lock my workstation?
我尝试了Leif引用的问题中给出的解决方案,发现
SessionSwitchReason.SessionUnlock
事件似乎是在计算机锁定之后而不是之前触发的。这意味着窗口大小和位置已经重置,因此调整大小失败。因此,我必须找到另一种方式来存储计算机被锁定之前的当前大小和位置。我唯一能做的就是订阅
ResizeEnd
用于 Winforms 应用程序,并更新其中的“预锁定”大小和位置。我还无法让它适用于 WPF 应用程序,因为 WPF 没有相当于
ResizeEnd
(或者我还没有找到它)并订阅SizeChanged
和LocationChanged
还不够好,因为它们会在计算机锁定时触发,并覆盖大小和位置。最后我不得不挂钩 Windows ExitSizeMove 事件来保存当前的大小和位置。有关如何参与此活动的详细信息,请访问此处:
I tried the solution given in the question referenced by Leif and found that the
SessionSwitchReason.SessionUnlock
event seemed to be fired after the computer had been locked rather than before. This meant that the window size and location had already been reset, so the resize failed.Therefore, I had to find another way of storing the current size and location before the computer was locked. The only thing I could see to do was to subscribe to the
ResizeEnd
for Winforms applications and update the "pre-lock" size and location there.I haven't been able to get it working for WPF applications yet, because WPF doesn't have the equivalent of
ResizeEnd
(or I haven't found it yet) and subscribing toSizeChanged
andLocationChanged
isn't good enough as these are fired when the computer is locked as well overwriting the size and location.In the end I had to hook into the Windows ExitSizeMove event to save the current size and position. Details of how to hook into this event can be found here: