窗口最大 最大化
我正在寻找创建一个程序,在其中我可以为所有窗口设置最大最大化尺寸(如按下最大化按钮时窗口最大化的尺寸)和最大化位置(最大化窗口的 X/Y 坐标)正在运行。这样我就可以在辅助显示器上随时显示雨量计,而无需手动调整每个窗口的大小。
我已经成功地为一个使用 WinAPI 中的 MINMAXSIZE 编写的简单程序做到了这一点。这种方法似乎非常适合我的小程序,但除了互联网上的 1 或 2 篇文章之外,关于它的文档很少。我想知道这是否是设置最大最大化大小的最佳方法,或者是否有其他方法可以做到这一点。
我计划将其实现到所有应用程序中的方式将是 DLL 注入或 Hook(我对这两种方法都没有任何经验),所以我也想知道你们对这些方法的想法。
我知道有一些应用程序已经做到了这一点,但我认为这可能是一次学习经历,而且我尝试过的所有应用程序都不能很好地工作(尽管所有应用程序都可能出现这种情况)由于 Windows 的运行方式)。
如果你们中的任何人仍然不确定我在说什么,MaxMax 正是我想要的(尽管它效果不太好,正如我在上一段中所述)。
预先感谢大家。
I am looking to create a program where I can set the maximum maximize size (as in the size the window maximises to when you hit the maximise button) and maximize position (X/Y coordinated for the maximised window) for all of the windows that are running. This is so that I can have my Rainmeter visible at all times on my secondary monitor without having to manually resize every window fit inside of it.
I have managed to do this for a simple program I wrote using MINMAXSIZE from the WinAPI. This method seems to work perfectly for my little program, but there is very little documentation on it beside 1 or 2 articles on the internet. I was wondering if this would be the best way to set the maximum maximise size, or if there is another way to do this.
They way I planned to implement this into all of the applications was going to be either DLL Injection or Hooks (neither of which I have any experience with), so I was also wondering your guys' thoughts on these methods.
I know there are a few applications out there that already do this, but I thought this could be a learning experience, and as well, all of the applications I tried do not work very well (although this could be the case with all of them due to the way Windows functions).
If any of you are still unsure about what I am talking about, MaxMax does exactly what I want (although it doesn't work so well, as I stated in my previous paragraph).
Thank you all in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能正在寻找的是工作区设置,您可以使用
SystemParametersInfo
函数,使用标志调用SPI_SETWORKAREA
/SPI_GETWORKAREA
。What you're probably looking for is the work area setting, that you can set/retrieve with the
SystemParametersInfo
function, called with the flagsSPI_SETWORKAREA
/SPI_GETWORKAREA
.您想要做的是使用全局 Windows 挂钩来处理 WM_GETMINMAXINFO。您可能知道,这条消息是:
使用它来覆盖默认最大值的最佳方法是填写 MINMAXINFO 结构如下:
在这种情况下,这将允许将默认值分配给您不关心的尺寸(最小 x/y),让您可以摆弄最大值如你所愿。您的 Windows 挂钩应使用 SetWindowsHookEx()< 完成/a> 并且应该看起来像这样:
hMod (instance_handle) 只能根据情况进行设置(请检查文档)。 dwThreadId 强制要求全局挂钩。您的 CallWndProc 可能看起来像这样:
不幸的是,您必须处理的是,唯一将被挂钩的窗口是您调用 SetWindowsHookEx() 时已经存在的窗口。我不知道有什么干净的方法可以解决这个问题,除了循环调用 SetWindowsHookEx() (呃!)。
您可以通过 DLL 注入来实现此目的,并使用 EnumWindows, EnumChildWindow 和 SetWindowLongPtr/设置窗口子类。但是,当您可以只使用 SetWindowsHookEx 时,为什么要这么麻烦呢? :)
要更改 x/y,您可能必须添加 WM_SYSCOMMAND 并检查 SC_MAXIMIZE 然后使用 SetWindowPos/MoveWindow正确定位它(如果您不希望它位于默认的 0, 0)。
What you want to do is use a global windows hook to handle WM_GETMINMAXINFO. As you may be aware, this is the message that is:
The best way to use this to override the default maximum is to fill in the MINMAXINFO structure like so:
This will allow the default values to be assigned to the sizes you don't care about (min x/y) in this case, leaving you to fiddle with the max values as you please. Your windows hook should be done with SetWindowsHookEx() and should look something like this:
hMod (instance_handle) should only be set depending on the circumstances (check the docs for this). The dwThreadId mandates a global hook. Your CallWndProc might looks something like this:
Unfortunately something you are going to have to deal with is that the only windows that will be hooked are the ones that had were existing when you made your call to SetWindowsHookEx(). I'm not aware of a clean way of getting past this, short of looping a call to SetWindowsHookEx() (ergh!).
You could potentially do this with DLL injection and effectively subclass every window with EnumWindows, EnumChildWindow and SetWindowLongPtr/SetWindowSubclass. But why go to all that trouble when you could just use SetWindowsHookEx? :)
To alter the x/y, you might have to add an override for WM_SYSCOMMAND and check for SC_MAXIMIZE then use SetWindowPos/MoveWindow to position it properly (if you don't want it on the default 0, 0).