Manage Window from a Process (Minimize, Maximize, Close...)
-
Hello, how can i minimize, maximaze, show, hide or close a Window from a Process? I know how to list all Processes, or the Processes which have a MainWindow, but how can i access that Window and do something with it? Thanks
-
Hello, how can i minimize, maximaze, show, hide or close a Window from a Process? I know how to list all Processes, or the Processes which have a MainWindow, but how can i access that Window and do something with it? Thanks
softwarejaeger wrote:
how can i minimize, maximaze, show, hide or close a Window from a Process?
P-Invoke ? If you have the window handle, you can use SetWindowPlacement[^] function to set minimize, maximized or restored states.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hello, how can i minimize, maximaze, show, hide or close a Window from a Process? I know how to list all Processes, or the Processes which have a MainWindow, but how can i access that Window and do something with it? Thanks
Hi, Set WindowState property of your form to FormWindowState.Maximized or FormWindowState.Minimized for maximizing and minimizing the Form. Refer to this [^] To Show/Hide and Close the form, use use Form.Hide/Close/Show. E.g. to show the current form, use this.Show() I hope this would be helpful.
John Adams ComponentOne LLC. www.componentone.com
-
Hello, how can i minimize, maximaze, show, hide or close a Window from a Process? I know how to list all Processes, or the Processes which have a MainWindow, but how can i access that Window and do something with it? Thanks
Importing user32.dll and using ShowWindow function with window handle is another solution: Here is a piece code u may use:
// Import User32.dll for windowing operations:
[System.Runtime.InteropServices.DllImport("User32.dll")]
static extern long ShowWindow(int windowHandle, int nCmdShow);private const int SM_SHOWMAXIMIZED = 3;
private const int SM_SHOWMINIMIZED = 2;Always keep the Murphy Rules in mind!
-
softwarejaeger wrote:
how can i minimize, maximaze, show, hide or close a Window from a Process?
P-Invoke ? If you have the window handle, you can use SetWindowPlacement[^] function to set minimize, maximized or restored states.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
OK, thanks but... how do i use this in c#? i get everytime a lot of errors
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
struct WINDOWPLACEMENT
{
internal int Length;
internal int flags;
internal int showCmd;
internal System.Drawing.Point ptMinPosition;
internal System.Drawing.Point ptMaxPosition;
internal System.Drawing.Rectangle rcNormalPosition;
}
[DllImport("user32")]
public static extern int SetWindowPlacement(int hwnd, ref WINDOWPLACEMENT lpwndpl);public class TestClass
{
}The Debugger told me, that in the line
public static extern int
a class,delegate or something else is expected, it underlines me the "int"... what to do? And when i delete the int it told me that "extern" isn't valid for this item... :confused: -
OK, thanks but... how do i use this in c#? i get everytime a lot of errors
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential)]
struct WINDOWPLACEMENT
{
internal int Length;
internal int flags;
internal int showCmd;
internal System.Drawing.Point ptMinPosition;
internal System.Drawing.Point ptMaxPosition;
internal System.Drawing.Rectangle rcNormalPosition;
}
[DllImport("user32")]
public static extern int SetWindowPlacement(int hwnd, ref WINDOWPLACEMENT lpwndpl);public class TestClass
{
}The Debugger told me, that in the line
public static extern int
a class,delegate or something else is expected, it underlines me the "int"... what to do? And when i delete the int it told me that "extern" isn't valid for this item... :confused:Check it in Pinvoke.net 1 - http://www.pinvoke.net/default.aspx/Structures/WINDOWPLACEMENT.html[^] 2 - http://www.pinvoke.net/default.aspx/user32/SetWindowPlacement.html[^] The page says another open source develoment which has ported some win32 APIs to managed functions has this function included. Check that too.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hi, Set WindowState property of your form to FormWindowState.Maximized or FormWindowState.Minimized for maximizing and minimizing the Form. Refer to this [^] To Show/Hide and Close the form, use use Form.Hide/Close/Show. E.g. to show the current form, use this.Show() I hope this would be helpful.
John Adams ComponentOne LLC. www.componentone.com
hi this is about process not about Forms I see A Code Snippet in vs.net 2008 about this but Not remember that code tanx