隐藏C程序的控制台窗口

时间:2022-11-20 00:22:03

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

我一直在环顾四周,但我无法找到问题的解决方案,即使有一些类似于我的解决问题。

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

我希望在我的C程序运行时隐藏控制台窗口。

#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 "initialization makes pointer from integer without a cast"

这是我尝试但编译器给我“初始化使得指针来自整数而没有强制转换”

and the fatal one which actually stops the compiling "undefined reference to 'GetConsoleWindow'"

和致命的一个实际上停止编译“未定义引用'GetConsoleWindow'”

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

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

1 个解决方案

#1


14  

Your

你的

#define _WIN32_WINNT 0x0500

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

(必须使用GetConsoleWindow - 请参阅文档)

#include <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.

windows.h使用#define来了解您所针对的Windows版本(以及它必须提供哪些声明/它必须添加到哪些其他字段以及可能与该链接器错误相关的其他魔法);如果你在包含windows.h后定义它,它将是无用的。

#1


14  

Your

你的

#define _WIN32_WINNT 0x0500

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

(必须使用GetConsoleWindow - 请参阅文档)

#include <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.

windows.h使用#define来了解您所针对的Windows版本(以及它必须提供哪些声明/它必须添加到哪些其他字段以及可能与该链接器错误相关的其他魔法);如果你在包含windows.h后定义它,它将是无用的。