如何调整窗口工作区域的大小,然后更新其他窗口以反映更改?
我有一个工具栏应用程序,它可以更改桌面的工作区域并将其自身定位在间隙中(在屏幕的顶部或底部)。我需要一个函数来调整其他窗口的大小,以便它们在调整大小后不会留在工具栏后面(工具栏始终位于顶部)。我正在使用下面的函数来更改工作区域:
private bool SetWorkspace(RECT rect)
{
bool result = SystemParametersInfo(SPI_SETWORKAREA,
0,
ref rect,
SPIF_change);
if (!result)
{
MessageBox.Show("The last error was: " +
Marshal.GetLastWin32Error().ToString());
}
this.minAll();
return result;
}
minAll() 函数是我调整其他窗口大小的方法:
public void minAll(){
IntPtr lHwnd = FindWindow("Shell_TrayWnd", null);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL, IntPtr.Zero);
System.Threading.Thread.Sleep(10);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL_UNDO, IntPtr.Zero);
System.Threading.Thread.Sleep(10);
}
此方法有效,因为工作区域确实会调整大小,并且没有窗口在其外部保留其旧位置,但存在一些问题:
- 正常(即未最大化或最小化)窗口有时会如此 小到无法显示,并且必须从 任务栏(Vista)可见
- 有时该方法使其他 窗口“总是在最上面”,而它们不应该是
- 它改变了窗口的 z 顺序,看起来是随机的
如果您关闭并重新打开受影响的窗口,前两个问题就可以解决,但这不是一个理想的解决方案,我甚至无法手动更正 z 顺序(我尝试在该方法之前保存 z 顺序,然后在之后恢复它,但没有运气)。
那么,任何人都可以看到我这样做有什么问题,或者有人知道应该如何完成吗?
I have a toolbar application which changes the work area of the desktop and positions itself in the gap (either at the top or bottom of the screen). I need a function which will resize the other windows so that they are not left behind the toolbar after the resizing (the toolbar is always on top). I'm using the function below to change the work area:
private bool SetWorkspace(RECT rect)
{
bool result = SystemParametersInfo(SPI_SETWORKAREA,
0,
ref rect,
SPIF_change);
if (!result)
{
MessageBox.Show("The last error was: " +
Marshal.GetLastWin32Error().ToString());
}
this.minAll();
return result;
}
and the minAll() function is how I'm resizing the other windows:
public void minAll(){
IntPtr lHwnd = FindWindow("Shell_TrayWnd", null);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL, IntPtr.Zero);
System.Threading.Thread.Sleep(10);
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL_UNDO, IntPtr.Zero);
System.Threading.Thread.Sleep(10);
}
This method works, in that the workarea does get resized and no window keeps its old position outside it, but there are a few problems:
- Normal (ie. not maximised or minimized) windows are sometimes made so
small that they aren't displayed, and have to be maximised from the
taskbar (Vista) to be visible - Sometimes the method makes other
windows 'always on top' when they shouldn't be - It changes the z-order of the windows, seemingly at random
The first two of these problems are fixed if you close and reopen the affected windows, but it's hardly an ideal solution and I can't even manually correct the z-order (I tried saving the z-order before the method and then restoring it afterwards, but no luck).
So, can anyone see what's wrong with how I'm doing this, or does anyone know how it's supposed to be done please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确的方法是创建一个 AppBar。请参阅SHAppBarMessage。 知识库中有一个 C++ 示例。 CodeProject 上有一个 C# 示例。
The correct way to do this is to create an AppBar. See
SHAppBarMessage
. There is a C++ sample in the Knowledge Base. There is a C# sample on CodeProject.