【问题标题】:Is it possible to set the MinimumSize property of another process' form? C#是否可以设置另一个进程表单的 MinimumSize 属性? C#
【发布时间】:2017-05-06 03:42:27
【问题描述】:

我希望我的程序使另一个进程的主窗体具有最小窗口大小。

我有正确的窗口句柄并尝试设置窗口的大小,如果它小于我想要的大小, 但这样一来,它就完全闪烁了。

MoveWindow() 让它闪烁太多, SetWindowPos() 以及


using System;
using System.Diagnostics;
using System.Windows.Forms;


namespace myProgram
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
      foreach (var process in Process.GetProcessesByName("myTarget"))
      {
        var handle = process.MainWindowHandle; // gets all instances of the target game
        // Something like SetWindowProperty(handle, MinimumSize, new Size(500, 500)) would be perfect
        // or: setting the size with
          // MoveWindow() - flashes horribly
          // SetWindowPos() - flashes horribly aswell
          // something else?
      }
    }
  }
}

我想要一个更流畅、不闪现或看起来不可怕的解决方案。

目标程序是一个游戏,具有相当大的窗口形式。

【问题讨论】:

  • 看来你的问题我不清楚。你有什么样品可以参考你需要的吗?
  • 您可能需要实现全局系统钩子,拦截并修改lParam中的WM_GETMINMAXINFO。我认为这仅在 C# 中是不可能的。
  • 请看这个Win32 GUI flickering on resize问题。

标签: c# .net winforms


【解决方案1】:

您正在寻找MoveWindow。看起来像:

[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool rePaint);

其中 hWnd 是您要调整大小的应用程序。

【讨论】:

  • 使用它会使我的目标闪烁,这是我不想要的。
猜你喜欢
  • 2014-12-28
  • 1970-01-01
  • 1970-01-01
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 2015-01-02
  • 2020-05-23
  • 1970-01-01
相关资源
最近更新 更多