I want to create a simple C++ class for transparent WinAPI labels (implemented using the standard "static" class). To accomplish this, I create a static control and override its Window Procedure to the following one:
LRESULT CALLBACK WndProc_Override(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
{
if (Message == WM_PAINT)
{
RECT rc;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, Text, strlen(Text), &rc, DT_CENTER | DT_VCENTER);
EndPaint(hwnd, &ps);
return 0;
}
return CallWindowProc(WndProc_Original, hwnd, Message, wparam, lparam);
}
The code was taken from Edward Clements' excellent answer to this question: C++ Win32 Static Control Transparent Background
I wanted to wrap it up in a C++ class so I don't have to create a new Window Procedure for each label I want to use in my program. I wanted the overridden Window Procedure to be a member function which would then use this
to use the label instance's stored data (the text to display, like so: DrawText(hdc, this->Text, strlen(this->Text), &rc, DT_CENTER | DT_VCENTER);
)
However, member functions require that this
be passed as the first parameter, whereas since this is a callback, I have no control over how Windows calls the function.
Is there any other way I can wrap it up in a compact class, so that I don't have to create a separate Window Procedure for each label?