locked
Could be a strange question, but something possible? RRS feed

  • Question

  • Hello,

    Let's say you created a Windows Form Application. If you look at the properties of that project, the output type should be Windows Application. Sometimes you set this output type temporarily to Console Application for Console debugging.

    You are going to see Console Window behind the form...

    My question is that...is there any nice way to hide programmatically this console window behind the form, right after starting the form application?...

    I can change the output type to Windows Application again, if I don't need that console window for debugging, but what I am looking for a way is to hide the Console Window behind the form in Console Application output type...

    Thanks,

    Friday, October 3, 2014 4:19 PM

Answers

  • Try adding two declarations to your form:

        [DllImport( "kernel32" )]
        static extern IntPtr GetConsoleWindow();

        [DllImport( "user32" )]
        static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );

    Then, in order to hide the console:

        ShowWindow( GetConsoleWindow(), 0);

    To restore:

        ShowWindow( GetConsoleWindow(), 4 );


    • Edited by Viorel_MVP Friday, October 3, 2014 6:38 PM
    • Marked as answer by Kristin Xie Tuesday, October 14, 2014 2:03 AM
    Friday, October 3, 2014 6:38 PM

All replies

  • Try adding two declarations to your form:

        [DllImport( "kernel32" )]
        static extern IntPtr GetConsoleWindow();

        [DllImport( "user32" )]
        static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );

    Then, in order to hide the console:

        ShowWindow( GetConsoleWindow(), 0);

    To restore:

        ShowWindow( GetConsoleWindow(), 4 );


    • Edited by Viorel_MVP Friday, October 3, 2014 6:38 PM
    • Marked as answer by Kristin Xie Tuesday, October 14, 2014 2:03 AM
    Friday, October 3, 2014 6:38 PM
  • Cool...There is GetConsoleWindow() ApI....I didn't know of it.

    Thanks a lot!

    Friday, October 3, 2014 6:44 PM