01 #include <stdio.h>
02 #include <stdlib.h>
03 #include <windows.h>
04
05 HANDLE StdHandle;
06
07 int RGBI (int Red, int Green, int Blue, int Intensified);
08 int Set_Color (int RGB_Fore, int RGB_Back);
09
10 int main (void)
11 {
12 StdHandle = GetStdHandle(STD_OUTPUT_HANDLE);
13 Set_Color(RGBI(0,1,0,1), RGBI(0,0,1,1));
14 char Str [8] = "Great.\n";
15 printf("%s", Str);
16 system("pause>nul");
17 CONSOLE_FONT_INFO FONT;
18 GetCurrentConsoleFont(StdHandle, FALSE, &FONT);
19 COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
20 return 0;
21 }
22
23 int RGBI (int Red, int Green, int Blue, int Intensified)
24 {
25 return (Intensified*8 + Red*4 + Green*2 + Blue);
26 }
27
28 int Set_Color (int RGB_Fore, int RGB_Back)
29 {
30 SetConsoleTextAttribute(StdHandle, RGB_Fore + RGB_Back*16);
31 return 0;
32 }
TDM-GCC报道
>mingw32-gcc.exe -Wall -c "main.c" -o "main.o"
main.c: In function 'main':
main.c:18:3: warning: implicit declaration of function 'GetCurrentConsoleFont' [-Wimplicit-function-declaration]
GetCurrentConsoleFont(StdHandle, FALSE, &FONT);
^
main.c:19:3: warning: implicit declaration of function 'GetConsoleFontSize' [-Wimplicit-function-declaration]
COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
^
main.c:19:3: error: invalid initializer
main.c:19:9: warning: unused variable 'Fontsize' [-Wunused-variable]
COORD Fontsize = GetConsoleFontSize(StdHandle, FONT.nFont);
^
为什么呢?我应该更新windows.h
吗?
在何处下载最新版本的windows.h
?
感谢。
答案 0 :(得分:1)
我认为您需要定义最低Windows版本,因此请在#include <windows.h>
#define _WIN32_WINNT 0x500
要编译使用此功能的应用程序,请定义_WIN32_WINNT 为0x0500或更高版本。有关更多信息,请参阅使用Windows 头。