Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a command prompt from appearing in a Win32 C application?

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

like image 306
Carson Myers Avatar asked Dec 30 '22 22:12

Carson Myers


2 Answers

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:

  • Why does my QT4.5 app open a console window under Windows?
  • GCC / C how to hide console window?
like image 97
John T Avatar answered Jan 12 '23 00:01

John T


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.

like image 28
unwind Avatar answered Jan 12 '23 01:01

unwind