I'm trying to make a program that can hide a process that is running, and then restore it for you.

I can successfully Hide the window using

private const int SW_HIDE = 0;
        private const int SW_RESTORE = 9;
         [DllImport("User32")]
        private static extern int ShowWindow(int hwnd, int nCmdShow);

        private void btnLogonServerHide_Click(object sender, EventArgs e)
        {
            int hWnd;
            Process[] processRunning = Process.GetProcesses();
            foreach (Process pr in processRunning)
            {
                if (pr.ProcessName == "logonserver")
                {
                    hWnd = pr.MainWindowHandle.ToInt32();
                    ShowWindow(hWnd, SW_HIDE);
                }
            }
        }

But when i try

private void btnLogonServerShow_Click(object sender, EventArgs e)
        {
            int hWnd;
            Process[] processRunning = Process.GetProcesses();
            foreach (Process pr in processRunning)
            {
                if (pr.ProcessName == "logonserver")
                {
                    hWnd = pr.MainWindowHandle.ToInt32();
                    ShowWindow(hWnd, SW_RESTORE);
                }
            }
        }

It doesn't do anything.

Any help would be appreciated!

Thanks,

Sipex

When you're hiding the window you can't find it anymore on your controlbar... use other controls.. here's the full list:

private const int SW_HIDE = 0;
private const int SW_SHOWNORMAL = 1;
private const int SW_NORMAL = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private const int SW_MAXIMIZE = 3;
private const int SW_SHOWNOACTIVATE = 4;
private const int SW_SHOW = 5;
private const int SW_MINIMIZE = 6;
private const int SW_SHOWMINNOACTIVE = 7;
private const int SW_SHOWNA = 8;
private const int SW_RESTORE = 9;
private const int SW_SHOWDEFAULT = 10;
private const int SW_FORCEMINIMIZE = 11;
private const int SW_MAX = 11;

Hope this helps for you.

I'm trying to make a program that can hide a process that is running, and then restore it for you.

I can successfully Hide the window using

private const int SW_HIDE = 0;
        private const int SW_RESTORE = 9;
         [DllImport("User32")]
        private static extern int ShowWindow(int hwnd, int nCmdShow);

        private void btnLogonServerHide_Click(object sender, EventArgs e)
        {
            int hWnd;
            Process[] processRunning = Process.GetProcesses();
            foreach (Process pr in processRunning)
            {
                if (pr.ProcessName == "logonserver")
                {
                    hWnd = pr.MainWindowHandle.ToInt32();
                    ShowWindow(hWnd, SW_HIDE);
                }
            }
        }

But when i try

private void btnLogonServerShow_Click(object sender, EventArgs e)
        {
            int hWnd;
            Process[] processRunning = Process.GetProcesses();
            foreach (Process pr in processRunning)
            {
                if (pr.ProcessName == "logonserver")
                {
                    hWnd = pr.MainWindowHandle.ToInt32();
                    ShowWindow(hWnd, SW_RESTORE);
                }
            }
        }

It doesn't do anything.

Any help would be appreciated!

Thanks,

Sipex

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.