I have been messing around with making a windows application in Dev-C++ I wanted to make it in a single source file, rather than a project to see if it worked. It did, other than the fact that I got the windows app, AND a DOS prompt behind it. Is there anyway to remove the DOS prompt? I will include the code, so that you can see what I mean.

#include <windows.h>

/*  Declare Windows procedure  */

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window */
    wincl.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           "Windows App",       /* Title Text */
           WS_SYSMENU,          /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           544,                 /* The programs width */
           375,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nFunsterStil);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
        /* Translate virtual-key messages into character messages */
        /* Send message to WindowProcedure */

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;

#define ID_BTN 1
#define ID_TEXTBOX 2

static HWND hwndTextbox;

/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    switch (message)                  /* handle the messages */
        case WM_CREATE:
                  hwndTextbox = CreateWindow(TEXT("EDIT"), TEXT("Type Here"),
                               hwnd, (HMENU) ID_TEXTBOX, NULL, NULL);
                  CreateWindow(TEXT("button"), TEXT("Click Me"),
                               hwnd, (HMENU) ID_BTN, NULL, NULL);
        case WM_COMMAND:
             //action for button
             if (LOWORD(wParam) == ID_BTN)
                //create variables
                int length = GetWindowTextLength(hwndTextbox) + 1;
                static char title[500] = "";
                //MessageBox(hwnd, title, "Debug Box", MB_OK);
                // Creates a window displaying the text typed in the box.

                SetWindowText(hwnd, title);
        case WM_DESTROY:
            PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        default:                      /* for messages that we don't deal with */
            return DefWindowProc (hwnd, message, wParam, lParam);

    return 0;
4 Years
Discussion Span
Last Post by adityatandon

That's the point. I wanted to see if I could do it in just one source file. It already works in a win32 app project. Just didnt know if there was a way to do it strictly in one source file.


Ah right, sorry :P
As far as I know, that console window is the main thread of the application, so I don't think there's any way for you to display only the form and not the console window.


solved it. You can hide the command prompt using this snippet of code below:

#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <iostream>
int main()
HWND hWnd1 = GetConsoleWindow();
ShowWindow( hWnd1, SW_HIDE );

return 0;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.