窗口最大 最大化

发布于 2024-12-02 18:19:24 字数 608 浏览 2 评论 0原文

我正在寻找创建一个程序,在其中我可以为所有窗口设置最大最大化尺寸(如按下最大化按钮时窗口最大化的尺寸)和最大化位置(最大化窗口的 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 技术交流群。

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

发布评论

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

评论(2

余生共白头 2024-12-09 18:19:24

您可能正在寻找的是工作区设置,您可以使用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 flags SPI_SETWORKAREA/SPI_GETWORKAREA.

情愿 2024-12-09 18:19:24

您想要做的是使用全局 Windows 挂钩来处理 WM_GETMINMAXINFO。您可能知道,这条消息是:

当窗口的大小或位置即将达到时发送到窗口
改变。应用程序可以使用此消息来覆盖窗口的
默认最大尺寸和位置,或其默认最小或最大
跟踪尺寸。

使用它来覆盖默认最大值的最佳方法是填写 MINMAXINFO 结构如下:

case WM_GETMINMAXINFO: {
  DefWindowProc(hWnd, message, wParam, lParam);
  MINMAXINFO* mmi = (MINMAXINFO*)lParam;
  mmi->ptMaxTrackSize.x = 100;
  mmi->ptMaxTrackSize.y = 100;
  return 0;
}

在这种情况下,这将允许将默认值分配给您不关心的尺寸(最小 x/y),让您可以摆弄最大值如你所愿。您的 Windows 挂钩应使用 SetWindowsHookEx()< 完成/a> 并且应该看起来像这样:

SetWindowsHookEx(WH_CALLWNDPROC, hook_procedure, instance_handle, 0);

hMod (instance_handle) 只能根据情况进行设置(请检查文档)。 dwThreadId 强制要求全局挂钩。您的 CallWndProc 可能看起来像这样:

__declspec(dllexport) LRESULT WINAPI CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
  CWPSTRUCT* cwp = (CWPSTRUCT*)lParam;
  if(WM_GETMINMAXINFO == cwp->message) {
    DefWindowProc(hWnd, message, wParam, lParam);
    MINMAXINFO* mmi = (MINMAXINFO*)lParam;
    mmi->ptMaxTrackSize.x = 100;
    mmi->ptMaxTrackSize.y = 100;
    return 0;
  }

  return CallNextHookEx(next_hook, nCode, wParam, lParam);
}

不幸的是,您必须处理的是,唯一将被挂钩的窗口是您调用 SetWindowsHookEx() 时已经存在的窗口。我不知道有什么干净的方法可以解决这个问题,除了循环调用 SetWindowsHookEx() (呃!)。

您可以通过 DLL 注入来实现此目的,并使用 EnumWindows, EnumChildWindowSetWindowLongPtr/设置窗口子类。但是,当您可以只使用 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:

Sent to a window when the size or position of the window is about to
change. An application can use this message to override the window's
default maximized size and position, or its default minimum or maximum
tracking size.

The best way to use this to override the default maximum is to fill in the MINMAXINFO structure like so:

case WM_GETMINMAXINFO: {
  DefWindowProc(hWnd, message, wParam, lParam);
  MINMAXINFO* mmi = (MINMAXINFO*)lParam;
  mmi->ptMaxTrackSize.x = 100;
  mmi->ptMaxTrackSize.y = 100;
  return 0;
}

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:

SetWindowsHookEx(WH_CALLWNDPROC, hook_procedure, instance_handle, 0);

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:

__declspec(dllexport) LRESULT WINAPI CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) {
  CWPSTRUCT* cwp = (CWPSTRUCT*)lParam;
  if(WM_GETMINMAXINFO == cwp->message) {
    DefWindowProc(hWnd, message, wParam, lParam);
    MINMAXINFO* mmi = (MINMAXINFO*)lParam;
    mmi->ptMaxTrackSize.x = 100;
    mmi->ptMaxTrackSize.y = 100;
    return 0;
  }

  return CallNextHookEx(next_hook, nCode, wParam, lParam);
}

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).

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