Basically nailed it:
void paintControlBackground(HWND hwnd, HDC dc) { HWND parent; RECT r; POINT p; int saved; parent = GetParent(hwnd); if (parent == NULL) xpanic("error getting parent container of control in paintControlBackground()", GetLastError()); if (GetWindowRect(hwnd, &r) == 0) xpanic("error getting control window rect in paintControlBackground()", GetLastError()); // the above is a window rect; convert to client rect px = r.left; py = r.top; if (ScreenToClient(parent, &p) == 0) xpanic("error getting client origin of control in paintControlBackground()", GetLastError()); saved = SaveDC(dc); if (saved == 0) xpanic("error saving DC info in paintControlBackground()", GetLastError()); if (SetWindowOrgEx(dc, px, py, NULL) == 0) xpanic("error moving window origin in paintControlBackground()", GetLastError()); SendMessageW(parent, WM_PRINTCLIENT, (WPARAM) dc, PRF_CLIENT); if (RestoreDC(dc, saved) == 0) xpanic("error restoring DC info in paintControlBackground()", GetLastError()); } case WM_CTLCOLORSTATIC: case WM_CTLCOLORBTN: if (SetBkMode((HDC) wParam, TRANSPARENT) == 0) xpanic("error setting transparent background mode to Labels", GetLastError()); paintControlBackground((HWND) lParam, (HDC) wParam); *lResult = (LRESULT) hollowBrush; return TRUE;
There are several free ends:
This will not work if the immediate parent of this control is a group package; in this case, you need to check the class name and go to the parent chain.
You also need to implement WM_PRINTCLIENT in any custom AND containers in the window class.
This does not work for group box labels yet; you will see the texture drawn properly, but the line of the group group will be drawn on top of it. I will mark this as a solution when I find out and update this post with this information.
(The flicker I saw seems to be caused by the garbage collector, which is used by another part of the program, and thus is not yet controlled. It will change soon, I hope.)
Thanks, meanwhile!
source share