简体   繁体   English

在C / C ++中创建一个“不可见”的Windows程序

[英]Creating an “invisible” windows program in C/C++

Ok this is a continuation from this question: How to make a simple Hello World "invisible" in Windows (C/C++) 好的,这是该问题的延续: 如何在Windows(C / C ++)中使简单的Hello World“不可见”

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. 互联网上的人们声称,仅创建Win32应用程序就不会显示任何图形指示。

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. 因此,不会显示在main内部键入的代码。 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. 该程序会弹出一个Cmd窗口。

I've also found that by initializing values at the STARTUPINFO structure like that 我还发现,通过像这样在STARTUPINFO结构中初始化值

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. 我想用while循环或不显示任何内容的简单打印来创建简单的.exe。 What am I missing? 我想念什么?

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. 我将假定您正在使用Visual Studio进行编译。

Go to Project Properties > Configuration Properties > Linker > System > SubSystem and set it to Windows . 转到Project Properties > Configuration Properties > Linker > System > SubSystem ,并将其设置为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. 我不知道如何在GCC上执行此操作。 Gerald has told me in the comments that using --subsystem,windows or -mwindows will do this for GCC. 杰拉尔德(Gerald)在评论中告诉我,使用--subsystem,windows-mwindows将对GCC做到这一点。 Note that -mwindows links the GDI libraries as well. 请注意, -mwindows链接GDI库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM