Hiding the console window
Is there an easy way to hide the console window created by win32 console applications? I'm completely allergic to WinMain's and whatever uglyness they bring with it, but the console window is quite unneccesary after it spawned the game's main window.
So rather than using an entry point that does exactly what you want, you want to instead hack a console app to not display a console?
...
...
Easy!
Well, it took me a little bit of figuring out...
That that is it.
Your console hidden.
Be sure to make it appear at the end of your program. Before return 0, just to be at the safe side.
Well, it took me a little bit of figuring out...
int main(int argc, char** argv){ HWND hWndConsole = GetForegroundWindow(); ShowWindow(hWndConsole,SW_HIDE); return 0;}
That that is it.
Your console hidden.
Be sure to make it appear at the end of your program. Before return 0, just to be at the safe side.
using GetConsoleWindow is probably safer [smile]
ie.
[edit]
Uhm, i just realized that this function only exists in XP/2000 :(
[edit2]
Just looking through the console section of the MSDN, try FreeConsole(). That is available right back to win95 [smile]
ie.
int main(int argc, char** argv){ ShowWindow(GetConsoleWindow(), SW_HIDE); return 0;}
[edit]
Uhm, i just realized that this function only exists in XP/2000 :(
[edit2]
Just looking through the console section of the MSDN, try FreeConsole(). That is available right back to win95 [smile]
Thanks, all very helpfull! Pitty it will still display for a brief moment though, perhaps I should just use a winmain :/
you could just use #ifdef for different platforms
eg.
Of course winmain passes the command line in as a single string, so you'd have to parse each argument out manually. But other than that, theres no other "uglyness" about it.
eg.
#ifdef _WIN32int WinMain(...)#elseint main (...)#endif
Of course winmain passes the command line in as a single string, so you'd have to parse each argument out manually. But other than that, theres no other "uglyness" about it.
Quote:Original post by Nerusai
I'm completely allergic to WinMain's and whatever uglyness they bring with it
Are you starting as an empty project? Personally I don't like starting a win32 gui app because of all the extra stuff they like to put in either. The trick is to start the GUI app as an empty project and just write your own WinMain and WindProc, its not hard. Any good windows programming book will show you how to set up a minimal window from scratch and once its done you can use it as the basis for all your gui apps. Petzolds "Programming Windows", any of the windows-based LaMothe books and many tutorials will show you how.
Don't do it like that! You still have a WinMain as entry-point under the hood which create a console window and calls your main function when you're in console mode! Hiding your console window like this 1000x uglier and really strange. Instead make an empty windows Gui project. Create a winmain.cpp file with a WinMain function which calls your regular main() function like this
//winmain.cpp#include <windows.h>extern int main(int argc, char* argv[]);int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdLine, int cmdShow){ return main(__argc, __argv);}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement