I'm relatively new to programming and such but I'm looking for just a quick fix (not for school or anything, I don't go to college or anything :D). I'm looking to find out how to hide the main dosish window that pops up. I'd like to keep it hidden from view or something if possible. Any help would be greatly appreciated as soon as possible.
BTW: I'm using [i]system("app.exe -param"); for launching an application within the application. It's not reading anything from the launched application either. I'm kinda looking for the application to exit after executing the other application if it's possible.
Just a question: why would you like the commandprompt not to show up?? This sounds fishy to me.
lol.. Actually, after posting this, I thought "man, I sound like I'm creating a virus or something." heh... It's not quite like that. Actually, there's this game which I usually launch through a shortcut but to switch between online and offline mode, you have to rename a certain file, so I just used C++ to automate it but the window stays in view and I'd rather have it hidden.
It's actually a server file for Battlefield 1942. When I play at LANs, I usually set up with different settings that me and my friends enjoy.
if you are trying to hide a window use
that will stop the window been shown when you press clt alt dlt but i dont know how to hide a process just yet
What header would you need to include to use ShowWindow()?
windows.h - it's part of the Win32 SDK - your compiler may or may not have that library.
heh.. It appears to but tells me hwnd is unidentified.
[EDIT]Fixed I guess
I do get a problem where I can't use ShowWindow(hwnd,SW_HIDE,0,0) as it says ShowWindow doesn't take 4 parameters.
I just did a search of the board for "hide and console" (without the quotes) in the C++ forum. Several interesting threads appeared with potential solutions (including more information on the problem you are having here). Try reading those.
Will check right now. Thanx.
You're going to need to do this entire program in Win32, which I don't recommend (since you hadn't even heard of the API) if there is another option. I don't think there is, however.
This will do the trick:
Just remember to include <windows.h>.
Well, you're new to programming, but copy paste doesn't hurt anybody... so if you're interested.
It could be better like this (quoted from the FAQ) :
Some things you should know.
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
char szPath = PUT_YOUR_EXE_NAME_HERE;
PROCESS_INFORMATION pi; //Gives info on the thread and..
//..process for the new process
STARTUPINFO si; //Defines how to start the program
ZeroMemory(&si,sizeof(si)); //Zero the STARTUPINFO struct
si.cb = sizeof(si); //Must set size of structure
BOOL bRet = CreateProcess(
szPath, //Path to executable file
NULL, //Command string - not needed here
NULL, //Process handle not inherited
NULL, //Thread handle not inherited
FALSE, //No inheritance of handles
0, //No special flags
NULL, //Same environment block as this prog
NULL, //Current directory - no separate path
&si, //Pointer to STARTUPINFO
π); //Pointer to PROCESS_INFORMATION
if(bRet == FALSE)
MessageBox(HWND_DESKTOP,"Unable to start program","",MB_OK);
CloseHandle(pi.hProcess); //Close handle to process
CloseHandle(pi.hThread); //Close handle to thread
If you want to use this example, you have to compile and link your code as a Win32 application. Don't worry, you don't have to pay any fees to MS.
Simply open your IDE, choose a new Win32 project, or Win32 GUI application.. whatever. Just don't choose something that states library or console. Then add your source files to the project, or create new files, and copy/paste. Then compile, link and your new brand application doesn't have any console or graphical window, althouh you can easilly see the process in the Task Manager.
The way this code is written, your application is stated and this process ends.
If your compiler, or IDE don't have win32 libs, or you're not using windows, then.. just use the old system(...) stuff, or read throughly the FAQ entry...
here is a working example of using sw_hide it will hide the window mIRC
using namespace std;
HWND hwnd = FindWindow(NULL, "mIRC");