How do I run my program without the console window appearing? My program doesn't produce any to the screen and I don't want my users having to stare at a console window.
Thanks,
Chris
Printable View
How do I run my program without the console window appearing? My program doesn't produce any to the screen and I don't want my users having to stare at a console window.
Thanks,
Chris
If the program doesn't output or writes something to the screen, the console window will close automatically, it's only when you run it through MSVC++ that you get the "Press any key to.......".
When you choose to make a Windows Console App (VC++ App Wizard)
DONT !!
Choose Windows Application (i think it is)
Then just put
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// Put Code Here
}
I didn't use as wizard to create this. I just opened and saved a couple of source and header files. I guess where I went wrong is using main() instead of WinMain().
Next question, is lpCmdLine the command line parameter? When I call this program, I pass it the name of an output file. Do I get this value from lpCmdLine instead of argv[1]?
Sorry, but I've never programmed in windows using C++.
Chris
I get the following Linking error when trying to use the int WINAPI WinMain() entry function:
Any ideas?Code:LIBC.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Release/AppTracker.exe : fatal error LNK1120: 1 unresolved externals
Here's a simple app I wrote that run in the background for a few minutes and attempt to maximize notepad:
It should get you started. There's great documentation on at MSDN.Code:#include <windows.h>
//function prototypes
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
//application entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
HWND hApp = NULL;
int i = 0;
for (i = 0; i <= 10; i++) {
hApp = FindWindow("Notepad", NULL);
if (hApp) {
SetForegroundWindow(hApp);
ShowWindow(hApp, SW_SHOWMAXIMIZED);
break;
} else {
Sleep(15000);
}
}//end for loop
return 0;
}
Here is the entire program:
I still get the linker error when I try to build this program. WHY?????????????Code:#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
//void main(int argc, char *argv[])
{
HANDLE hFile;
long lRet;
//Delete the File
lRet = DeleteFile(lpCmdLine);
//Recreate the File
hFile = CreateFile(lpCmdLine,
GENERIC_WRITE,
NULL,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
//Close the Open File Handle
CloseHandle(hFile);
return 1;
}
You get the linker error because your project is a Win32 Console Application and not a Win32 Application.
In the linker options, change /subsystem:console to /subsystem:windows.