Windows console app
Hello,
In windows, when your main function is a main() and not a WinMain() function, you get a console. I am using GLFW to manage my windows. So I don't need a WinMain function. Is there a way to make the console dissapear? ex. You double click the exe, you never see the console, and then the window GLFW creates appears. I want to make the console never appear. Is this possible?
Thanks, Slaru
Short answer: no
Long answer: if you really really want to, I'm sure it's possible (through various API calls and events), but there's no easy way that I've ever seen
Console apps are meant to be just that: consoles. The fact that you can create windows is really just a side-effect of the fact that it's still a win32 app.
Most developers end up creating a stub WinMain that wraps whatever framework they're using. SDL, for example, provides a wrapper that creates the graphics context then calls your main() function so you can start the game.
Long answer: if you really really want to, I'm sure it's possible (through various API calls and events), but there's no easy way that I've ever seen
Console apps are meant to be just that: consoles. The fact that you can create windows is really just a side-effect of the fact that it's still a win32 app.
Most developers end up creating a stub WinMain that wraps whatever framework they're using. SDL, for example, provides a wrapper that creates the graphics context then calls your main() function so you can start the game.
If I recall correctly, simply putting your main function in WinMain (and setting a windows, rather than console, subsystem) is all you need to do. WinMain does not automatically create a window.
The reason I wanted to was so I can totally not rely on Windows, for easy cross-platform porting (GLFW is cross-platform). If it is very complicated, then I will just use windows and WinMain. But if there is a way not too complicated, then that would be nice.
You will need to write some windows specific code. You can either achieve this as Sneftel suggested (/SUBSYTEM:Windows) and winmain, or you can just call
FreeConsole
Just use
#ifdef _WIN32
#endif
to ensure your windows specific code only compiles under windows
FreeConsole
Just use
#ifdef _WIN32
#endif
to ensure your windows specific code only compiles under windows
You could try something like:
This ensures that, if compiling under Windows, WinMain() will be in the entry point and it will call main(), and if compiling under a different OS, main() will simply be the entry point.
int main(void); #ifdef _WIN32 // If compiling for 32-bit Windowsint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ return main(); // Note: If you have // int main(int argc, char **argv) // then you will have to parse lpCmdLine and fill in argc and argv yourself}#endifint main(void){...}
This ensures that, if compiling under Windows, WinMain() will be in the entry point and it will call main(), and if compiling under a different OS, main() will simply be the entry point.
I never really saw the point of preferring WinMain over main. WinMain gets its parameters via GetModuleHandle(NULL) and GetCommandLine() anyway.
Short answer: Yes.
I make GLUT apps all the time using main(). If you are using Visual Studio, add this line to your source:
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
You could do it in the project properties, but this line is easier.
I make GLUT apps all the time using main(). If you are using Visual Studio, add this line to your source:
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )
You could do it in the project properties, but this line is easier.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement