I would like to understand how to set the background color of a button in win32.
I create my button with
CreateWindow
and tried using the API
setbkcolor
and
setdcbrushcolor
with all the necessary parameters but it does not work, then I tried to use
FillRect
but, not having found anything minimally commented, I cannot make the area of the colored rectangle coincide with the surface of my button and then the text of the button is covered from the rectangle.
What can I do?
Thanks in advance for the help and advice
Below is the base code of my window
What I have tried:
#include <windowsx.h>
#include <windows.h>
#include "resource.h"
#pragma GCC diagnostic ignored "-Wunused-parameter"
#define IDC_BUTTON_START 0
HINSTANCE ghinstApp;
HWND ghwndApp;
HWND hStart;
BOOL Dlg_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
HFONT hFont;
ghwndApp = hwnd;
SetClassLong(hwnd, GCLP_HICON, (LONG) LoadIcon(ghinstApp, MAKEINTRESOURCE(IDI_ICONA)));
hFont = CreateFont(40, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Calibri");
hStart = CreateWindow("Button", "PLAY", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 0, 0, 150, 114, hwnd, (HMENU)IDC_BUTTON_START, ghinstApp, NULL);
SendDlgItemMessage(hwnd, IDC_BUTTON_START, WM_SETFONT, (WPARAM)hFont, TRUE);
return TRUE;
}
void Dlg_OnClose()
{
EndDialog(ghwndApp, 0);
}
BOOL CALLBACK Dlg_Proc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hDlg, WM_INITDIALOG, Dlg_OnInitDialog);
HANDLE_MSG(hDlg, WM_CLOSE, Dlg_OnClose);
default:
break;
}
return FALSE;
}
int WINAPI WinMain(HINSTANCE hinstExe, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int nCmdShow)
{
ghinstApp = hinstExe;
DialogBox(hinstExe, MAKEINTRESOURCE(IDD_DIALOGMAIN), NULL, Dlg_Proc);
return (0);
}