Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set console window size and position

I would like to open multiple console programs on my desktop. This is what I have to do everytime: 1.Right click Desktop->Screen resolution->Detect (4 monitors). 2.Open 16 different console programs (4 per screen). 3.Clicking on all windows to get the Z-order correctly. 3.Right click Taskbar->Show Windows Stacked (to organize all 16 windows to perfect squares, 4 on each screen in order of z-index).

Is there a way to do even just a part of this programmatically to help this go quicker?

like image 636
TeamBreezy Avatar asked Feb 08 '16 06:02

TeamBreezy


1 Answers

You can use the windows API to move your console window. Use DllImport to declare the WinApi functions you want to use:

[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr GetConsoleWindow();

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

Then call them: e.g.

IntPtr ptr = GetConsoleWindow();
MoveWindow(ptr, 0, 0, 1000, 400, true);

You can use further WinApi function as SetWindowPos. You can find the DllImport syntax by searching the web for PInvoke and the name of the function. Follow the explanations there and in MSDN.

like image 93
Fratyx Avatar answered Sep 18 '22 00:09

Fratyx