2

Ok this is a continuation from this question: How to make a simple Hello World "invisible" in Windows (C/C++)

People gave me some guidance and here I am with a new qestion:

Aight after doing some research I am stuck again. People on the internet claim that by just creating a win32 application there will be no graphical indications.

Here is the code that does this (I'm pretty sure you already know this but w/e)

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {

//code
return 0;
}

So the code typed inside main is not displayed. I don't really get what kind of code they mean but for example:

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow) {

    while (1) {
    }
}

This program pops a Cmd window just fine.

I've also found that by initializing values at the STARTUPINFO structure like that

STARTUPINFO StartupInfo;
memset(&StartupInfo, 0, sizeof(StartupInfo));
// set the size of the structure
StartupInfo.cb = sizeof(STARTUPINFO);
// tell the application that we are setting the window display 
// information within this structure
StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
// set the window display to HIDE
StartupInfo.wShowWindow = SW_HIDE;

would hide the console window. This doesn't work either for me though. I have this feeling that I am missing a major concept here so I need your knowledge guys. I want to create simple .exe with something like a while loop or a simple print that doesn't display a thing. What am I missing?

4
  • 1
    possible duplicate of How to remove command line from a compiled program? Short answer: create an executable with "subsystem GUI" instead of "subsystem Console" (see your linker options). Commented Feb 29, 2012 at 1:46
  • Hmm I didn't spot that unfortunately, I will check it out though. Thanks for the input as well man Commented Feb 29, 2012 at 2:11
  • No worries, I only knew about that duplicate because I answered that other question. :) Commented Feb 29, 2012 at 2:14
  • So i checked the other question and it is indeed very relevant. I found this link there: irrlicht3d.org/wiki/index.php?n=Main.DisablingConsoleWindow . It pretty much sums up all I was asking :D Commented Feb 29, 2012 at 2:49

1 Answer 1

5

You have to use a specific compiler option to do this; it's not a property of the code itself. I will assume you are using Visual Studio to compile.

Go to Project Properties > Configuration Properties > Linker > System > SubSystem and set it to Windows. If you do this and run your program and, for example, put your program into an infinite loop, you'll have to kill it from the Task Manager.

I have no idea how to do this on GCC. Gerald has told me in the comments that using --subsystem,windows or -mwindows will do this for GCC. Note that -mwindows links the GDI libraries as well.

Sign up to request clarification or add additional context in comments.

2 Comments

--subsystem,windows or -mwindows for GCC. -mwindows also adds the GDI libraries to the linker
Alright i will check it out right now. I use Code::Blocks but I have Visual studio aswell just not familiar with it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.