Basu Biswas

Basu Biswas

  • NA
  • 55
  • 0

How to get the caption of Console window..(Hiding console window)

Apr 9 2007 3:51 AM

Hi,

I want to hide the console window as i m running a windows service in background.

after searching a lot in google i found this code....

 

using System.Runtime.InteropServices;

 

...

      [DllImport("user32.dll")]

      public static extern IntPtr FindWindow(string lpClassName,string lpWindowName);

 

      [DllImport("user32.dll")]

      static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

 

...

 

         //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under.

         IntPtr hWnd = FindWindow(null, "Your console windows caption"); //put your console window caption here

         if(hWnd != IntPtr.Zero)

         {

            //Hide the window

            ShowWindow(hWnd, 0); // 0 = SW_HIDE

         }

 

                 

         if(hWnd != IntPtr.Zero)

         {

            //Show window again

            ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA

         }

In this code the line

  IntPtr hWnd = FindWindow(null, "Your console windows caption");

wants "Console window caption" ..from where i can get console window caption...

if possible do help...or else is there any other way to hide the console window as I am not sure where the above code gonna work ??

 


Answers (1)