![]() Public static extern bool SetFocus(IntPtr hWnd) Launching applications and input parameters Public static extern bool ShowWindow(IntPtr hWnd, int X) The really interesting thing about this, is that it allows us to move the window to the position we would like with any size, so we can take advantage of it in order to set any number of windows, being these equally distributed.įinally we need a couple of additional calls to Windows API functions to maximize the window before moving it, and to set the focus, which are imported in a similar way: These are found within the namespace, which requires in addition a reference as System.Drawing from our project. IntPtr handle = proc.P: įor moving the window, we need to set an origin and a size, and for this we could either fix them manually, or rely on the resolution of the screen, using the following functions: foreach (Process proc in Process.GetProcesses () There are many ways to locate it, and one of them is from the list of processes, selecting those whose main window matched with what was looking for, in this case “Visual Studio”. To be able to move the window, we need its hWnd, which is a unique window identifier. We will have to repeat this process for each function that we want to import, a we will also need to add the following using: using Public static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint) To use the Windows API functions we have to copy their header in our function, define it as external (.NET framework will already know what to do) and define the DLL from which we import, in this case the function MoveWindow is located in user32.dll: It was not too complex, but I chose to do a small application with C# so that it could solve the problem, using native calls to the Windows API through P/Invoke: Importing functions and moving windows Top, $width + $dx, $height + $dy, $true ) In fact, in the following entry of TechNet Provide Input to Applications with PowerShellexplains how to send commands to an application using SendKeys, resulting in the following code: add-type -AssemblyName microsoft.VisualBasicĪdd-type -AssemblyName Theorically, we can solve this by using Powershell. It seemed simple, I would only need to emulate this key combination, something that it seemed easy to do: If we have Windows 7 or higher we can make use of Aero Snap, using Win+Left or Win+Right, it sets a window to the left or to the right of the screen. So I set out to find the way of solving this small issue. This requires opening 2 different instances of visual studio by hand, and attach each side of the screen, something tedious, boring, and, above all, automatable. When we test VS Anywhere in a production environment, one of the things that we tend to do is to open 2 sessions of Visual Studio on either side of the screen, so we can make quick tests of specific features.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |