Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C++
#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);
}


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
Posted
Updated 16-Dec-18 2:01am
v2

 
Share this answer
 
v2
Comments
Kyserx 16-Dec-18 7:23am    
At the first link i don't understand the most of the code.
At the second link i don't know how to create CButton variable.
I'm really beginnre for this.
RickZeeland 16-Dec-18 8:07am    
I added a link to an online tutorial at TutorialsPoint, good luck :)
Kyserx 16-Dec-18 9:12am    
Thanks ^^
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.
 
Share this answer
 
Comments
Kyserx 16-Dec-18 9:13am    
Thanks ^^

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900