Do I have to create a window in a Windows API application (with WinMain)? What if my application runs in the background (a server)?
Printable View
Do I have to create a window in a Windows API application (with WinMain)? What if my application runs in the background (a server)?
You can use the WinAPI functions while running the program in a standard console, that is, you don't need to make a window. If you want to run in background, you can use handles and then the ShowWindow() function to hide the console.
You could have simply tried it, of course :) And this would have been better posted under Windows Programming, if I'm not mistaken.
windows application run on several windows subsystems: console, windows, posix, whatever
http://msdn.microsoft.com/library/de...mplref_135.asp
http://msdn.microsoft.com/library/de...locconsole.asp
to run a application with main you have to specify subsystem console (it's the default to most compilers). To work with a gui, specify windows. With a gui, you can call AllocConsole() to create a console for your process.
http://msdn.microsoft.com/library/de...locconsole.asp
with a console app... itīs a bit harder to get rid of the console. I donīt know why
where's a small example - of course this syntax for pragma coment is Ms specific. I don't know the gcc version. Never tried it
A console app
a gui appCode:#pragma comment(linker, "/SUBSYSTEM:CONSOLE")
#include <iostream>
int main(){
std::cout<<"Hllo world!"<<std::endl;
return 0;
}
any process can run without any console or window.Code:#pragma comment(linker, "/SUBSYSTEM:WINDOWS")
#include <windows.h>
int WinMain(HINSTANCE hc, HINSTANCE hp, LPSTR cmdln, int guicmd){
MessageBox(GetDesktopHandle(),"hello world","hello world",0);
return 0;
}
Of course to kill it you have to go to Task Manager