Computer Science Canada

hide the dos window

Author:  Geminias [ Sun Nov 20, 2005 8:17 pm ]
Post subject:  hide the dos window

pls tell me there is an easy way to get rid of the dos window.. i mean i'm making a window with winAPI and this stupid dos window shows in the back round all the time.

Author:  wtd [ Sun Nov 20, 2005 8:19 pm ]
Post subject: 

Are you using an IDE?

Author:  Geminias [ Sun Nov 20, 2005 8:29 pm ]
Post subject: 

yeah dev c++

my fingers were getting sore from all the command line typing i had to do with mingw. dev c++ is a much more friendly way to go when you're constantly testing little programs.

Author:  wtd [ Sun Nov 20, 2005 8:31 pm ]
Post subject: 

Here's an idea... find the executable Dev-C++ created, if you can, and double-click it.

Author:  Geminias [ Sun Nov 20, 2005 8:37 pm ]
Post subject: 

did you misunderstand me or am i misunderstanding you? that is the question twirling through my brain.

you've seen me post here often enough to know that i certainly know how to run a compiled program. so i hope that isn't what you thought i was asking.

just because i am not an experienced programmer does not mean i am an idiot... but you already know that right? then why treat me like i was born yesterday? maybe you shouldn't help people if it annoys you?

Now for the question:

i use the windows.h preprocessor and winmain() instead of main.. i make my window and it shows up fine, but behind it there is a dos window, is there a way to remove it?

i dont like it there, it looks unprofessional to me.

Author:  wtd [ Sun Nov 20, 2005 9:02 pm ]
Post subject: 

My thinking was that the window was there because the executable was launched via the IDE, which was spawning that to show error output.

Author:  Geminias [ Sun Nov 20, 2005 9:11 pm ]
Post subject: 

hmm, no after my post i checked it by running the .exe but i had no luck. the console window still appeared behind it. Crying or Very sad

i will likely have to resort to CreateProcess() and make it run silent.. unless you know of a better way?

Author:  wtd [ Sun Nov 20, 2005 9:16 pm ]
Post subject: 

Trying to find something, though it's not easy considering how convoluted Microsoft's documentation is.

As for the IDE thing... I just like to rule out the simple stuff first.

Author:  Geminias [ Sun Nov 20, 2005 9:18 pm ]
Post subject: 

yeah i always do a google and search around before i ask any questions here. I understand you're a linux man, but if you find anything let me know.

Author:  wtd [ Sun Nov 20, 2005 9:20 pm ]
Post subject: 

Can I see your code? I'm seeing an "int nCmdShow" arg to WinMain that looks like it might relate to this issue.

Author:  Geminias [ Sun Nov 20, 2005 9:28 pm ]
Post subject: 

I thought that also. It looks a lot like "show command" lol, which was the first thing i went after.

heres a link which should dissuade you from that line of thought.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/showwindow.asp[/code]

Author:  wtd [ Sun Nov 20, 2005 9:36 pm ]
Post subject: 

What happens with this sample?

code:
#include <windows.h>

const char *ClsName = "BasicApp";
const char *WndName = "A Simple Window";

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT uMsg,
                           WPARAM wParam, LPARAM lParam);

INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
               LPSTR lpCmdLine, int nCmdShow)
{
        MSG        Msg;
        HWND       hWnd;
        WNDCLASSEX WndClsEx;

        // Create the application window
        WndClsEx.cbSize        = sizeof(WNDCLASSEX);
        WndClsEx.style         = CS_HREDRAW | CS_VREDRAW;
        WndClsEx.lpfnWndProc   = WndProcedure;
        WndClsEx.cbClsExtra    = 0;
        WndClsEx.cbWndExtra    = 0;
        WndClsEx.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
        WndClsEx.hCursor       = LoadCursor(NULL, IDC_ARROW);
        WndClsEx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
        WndClsEx.lpszMenuName  = NULL;
        WndClsEx.lpszClassName = ClsName;
        WndClsEx.hInstance     = hInstance;
        WndClsEx.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

        // Register the application
        RegisterClassEx(&WndClsEx);

        // Create the window object
        hWnd = CreateWindow(ClsName,
                          WndName,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
       
        // Find out if the window was created
        if( !hWnd ) // If the window was not created,
                return 0; // stop the application

        // Display the window to the user
        ShowWindow(hWnd, SW_SHOWNORMAL);
        UpdateWindow(hWnd);

        // Decode and treat the messages
        // as long as the application is running
        while( GetMessage(&Msg, NULL, 0, 0) )
        {
             TranslateMessage(&Msg);
             DispatchMessage(&Msg);
        }

        return Msg.wParam;
}

LRESULT CALLBACK WndProcedure(HWND hWnd, UINT Msg,
                           WPARAM wParam, LPARAM lParam)
{
    switch(Msg)
    {
    // If the user wants to close the application
    case WM_DESTROY:
        // then close it
        PostQuitMessage(WM_QUIT);
        break;
    default:
        // Process the left-over messages
        return DefWindowProc(hWnd, Msg, wParam, lParam);
    }
    // If something was not done, let it go
    return 0;
}

Author:  Geminias [ Sun Nov 20, 2005 10:17 pm ]
Post subject: 

linker error, and i can't do anything about that since i dont know how to make dll's and link them and stuff

Author:  wtd [ Sun Nov 20, 2005 10:25 pm ]
Post subject: 

So, C# is a decent language. Smile

Author:  md [ Sun Nov 20, 2005 10:27 pm ]
Post subject: 

a linker error doesn't mean you need to make dlls, it just means you need to link against the right libraries. Unfortunately I don't know what they would be... but I know that they exist and that msdn should tell you what they are.

Author:  Geminias [ Mon Nov 21, 2005 12:40 am ]
Post subject: 

yeah, i guess thats true cornflake.

oh well, if anyone stumbles across how to make the program run without a dos window that would be helpful.

Author:  Geminias [ Mon Nov 21, 2005 1:34 am ]
Post subject: 

hey wtd.. i found a "tutorial" about making the dos window invisible.

i can't make much sense of it though... i dont know if its either a really bad tutorial or if i'm just not advanced enough yet to put it to use.

i can't get the source it provides to work either.

<a href="http://www.codeproject.com/win32/runsilent.asp#xx229599xx">Vist it here</a>

ps. no i did not try to run it exactly as it appears here.

c++:

DWORD RunSilent(char* strFunct, char* strstrParams)
{
        STARTUPINFO StartupInfo;
        PROCESS_INFORMATION ProcessInfo;
        char Args[4096];
        char *pEnvCMD = NULL;
        char *pDefaultCMD = "CMD.EXE";
        ULONG rc;
       
        memset(&StartupInfo, 0, sizeof(StartupInfo));
        StartupInfo.cb = sizeof(STARTUPINFO);
        StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
        StartupInfo.wShowWindow = SW_HIDE;

        Args[0] = 0;

        pEnvCMD = getenv("COMSPEC");

        if(pEnvCMD){
               
                strcpy(Args, pEnvCMD);
        }
        else{
                strcpy(Args, pDefaultCMD);
        }

        // "/c" option - Do the command then terminate the command window
        strcat(Args, " /c ");
        //the application you would like to run from the command window
        strcat(Args, strFunct)
        strcat(Args, " ");
        //the parameters passed to the application being run from the command window.
        strcat(Args, strstrParams);

        if (!CreateProcess( NULL, Args, NULL, NULL, FALSE,
                CREATE_NEW_CONSOLE,
                NULL,
                NULL,
                &StartupInfo,
                &ProcessInfo))
        {
                return GetLastError();   
        }

        WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
        if(!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
                rc = 0;

        CloseHandle(ProcessInfo.hThread);
        CloseHandle(ProcessInfo.hProcess);

        return rc;
       
}

Author:  [Gandalf] [ Mon Nov 21, 2005 1:40 am ]
Post subject: 

From my somewhat limited experience with Dev-C++, I am almost sure that there is a 'project' option that disables the command prompt showing up. Look around there. Or else, try selecting the 'WinApi' option, not "command prompt" when creating your project.


: