C语⾔EasyX实现即时显⽰键盘输⼊内容由于代码没地⽅放——
#include<stdio.h>
#include <windows.h>
#include<conio.h>
#include<graphics.h>
//改了个字体样式
void setTextStyle() {
LOGFONT f;          //这个结构体定义了字体的属性
gettextstyle(&f);      // 获取当前字体设置
f.lfHeight = 70;      // 设置字体⾼度
f.lfWeight = 1000;
_tcscpy_s(f.lfFaceName, _T("Segoe Script"));  // 设置字体
f.lfQuality = ANTIALIASED_QUALITY;  // 设置输出效果为抗锯齿
settextstyle(&f);      // 设置字体样式
//setbkmode(TRANSPARENT);// 去掉⽂字背景
}
TCHAR* f1(const char* pChar)
{
TCHAR* pTchar = NULL;
int nLen = strlen(pChar) + 1;
#ifdef _UNICODE
pTchar = new wchar_t[nLen];
MultiByteToWideChar(CP_ACP, 0, pChar, nLen, pTchar, nLen);
#else
pTchar = new char[nLen];
wcsncp(pTChar, pChar, nLen * sizeof(char));
#endif
return pTchar;
}
int main(){
initgraph(1024, 640);
TCHAR letters[100];
char tempChar;
char tempStr[100];
int counter = 0;
setTextStyle();
while (1) {
if (_kbhit) {
tempChar = _getch();
tempStr[counter] = tempChar;
for (int i = 0; i < counter + 1; i++) {
letters[i] = *f1(tempStr + i);
}
letters[counter + 1] = '\0';
cleardevice();
outtextxy(120, 20, letters);
counter++;
}
textstyle}
_getch();
closegraph();
return 0;
}
其中char转TCHAR的函数见:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。