如何隐藏C程序的控制台窗口

如何隐藏C程序的控制台窗口

本文介绍了如何隐藏C程序的控制台窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在环顾四周,但即使有一些据称已解决的类似于我的问题,我也找不到解决问题的方法.

I've been looking around but I couldn't find the solution to my problem, even with some supposedly solved problems that resemble mine.

我想在我的C程序运行时隐藏控制台窗口.

I want to hide the console window when my C program runs.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define _WIN32_WINNT 0x0500

int main(){
    HWND hWnd = GetConsoleWindow();
    ShowWindow( hWnd, SW_MINIMIZE );  //won't hide the window without SW_MINIMIZE
    ShowWindow( hWnd, SW_HIDE );
}

这是我尝试过的,但是编译器给了我

This is what I tried but the compiler gives me

和实际上停止编译的致命代码:

and the fatal one which actually stops the compiling:

PS:我已经检查了 wincon.h 并定义了GetConsoleWindow()函数.

PS: I've checked wincon.h and the GetConsoleWindow() function is defined.

推荐答案

您的

#define _WIN32_WINNT 0x0500

(使用GetConsoleWindow所需-请参见)必须先于

(which is needed to use GetConsoleWindow - see the documentation) must be before

#include <windows.h>

windows.h使用#define来了解您要定位的Windows版本(以及它必须提供哪些声明/它必须向结构中添加哪些其他字段/与之相关的其他魔术)链接器错误);如果在之后定义它,则将windows.h包括在内就没用了.

That #define is used by windows.h to know which version of Windows you are targeting (and thus which declarations it has to provide/which additional fields it has to add to structures/other magic that may be related to that linker error); if you define it after you include windows.h it will be useless.

这篇关于如何隐藏C程序的控制台窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 09:02