0

I want my program to make the main form of another process have a minimum window size.

I have the correct window handle and tried setting the size of the window if it is smaller than my wanted size, but this way it is totally flashing.

MoveWindow() makes it flash too much, SetWindowPos() aswell


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?
      }
    }
  }
}

I would like a solution which is smoother and doesn't flash or look horrible.

The target program is a game, with a sizeable windows form.

  • it seems that your question is not clear to me. do you have any sample where i can refer what you need? – Muj May 06 '17 at 04:05
  • you may need to implement global system hook, intercept and modify `lParam` in `WM_GETMINMAXINFO`. I don't think this is possible in C# alone. – bansi May 06 '17 at 04:51
  • please see this [Win32 GUI flickering on resize](http://stackoverflow.com/questions/2036599/win32-gui-flickering-on-resize) question.
    – Rainmaker May 06 '17 at 05:52

1 Answers1

0

You are looking for MoveWindow. Which looks like:

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

Where hWnd is the application you want to resize.

osumatu
  • 410
  • 1
  • 8
  • 25