gpt4 book ai didi

c++ - WIN32API : owner-drawn button creates white background around the text when clicked

转载 作者:太空宇宙 更新时间:2023-11-04 08:37:14 26 4
gpt4 key购买 nike

我创建了一个 Owner-Drawn 按钮。我使用 WM_CTLCOLORBTN 消息来绘制它:

//get the text of the button
wchar_t buttonText[20];
int textLength = SendMessage((HWND)lParam,WM_GETTEXT,20,(LPARAM)buttonText);

Font FootlightMTLight(L"Footlight MT Light",20,0,false,false,false,L"Black");
SelectObject((HDC)wParam,FootlightMTLight.getWindowHandle());

TextOut((HDC)wParam,30,15,buttonText,textLength);
SetTextColor((HDC)wParam, RGB(0,0,0));
SetBkColor((HDC)wParam, RGB(229,255,229));

PatBlt((HDC)wParam,0,0,1,50,BLACKNESS); //x,y,width,height
PatBlt((HDC)wParam,269/2-1,0,1,50,BLACKNESS);
PatBlt((HDC)wParam,0,49,269/2,1,BLACKNESS);
PatBlt((HDC)wParam,0,0,269/2,1,BLACKNESS);

static HBRUSH handleToButtonBrush = CreateSolidBrush(RGB(229,255,229));
return (INT_PTR)handleToButtonBrush;

“字体”是我创建的对象(我用类等包装了 HFONT 句柄和 CreateFont 函数。getWindowHandle() 基本上返回 HFONT )。

按钮呈现得很好,但按下它会使文本背景变为白色。我在网上搜索原因和解决方案,但没有找到具体的解决方案。提前致谢!

最佳答案

您需要在实际绘制文本之前调用这些行

SetTextColor((HDC)wParam, RGB(0,0,0));
SetBkColor((HDC)wParam, RGB(229,255,229));
TextOut((HDC)wParam,30,15,buttonText,textLength);

关于c++ - WIN32API : owner-drawn button creates white background around the text when clicked,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25698805/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com