views:

326

answers:

3

I really have no idea why this is happening... I created a win32 application in emacs, and whenever I make it and run it (not through the command prompt), a command prompt window pops up under the window. If I build a win32 application in Code::Blocks, and just run its default template, then it runs without a command prompt window. I looked all through the code of both and can't figure out what might cause this...

I thought it was because I included some printf() statements in there, but I didn't want them to stay there (they were for debugging), so I wrote a macro:

#define DEBUG

in main.c, and

#ifdef DEBUG
#include<stdio.h>
#define DBG printf
#else
#define DBG
#endif

in a header (included after the #define DEBUG of course).

When I undef'd DEBUG, the window still showed up... I don't know what I am doing to make it happen, what sorts of things cause a command prompt window to show up in a win32 application? I tried using all the ****Ex() windows functions instead of just CreateWindow(), etc, but that didn't change anything. I checked and re-checked the class definition and registration, to no avail, and made sure I didn't forget a printf() statement (which would have caused an error even if I did, since stdio.h isn't included unless DEBUG is defined).

This is what I included:

#include<windows.h>
#include<windowsx.h>
#include"main.h"
#include"windowproc.h"

anyone know what can cause this? I even commented out all of my stdio, DBG, printf junk, and it still showed up, and I swear there's no difference between my code and the Code::Blocks generated code, aside from my use of HANDLE_MSG and a few extra functions to split up the code.

Update

I am using MinGW 3.4.5. using the -mwindows switch worked, thanks

+4  A: 

Try linking with the -mwindows switch.

Your program should also have the main method read like so:

int WINAPI WinMain(
....
)

as opposed to the traditional int main().

Related threads:

John T
+2  A: 

Windows makes a difference between "console" and "Windows" applications. Console applications will always be run with an associated terminal.

See this question for details on the differences.

unwind
+2  A: 

Don't know what compiler you are using but I know GCC needs the -mwindows option to suppress the command line window.

JD