Farooque Khan

Farooque Khan

  • NA
  • 151
  • 38.7k

hide show process in c#

Dec 4 2015 5:32 AM
Im trying to make a show/hide window but no way to make work a show window when i hide it. I already read in many forums but no way to do it work, sone one can help???

private const int SW_HIDE = 0;
private const int SW_SHOW = 5;         
[DllImport("User32")]         
private static extern int ShowWindow(int hwnd, int nCmdShow);  
//WORKING         
private void button1_Click(object sender, EventArgs e)        
{             
   int hWnd;             
   Process[] processRunning = Process.GetProcesses();             
   foreach (Process pr in processRunning)             
   {                 
      if (pr.ProcessName == "notepad")                 
      {                     
         hWnd = pr.MainWindowHandle.ToInt32();                     
         ShowWindow(hWnd, SW_HIDE); 
       }             
   }
//NOT WORKING         
private void button2_Click(object sender, EventArgs e)         
{            
   int hWnd;            
   Process[] processRunning = Process.GetProcesses();             
   foreach (Process pr in processRunning)             
   {
      if (pr.ProcessName == "notepad")                 
      {
         hWnd = pr.MainWindowHandle.ToInt32();                
         ShowWindow(hWnd, SW_SHOW);
      }
   } 
}

Answers (1)