# include <stdio.h>
# include <conio.h>
# include <windows.h>
# include <stdlib.h>
# include <string.h>
# include <time.h>
void OutputAttribute (void)//给指定的字符填充属性
{
HANDLE H = GetStdHandle (STD_OUTPUT_HANDLE);
COORD cursorposition = {30 , 1};
WORD Attribute = FOREGROUND_RED | FOREGROUND_INTENSITY;
DWORD UL;
SetConsoleCursorPosition (H , cursorposition);
for (int i = 1; i <= 200; i++)
{
printf ("0");
}
printf ("你好啊");
FillConsoleOutputAttribute (H , Attribute , 200 , cursorposition , &UL);
printf ("%d" , UL);
}
void OutputCharacter (void)
{
HANDLE H = GetStdHandle (STD_OUTPUT_HANDLE);
COORD cursorposition = {25 , 5};
DWORD UL;
char str[] = "你好,欢迎来到这里!";
int n;
PWCHAR Wstr;
n = MultiByteToWideChar (CP_ACP , 0 , str , -1 , NULL , 0);
Wstr = (PWCHAR)malloc (n*sizeof (WCHAR));
MultiByteToWideChar (CP_ACP , 0 , str , -1 , Wstr , n);
WriteConsoleOutputCharacter (H , Wstr , n-1 , cursorposition , &UL);
free (Wstr);
}
void OutputCharacterAttribut (void)
{
HANDLE H = GetStdHandle (STD_OUTPUT_HANDLE);
COORD Buffersize = {80 , 25};
COORD cursorposition = {25 , 8};
CHAR_INFO info , infoarray[80*25];
info.Attributes = FOREGROUND_RED | FOREGROUND_INTENSITY;
///这里将char类型转换为wchar_t类型
char greeting[] = "您好,欢迎光临125!";
int n;
PWCHAR Wstr;
//
n = strlen (greeting);
n = MultiByteToWideChar (CP_ACP , 0 , greeting , -1 ,NULL , 0);//这个也是求出长度。
//
printf ("%d" ,n);//char 与 wchar_t 类型的字符串长度不一样的。
Wstr = (PWCHAR)malloc (n*sizeof (WCHAR));
MultiByteToWideChar (CP_ACP , 0 , greeting , -1 , Wstr , n);
n = wcslen (Wstr);//求字符串长度
//
printf ("%d" ,n);//
///////////////////////////////
for (int i = 0; i < n; i++)
{
info.Char.UnicodeChar = Wstr[i];
infoarray[80*8+(25+i)] = info;
}
SMALL_RECT rc1 = {25 , 8 , 25+n-1 ,8};
WriteConsoleOutput (H , infoarray , Buffersize , cursorposition , &rc1);
free (Wstr);
}
void BufferSize (void)
{
HANDLE H = GetStdHandle (STD_OUTPUT_HANDLE);
COORD SIZE = {100 , 25};
SetConsoleScreenBufferSize (H ,SIZE);
SMALL_RECT cr = {0 , 0 , 100-1 , 25-1};
SetConsoleWindowInfo (H , true , &cr);
CloseHandle (H);
}
int main (void)
{
//
BufferSize ();
OutputAttribute();
OutputCharacter ();
OutputCharacterAttribut ();
getchar ();
return 0;
}
请教下,为什么缓冲区的大小改变后什么都输出不了了