Alright, I have a assignment that requires that the user be asked if they would like the program to use the command prompt, or a GUI. I need some help getting this to work, I'm trying to call int main() first, which creates the command prompt and then going to the WinMain() function to create the window depending on user input. I have tried calling WinMain() inside main() but that doesn't work.
How can I go about creating two separate processes? I can't use any non-standard libraries because the professor has to be able to compile my code from a single .cpp file, so I have been doing all my GUI work with the built in WinAPI.
99% of the times that I program in C++ is to create a DLL, so I may be off here. My vote is: You cannot have both types compiled under a single executable. You have to have 2. If I needed this, I would create a Windows (with a Windows GUI) executable that prompts the user for either type. If the user chooses console, then I would launch the other executable; if the user chooses a GUI, then I would just continue loading.
But that's me, and under the premise that the two types cannot live together in the same executable. I may very well be mistaken on this one.
Another alternative is to just create a single Windows app but hide the window. If the user then opts for GUI, you show the window. You can show/hide windows all day long with a minimum of effort.
I think there is also a function called "AllocConsole()" that lets you get a console window if you don't have one (although I don't know how you would hide it).
I was meaning two executables >.>
And you can access GUI kits within a single process, I've done it before. A lot of GUI kits also do this. I just don't remember how >..>.
The normal choice is to have two executables. It's not often that you have a GUI and console edition of a program in a single executable. It's usually popular to contain a console within a GUI but that's another thread.
The only difference between a Win32 GUI application and a Win32 Console application (from the standpoint of the process loader) is in a value in the PE32 header that says whether or not the application gets a console window when it starts.
The simplest way is to start as a Console application. If the user wants the GUI interface, use either FreeConsole() to get rid of the console entirely or ShowWindow() to hide it. The first option is probably more correct. You must be careful not to use standard I/O when the console is not available.