Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Manage Window from a Process (Minimize, Maximize, Close...)

Manage Window from a Process (Minimize, Maximize, Close...)

Scheduled Pinned Locked Moved C#
questiontutorial
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    softwarejaeger
    wrote on last edited by
    #1

    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

    N J S 3 Replies Last reply
    0
    • S softwarejaeger

      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

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • S softwarejaeger

        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

        J Offline
        J Offline
        John Ad
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • S softwarejaeger

          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

          S Offline
          S Offline
          selcuks
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0
          • N N a v a n e e t h

            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

            S Offline
            S Offline
            softwarejaeger
            wrote on last edited by
            #5

            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:

            N 1 Reply Last reply
            0
            • S softwarejaeger

              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:

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • J John Ad

                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

                M Offline
                M Offline
                MehdiMousaviNezhad
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups