当工作站锁定然后解锁时,如何防止窗口大小调整?

发布于 2024-08-14 01:15:16 字数 493 浏览 2 评论 0原文

我们有一个在多显示器环境中运行的应用程序。用户通常将应用程序对话框分散到多个监视器上。

如果用户锁定工作站,然后解锁它,我们的应用程序就会被告知调整大小。

我们的用户发现这种行为令人沮丧,因为他们随后花了一些时间恢复以前的布局。

我们还不确定是图形驱动程序请求调整大小还是 Windows。希望通过这个问题,可以更清楚哪个组件负责,

(文件)资源管理器和 Firefox 等流行应用程序在此设置中的行为方式相同。只需复制:

  1. 打开资源管理器 (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:

  1. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伴随着你 2024-08-21 01:15:16

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.

枫林﹌晚霞¤ 2024-08-21 01:15:16

类似的问题有一个答案,允许您 在 .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?

我的鱼塘能养鲲 2024-08-21 01:15:16

我尝试了Leif引用的问题中给出的解决方案,发现SessionSwitchReason.SessionUnlock 事件似乎是在计算机锁定之后而不是之前触发的。这意味着窗口大小和位置已经重置,因此调整大小失败。

因此,我必须找到另一种方式来存储计算机被锁定之前的当前大小和位置。我唯一能做的就是订阅 ResizeEnd 用于 Winforms 应用程序,并更新其中的“预锁定”大小和位置。

我还无法让它适用于 WPF 应用程序,因为 WPF 没有相当于 ResizeEnd(或者我还没有找到它)并订阅 SizeChangedLocationChanged 还不够好,因为它们会在计算机锁定时触发,并覆盖大小和位置。

最后我不得不挂钩 Windows ExitSizeMove 事件来保存当前的大小和位置。有关如何参与此活动的详细信息,请访问此处

private const int WM_EXITSIZEMOVE = 0x232;

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
    source.AddHook(new HwndSourceHook(WndProc));
}

private IntPtr WndProc(IntPtr hwnd, int msg,
                       IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == WM_EXITSIZEMOVE)
    {
        // save location and size of window

        handled = true;
    }

    return IntPtr.Zero;
}

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 to SizeChanged and LocationChanged 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:

private const int WM_EXITSIZEMOVE = 0x232;

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
    source.AddHook(new HwndSourceHook(WndProc));
}

private IntPtr WndProc(IntPtr hwnd, int msg,
                       IntPtr wParam, IntPtr lParam, ref bool handled)
{
    if (msg == WM_EXITSIZEMOVE)
    {
        // save location and size of window

        handled = true;
    }

    return IntPtr.Zero;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文