欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Windows API之改变字体颜色篇

程序员文章站 2022-07-05 10:58:48
...

格式:

SetTextColor(hdc,RGB(0,0,0));//RGB(0,0,0)代表黑色
SetBkMode(hdc,TRANSPARENT);//设置文字背景为透明色
//StringCchPrintf(szBuffer,128,TEXT("需要改变颜色的文字"));
//StringCchLength(szBuffer,128,&iTarget);
//TextOut(hdc,100,100,szBuffer,iTarget);//文字

示例:

SetTextColor(hdc,RGB(r,g,b))里设置rgb值,可以打开PhotoShop里的调色板选择颜色然后查看RGB值再填写到这个RGB函数的参数里

SetBkMode(hdc,TRANSPARENT);//设置文字背景为透明色

SetTextColor(hdc,RGB(246,190,214));
StringCchPrintf(szBuffer,128,TEXT("How You Like That"));
StringCchLength(szBuffer,128,&iTarget);
TextOut(hdc,400,420,szBuffer,iTarget);


SetTextColor(hdc,RGB(231,156,194));
StringCchPrintf(szBuffer,128,TEXT("How You Like That"));
StringCchLength(szBuffer,128,&iTarget);
TextOut(hdc,400,440,szBuffer,iTarget);


SetTextColor(hdc,RGB(29,27,56));
StringCchPrintf(szBuffer,128,TEXT("How You Like That"));
StringCchLength(szBuffer,128,&iTarget);
TextOut(hdc,400,460,szBuffer,iTarget);

SetTextColor(hdc,RGB(51,109,136));
StringCchPrintf(szBuffer,128,TEXT("How You Like That"));
StringCchLength(szBuffer,128,&iTarget);
TextOut(hdc,400,480,szBuffer,iTarget);

效果就是这个样子:
Windows API之改变字体颜色篇