How to Change Another Program's Window's Size

How do I change another program's window's size?

You can use MoveWindow (Where hWnd is the window you want to move):

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

MoveWindow(ApplicationHandle, 600, 600, 600, 600, true);

If you don't know the window pointer, you can use the FindWindow functionality.

Also worth a read is MSDN SetWindowPos (Very similar to MoveWindow).

Resize other window or application c#

If you want the window to have a size of 1280x720 then use that size in the MoveWindow call.

  MoveWindow(handle, Rect.left, Rect.top, 1280, 720, true);

How to change the window size after the program starts?

Firstly, window.winfo_geometry() will give you the geometry of the window.

For getting width only, use window.winfo_width().

For getting height only, use window.winfo_height()

e.g.

if window.winfo_width() > 520 :
window.geometry('520x300')

Now, since you are using window.resizable(0,1), you are disabling the window's width to be resized, so windows's width will be fixed to 520.
So, how will it exceed 520, if it's not resizable?
If you enable it, and then want window's width to not exceed 520:

Tkinter offers .maxsize() and .minsize() to fix the size of the root window.

e.g. if you want that the window's width to not exceed 520, then just set the width in maxsize as 520.

window.geometry('520x300')
window.maxsize(520, 300)

The window's width will not be resized more than 520 now.


In case, you want to resize according to the user's screen's size:

To get the screen size, you can use winfo_screenwidth() which returns the screen width and winfo_screenheight() for the height of the screen in pixels.

window.geometry() can be recalled if needed.


EDIT: An example of recalling window.geometry() after the start of program(, even after resizing is disabled horizontally):

def resizeScreen():
window.geometry('520x300')

b = Button(window, text="RESIZE", command=resizeScreen)
b.pack()

Whenever this button is clicked, the screen will be resized, from what it is currently.
You can call this same function without using a button, by just calling the function. It depends on your code, how you use it.

Change Existing Window Size & Position

FindWindow (user32) Reference (Pinvoke.net)

Perhaps the alternative text at the top of the page would be simpler:

If you need to find windows for a given process ID, try
using EnumWindows in combination with
GetWindowThreadProcessId.

To implement the above, try using the Process.GetProcessesByName Method

Once you're able to obtain a reference to the Window, this link may help you remove its borders.

Moving the location and changing size of a external program

You can use the MoveWindow API

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

MoveWindow(ApplicationHandle, 600, 600, 600, 600, True);

How to change window size in C++?

That function is useless for console applications, which don't own a window (unless they create one using the CreateWindow API, which is atypical for console apps). Instead their output is connected to csrss, which does have windows.

You should be using

  • SetConsoleScreenBufferSize
  • SetConsoleWindowInfo

instead.

There's an example at http://www.cplusplus.com/forum/windows/10731/



Related Topics



Leave a reply



Submit