赞
踩
由于代码没地方放——
- #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++;
- }
- }
- _getch();
- closegraph();
- return 0;
- }
其中char转TCHAR的函数见:TCHAR * 转为char * 和 char * 转为 TCHAR *
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。