16,467
社区成员
发帖
与我相关
我的任务
分享
// StepText(hdc,&rect,"haha 你好!\r\nhaha 你也好!\r\n\r\nhaha 他好!\r\nhaha 她也好!");
void StepText(HDC hdc,RECT *rc,char *str)//文字逐字显示
{
int len=strlen(str);//计算字符串的长度
int posx;//当前字符位置
int posy=rc->top;
SIZE size;//存储每个字符的宽高
SetTextAlign(hdc,TA_UPDATECP|TA_LEFT|TA_TOP);//设置自动更新文字位置
while(len>0)
{
posx=rc->left;
MoveToEx(hdc,rc->left, posy,NULL);//移动到行首
while(len>=0)
{
int t;
if((str[0])<0) {t=2;SetTextColor(hdc,255);}//中西字符辨别
else {t=1;SetTextColor(hdc,0);}
GetTextExtentPoint32(hdc,str,t,&size);//获取字符宽高
if(posx+size.cx>rc->right) break;//若超出边界
posx+=size.cx;//更新当前位置
if(*str==0x0D){ str+=1; continue;}
if(*str==0x0A){ str+=1; len=strlen(str); break;}
TextOut(hdc,0,0,str,t);//输出字符
str+=t;//更新字符
len-=t;//更新字符长度
if(len<=0) break;//若字符输出完毕
} // end while(len>=0)
// newline:
posy+=size.cy; //进行移行处理
if((posy+size.cy+ size.cy)>=rc->bottom)//下一行无法书写,进行滚屏
{
RECT rect=*rc;
rect.top+=size.cy;//滚屏位置
ScrollDC(hdc,0,-size.cy,&rect,NULL,NULL,NULL);
posy-=size.cy; //恢复移行处理
}
}
}
void StepText(HDC hdc,RECT *rc,char *str)//文字逐字显示
{
int len=strlen(str);//计算字符串的长度
int posx;//当前字符位置
int posy=rc->top;
SIZE size;//存储每个字符的宽高
SetTextAlign(hdc,TA_UPDATECP|TA_LEFT|TA_TOP);//设置自动更新文字位置
while(len>0)
{
posx=rc->left;
MoveToEx(hdc,rc->left, posy,NULL);//移动到行首
while(len>=0)
{
int t;
if((str[0])<0) t=2;//中西字符辨别
else t=1;
GetTextExtentPoint32(hdc,str,t,&size);//获取字符宽高
if(posx+size.cx>rc->right) break;//若超出边界
posx+=size.cx;//更新当前位置
TextOut(hdc,0,0,str,t);//输出字符
str+=t;//更新字符
len-=t;//更新字符长度
if(len<=0) break;//若字符输出完毕
}
posy+=size.cy; //进行移行处理
if((posy+size.cy+ size.cy)>=rc->bottom)//下一行无法书写,进行滚屏
{
RECT rect=*rc;
rect.top+=size.cy;//滚屏位置
ScrollDC(hdc,0,-size.cy,&rect,NULL,NULL,NULL);
posy-=size.cy; //恢复移行处理
}
}
}