Windows GUI更改按钮颜色 [英] Windows GUI change button color
问题描述
我想在用户点击它时更改按钮颜色。
主要计划是:每个月第10个工人的按钮变为红色,如果工人完成了他的工作,那么点击按钮它会变成绿色。
我不知道该怎么办。
我已经有了这个代码......我刚刚创建了一个窗口并添加了一个按钮:
I wanna change button colors when the user click on it.
The main plan is: every month 10th one worker's button go to red and if the worker done his job then click on the button and it going to be green.
I have no idea what to do.
I already have this code... I just created a window and add a button to it:
#include <windows.h>
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);
void AddButton(HWND hwnd);
LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT msg, WPARAM wp,
LPARAM lp)
{
switch (msg) {
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
AddButton(hWnd);
break;
default:
return DefWindowProcW(hWnd, msg, wp, lp);
}
}
void AddButton(HWND hWnd)
{
CreateWindowW(L"Button", L"Change colors", WS_VISIBLE | WS_CHILD,
350, 200,
100, 100,
hWnd,
NULL,
NULL,
NULL);
}
我的尝试:
所以我尝试了WM_LBUTTONDOWN ...所以我认为这是当用户点击按钮时程序会做的事情。我放入了开关(msg)案例WM_LBUTTONDOWN:
但不知道下一步是什么
What I have tried:
So I tried WM_LBUTTONDOWN... so i think this is something when the user click on the button the program will do something. i put in the switch(msg) case WM_LBUTTONDOWN:
but no idea what's next
推荐答案
在这里查看答案:如何更改按钮WinAPI C ++的背景颜色 - 堆栈溢出 [ ^ ]
这里:如何更改vc ++ mfc for vs2008中按钮的颜色 [ ^ ]
另请参阅此处的在线教程: MFC按钮 [ ^ ]
See answers here: How can I change the background color of a button WinAPI C++ - Stack Overflow[^]
And here: how to change color of button in vc++ mfc for vs2008[^]
Also see online tutorial here: MFC Button[^]
您需要使用自定义绘图功能,请参阅< a href =https://docs.microsoft.com/en-gb/windows/desktop/Controls/buttons>按钮 - Windows应用程序| Microsoft Docs [ ^ ]。我建议首先更熟悉Windows控件的一般用法。自定义绘图是一个稍微高级的主题。
You need to use the custom draw feature, see Button - Windows applications | Microsoft Docs[^]. I would suggest getting more familiar with the general use of Windows controls first. Custom drawing is a slightly more advanced subject.
这篇关于Windows GUI更改按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!