错误示例
char text[] = "button";//这里的字符串是由char类型数组构成的字符串
int tx = textwidth(text);//这三个函数都会报错
int ty = textheight(text);
outtextxy(tx, ty, text);
原因
easyx的函数重载中并没有char类型的形参
// Text related functions
void outtextxy(int x, int y, LPCTSTR str); // Output a string at the specified location
void outtextxy(int x, int y, TCHAR c); // Output a char at the specified location
int textwidth(LPCTSTR str); // Get the width of a string
int textwidth(TCHAR c); // Get the width of a char
int textheight(LPCTSTR str); // Get the height of a string
int textheight(TCHAR c); // Get the height of a char
int drawtext(LPCTSTR str, RECT* pRect, UINT uFormat); // Output a string in the specified format within the specified area.
int drawtext(TCHAR c, RECT* pRect, UINT uFormat); // Output a char in the specified format within the specified area.
解决方法
用wchar_t 或TCHAR来代替char 定义字符串数组,并在字符串前加L、_T()或TEXT()
wchar_t text[] = L"button";//注意要加L
/*
下面三种格式都可以
TCHAR text[] = L"button";
TCHAR text[] = _T("button");
TCHAR text[] = TEXT("button");
*/
int tx = textwidth(text);
int ty = textheight(text);
outtextxy(tx, ty, text);