Thread: Console boxes

  1. #1
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11

    Console boxes

    (asthetics) I know it can be done easily with a windows project, but how can you make a program invisible? even without iostream header file, the console box still appears. Any way to make it go away?
    Behind me lies another fallen soldier...

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    On the Win32 platform, one solution is to design the process as a service.

    Kuphryn

  3. #3
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    bool HideConsoleWindow()
    {
        char title[MAX_PATH];
        HWND hwnd;
    
        // NOTE: if you have 2000/XP and latest Platform SDK, then you can simply 
        //       call GetConsoleWindow() and pass that to ShowWindow()
        
        if (GetConsoleTitleA(title, sizeof(title))      &&
            ((hwnd = FindWindowA(NULL, title)) != NULL) &&
            ShowWindow(hwnd, SW_HIDE))
        {
            return true;        
        }//if
    
        return false;
    }//HideConsoleWindow
    
    int main()
    {
        if (HideConsoleWindow())
            MessageBoxA(NULL, "You can't see me!", "<Nelson>:Ha-Ha", MB_OK);
        else
            cout << "Didn't work, ec = " << GetLastError() << endl;
    
        return 0;
    }//main
    Or start the console application using this:
    Code:
    bool StartAppHidden(char *command)
    {
        PROCESS_INFORMATION ProcInfo = {0};
        STARTUPINFO si = {0};
    
        si.cb = sizeof(STARTUPINFO);
        si.dwFlags = STARTF_USESHOWWINDOW;
        si.wShowWindow = SW_HIDE;
    
        BOOL bSuccess;
        bSuccess = CreateProcessA(NULL, command, NULL, NULL, FALSE, 0, NULL, NULL, 
                                  &si, &ProcInfo); 
        if (!bSuccess)
            return false;
    
        CloseHandle(ProcInfo.hThread);
        CloseHandle(ProcInfo.hProcess);
    
        return true;
    }//StartAppHidden
    gg

  4. #4
    Banned
    Join Date
    May 2004
    Posts
    55
    There is an easy answer, if you are using Dev-C++ go to "Linker" and write Yes instead of No on the "Make a console window"

  5. #5
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Quote Originally Posted by Bomber_nuke88
    (asthetics) I know it can be done easily with a windows project...
    He knows.

    gg

  6. #6
    Authorized Technician
    Join Date
    Jul 2004
    Posts
    11
    It makes sense if it's impossible, MS-DOS doesn't have multitasking capabilities, and what I really want to do is make a simple program have no console box. Yea, I am using Dev-C++, and I already did the windows deal. But whenever I include Windows.h my compile time doubles, but I guess I'll just make it winapp.
    Behind me lies another fallen soldier...

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> ...MS-DOS doesn't have multitasking capabilities...
    Dev-C++ creates 32bit console applications will all the capabilities of 32bit GUI applications. The only difference is that the OS creates a console window for you and hooks up standard input and standard output to that window.
    Any technique you use will require windows.h, so you might as well do it the WinMain() way.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Really hard recursion with boxes, help?
    By aciarlillo in forum C++ Programming
    Replies: 3
    Last Post: 10-13-2005, 07:22 AM
  2. Full Screen Console
    By St0rmTroop3er in forum C++ Programming
    Replies: 1
    Last Post: 09-26-2005, 09:59 PM
  3. Problems with a simple console game
    By DZeek in forum C++ Programming
    Replies: 9
    Last Post: 03-06-2005, 02:02 PM
  4. Console Functions Help
    By Artist_of_dream in forum C++ Programming
    Replies: 9
    Last Post: 12-04-2004, 03:44 AM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 10:19 AM