#229 WinForms


I was just doing some PowerShell scripting and I noticed that Console (version 2.00.138) doesn't seem to support the use of WinForms. The form will run, but will be invisible (and unavailable). The same script run in a normal console window works correctly.

Other GUI-based applications I've looked at so far seem to start just fine from Console, under any shell (I mostly use CMD and PowerShell.)


  • Nobody/Anonymous

    Logged In: NO

    I had the same problem in my own powershell scripts. From looking through the source code for Console, this would be a non trivial fix due to the fact that Console has to execute the shell executable with at least CREATE_NEW_CONSOLE, and therefore also the SW_HIDE flag. This is setting the default show state for all windows in the shell process to be hidden, which is what we are seeing here.

    However, I did find a workaround: have the window call ShowWindow(SW_SHOW) instead of ShowWindow(SW_SHOWDEFAULT). For a WinForm in powershell (or any other .net language, even) you have toggle the visible status of the form to get it to call ShowWindow again (it caches it's visible status)... so it would be something like: $Form.Visible = $false; $Form.Visible = $true

    Marty Disibio

  • Marko Bozikovic

    Marko Bozikovic - 2008-08-15

    Logged In: YES
    Originator: NO

    This is fixed in the next build.

    As 'nobody' said, the problem was with the default SW_ value Console was starting its child processes. If a grandchild process uses SW_SHOWDEFAULT flag for showing its window, it will use SW_HIDE flag and its window will be hidden on startup.

    Console's child windows are now started with SW_SHOW flag, but are created off-screen, so you will se just a quick flash of its taskbar button. There is no perfect solution, but this looks better since it eliminates invisible windows :)

  • Marko Bozikovic

    Marko Bozikovic - 2008-08-15
    • status: open --> closed

Log in to post a comment.