Reputation: 16724
I'm handling WM_CTLCOLORSTATIC
like this:
case WM_CTLCOLORSTATIC:
{
HWND fromHwnd = (HWND) lParam;
if(fromHwnd == hGroupBox)
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(255, 255, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LRESULT) bckBrush;
}
}
break;
It uses the returned brush as background color but the SetTextColor()
has no effect at all. What am I missing?
Here's all my code:
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "Comctl32.lib")
#pragma comment(lib, "Gdi32.lib")
#define WIN32_LEAN_AND_MEAN
#define UNICODE
#define _UNICODE
#include <windows.h>
#include <Commctrl.h>
#include <crtdbg.h>
#include <strsafe.h>
#include <string.h>
#include <assert.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hGroupBox;
HBRUSH bckBrush;
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR pCmdLine, int nCmdShow)
{
MSG msg = {0};
HWND hwnd;
WNDCLASSW wc = {0};
wc.lpszClassName = L"Window";
wc.hInstance = hInstance;
wc.hbrBackground = GetSysColorBrush(COLOR_3DFACE);
wc.lpfnWndProc = WndProc;
wc.hCursor = LoadCursor(0, IDC_ARROW);
if(!RegisterClass(&wc)) {
assert(!"register class error");
}
bckBrush = CreateSolidBrush(RGB(0, 128, 0));
int width = 500;
int height = 350;
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
int cx = (screenWidth - width) / 2;
int cy = (screenHeight - height) / 2;
hwnd = CreateWindowW(wc.lpszClassName, L"Window",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
cx, cy, width, height, NULL, NULL,
hInstance, NULL);
while (GetMessage(&msg, NULL, 0, 0))
{
if (!IsDialogMessage(hwnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (int) msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
CreateWindowW(L"Static", L"This is label 1...",
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
50, 10, 130, 25, hwnd, (HMENU) 18, NULL, NULL);
CreateWindowW(L"Static", L"This is label 2...",
WS_VISIBLE | WS_CHILD | WS_TABSTOP,
50, 40, 130, 25, hwnd, (HMENU) 19, NULL, NULL);
hGroupBox =
CreateWindowW(L"button", L"Pick a city",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_GROUPBOX,
50, 75, 200, 150, hwnd,
(HMENU) 20, NULL, NULL);
break;
case WM_CTLCOLORSTATIC:
{
HWND fromHwnd = (HWND) lParam;
if(fromHwnd == hGroupBox)
{
HDC hdcStatic = (HDC) wParam;
SetTextColor(hdcStatic, RGB(255, 255, 0));
SetBkMode(hdcStatic, TRANSPARENT);
return (LRESULT) bckBrush;
}
}
break;
case WM_DESTROY:
DeleteObject(bckBrush);
bckBrush = NULL;
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, msg, wParam, lParam);
}
Upvotes: 0
Views: 133