Running and compiling a simple win32 program in C++

Hi. I'm new to the world of C++, so forgive me for asking a newbie type of question. As title suggests, I'm trying to run this simple hello world program using a simple call to WinMain(). The program runs, but trouble is that it runs as a console program. When I click on hellowin.exe, a black console opens in the background while this is run. Is there a way to avoid that?

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
	MessageBox(NULL, "Hello Windows!","MyFirst",MB_OK);
	return 0;
Choose "win32 project" from your IDE settings, NOT "console project".
@modoran - Actually I wanted to compile this directly from the command line without creating a make file or a VC++ project.

I've now found the answer. I used the "\SUBSYSTEM:WINDOWS" linker option of CL to compile it. The "win32 project" flag would have done the same thing:

cl hellowin.c /link /SUBSYSTEM:WINDOWS user32.lib
Topic archived. No new replies allowed.