Windows gui with console


  • Discourse touched me in a no-no place

    @accalia said:

    what your console app can do after being launched is spin up a GUI and then detach from the console.

    Supposedly you can do the reverse, too, which is probably better because it doesn't create a spurious console.

    I haven't tried it, but maybe I will tomorrow on my day off.


  • FoxDev

    if you can do the reverse than that's VERY recent thing.

    i know that it was impossible on XP, although i'm not positive on the service packs as i wasn't working on that project anymore since the service packs hit and havent' wanted to do something like that since.

    however I will say with the removal of the GUI on server builds now a posiblity i would say the console => GUI route would be preferable because you can run the server completely headless


  • Discourse touched me in a no-no place

    @accalia said:

    i know that it was impossible on XP

    Given that the relevant functions say supported since[1] Windows 2000, I suspect you're wrong.

    [1] Everyone remembers what that means, right? Not when the function was introduced, but what is the earliers-currently-supported version of Windows that supports the function.


  • kills Dumbledore

    Ever heard of an installer?


  • FoxDev

    @FrostCat said:

    Not when the function was introduced, but what is the earliers-currently-supported version of Windows that supports the function.

    possibly was introduced after i looked at it then. as i said the last time i wanted it was for XP, not XPspAnything.... XP.

    if support was added in a service pack then it probably made it into the service packs for 2k as well, and MSDN documentation i find tends to assume you are up to date on your service packs.



  • Installers are an extra middleman that I don't need. Anyway, the installer would have to contain all the files, so that doesn't remove the "all the files embedded in one executable" thing.



  • Mmm, as much as I knock Java GUI apps for stuff, at least you can launch a java .jar file from either the command-line (via java) or by double-clicking through the GUI (runs javaw) and it either has a console or doesn't depending on how it was launched. You can launch GUI windows from it either way.

    Edit: Of course, you should make sure you can even create GUI windows before trying it. java.awt.GraphicsEnvironment.isHeadless() will return true if there's no GUI.


  • Discourse touched me in a no-no place

    Try starting a java app via javaw.exe some time and watch what happens.



  • Try starting a Java app on any OS other than Windows with javaw.

    Oh wait, javaw is only needed for Windows because it's a Windows-specific kludge.



  • @ben_lubar said:

    The only OS that has problems displaying a GUI and still allowing stdout/stderr to write to the console that started the program is Windows.

    Look, I just gave you the answer. AttachConsole(ATTACH_PARENT_PROCESS) when you want to re-use the parent console in a GUI app, AllocConsole() when you don't.have a console but want one. Do it before displaying a GUI.

    How hard is that?



  • If you're not starting an app that launches a new process for winform, launches a new process for console app, and then issues a waitone -- and the GUI form and console talk via named pipes...

    You're doing it wrong.

    Or something.



  • Ironically, my solution (+ or -) the named pipes would actually work for you here.


  • Discourse touched me in a no-no place

    @antiquarian said:

    I was about to ask if you were still going for a TRWTF badge, then I looked at the badges page and saw that there isn't one.

    http://what.thedailywtf.com/badges/107/worst-of-the-worst is close...



  • @blakeyrat said:

    It really depends on whether SSH/the text terminal supports only ASCII or the ANSI cursor and color extensions. (And also whether there's ANSI cursor and color extensions are standard between Windows and Linux, I don't know honestly.)
    I could be wrong, but I think that the Windows terminal program does things like set colors out-of-channel: i.e. rather than embed escapes that change the color inline in the output, the program makes a separate API call to set the color. But I also don't fully understand the interaction between the portable C runtime and the console APIs in Win32.



  • @EvanED said:

    I could be wrong, but I think that the Windows terminal program does things like set colors out-of-channel: i.e. rather than embed escapes that change the color inline in the output, the program makes a separate API call to set the color

    You can do all kinds of weird shit in Windows terminal. Once you're using WinAPI anyway, it's basically just another GDI window.

    namespace ConsoleApplication12
    {
    class Program
    {
    
        [DllImport("gdi32.dll")]
        private extern static int SetPixel(int hdc, int x, int y, int color);
    
        [DllImport("kernel32.dll")]
        private extern static int GetConsoleWindow();
    
        [DllImport("user32.dll")]
        private extern static int GetDC(int i);
    
        static void Main(string[] args)
        {
            int myCon = GetConsoleWindow();
            int myDC = GetDC(myCon);
            for (int i = 50; i < 150; i++)
            {
                for (int j = 50; j < 150; j++)
                {
                    if (i == 50 || i == 149 || j == 50 || j == 149)
                        SetPixel(myDC, i, j, 255*256*256 + 255*256 + 255);
                }
            }
            Console.ReadLine();
        }
    }
    }
    

    (yep, in C# for greater WTFness).



  • @Maciejasjmj said:

    255256256 + 255*256 + 255

    Amazing how C# doesn't have hexadecimal literals.



  • @ben_lubar said:

    Amazing how C# doesn't have hexadecimal literals.

    You assume I was willing to sacrifice 3 seconds it would take me to remember that it has.


  • Discourse touched me in a no-no place

    @Maciejasjmj said:

    ben_lubar:
    Amazing how C# doesn't have hexadecimal literals.

    You assume I was willing to sacrifice 3 seconds it would take me to remember that it has.

    Why would you use those when you can use 256 << 16?


  • Discourse touched me in a no-no place

    @blakeyrat said:

    It really depends on whether SSH/the text terminal supports only ASCII or the ANSI cursor and color extensions. (And also whether there's ANSI cursor and color extensions are standard between Windows and Linux, I don't know honestly.)

    It depends on what terminal is being emulated (which might or might not be determined by the SSH client; PuTTY is also a terminal emulator, whereas Unix ssh clients leave that up to their calling environment to determine). Almost everything goes with emulating the extended VT100 these days. Because almost everything supports that and it does what people want.

    No idea how we ended up with that one picked. Probably a chance or convenient-default-in-a-common-program thing.
    @blakeyrat said:

    If so, it's possible to create a GUI in a terminal window. If not, you can do... stuff, but I don't think you could do anything I'd consider a "GUI".

    Back in the later days of Turbo Pascal (which I retain a soft spot for), just before Windows gobbled up DOS completely, there were quite a few programs doing effectively-GUI IDEs with just a terminal-like thing to drive it. Windows, dialogs, all that stuff (except for showing pictures).

    Everything worked well, unless some code overwrote the character shapes used by the hardware, when it became just a bit confusing. 😉



  • The really elegant way to write it would be (1 << 24) - 1
    256 << 16 is @OffByOne.


  • ♿ (Parody)

    @accalia said:

    With windows, you can either have a console or not, that's decided at app compile time. so your choices are either full GUI with no console or a console app with optional GUI.

    You can create a console from a GUI app in windows. However, that will be a different console in the case where the program is launched from a console.

    Start with AllocConsole().



  • @boomzilla said:

    You can create a console from a GUI app in windows. However, that will be a different console in the case where the program is launched from a console.

    You could try an AttachConsole() to your parent's console and check the error codes to determine what happens next...


  • ♿ (Parody)

    @tarunik said:

    You could try an AttachConsole() to your parent's console and check the error codes to determine what happens next...

    Yeah...I've never tried doing that, and hadn't read through the whole thread before seeing that had already been suggested. Catching up is hard.


Log in to reply