Brah, sub-classed WM_PAINT call to ::DrawFrameControl() with ListView's default call to ::CallWindowProcW() No-Diggity!

Anne Wilcoxen 46 Reputation points
2023-12-16T00:17:51.22+00:00

Golly-plops & turtle tops!
I’ve sub-classed a ListView with the intent of making it into my own TreeView! Jeepers!
I want it to draw this, but with the TreeView + and - marks on the left side:
User's image

To that end I’ve crafted up the following code inside the sub-class routine:

			case WM_PAINT : {
 				RECT clientRect;
 				GetClientRect(_hWnd, &clientRect);
   				PAINTSTRUCT ps;
 				HDC hdc = BeginPaint(_hWnd, &ps);
  				// Create a compatible memory DC and bitmap
 				HDC memDC = CreateCompatibleDC(hdc);
 				HBITMAP memBitmap = CreateCompatibleBitmap(hdc, clientRect.right, clientRect.bottom);
 				HBITMAP oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap);
  				  				// Now do your custom drawing on memory DC
 				RECT rcButton = {10, 50, 30, 70};
 				DrawFrameControl(memDC, &rcButton, DFC_BUTTON, DFCS_BUTTONCHECK);
  				// Call the original window procedure to draw into memory DC
   				LRESULT lrRes = CallWindowProcW(wpOrig, _hWnd, _uMsg, _wParam, (LPARAM)memDC); 
  				// Blit the memory DC to screen
 				BitBlt(hdc, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right - ps.rcPaint.left,
 					   ps.rcPaint.bottom - ps.rcPaint.top, memDC, ps.rcPaint.left, ps.rcPaint.top, SRCCOPY);

 				// Clean up
  				SelectObject(memDC, oldBitmap);
  				DeleteObject(memBitmap);
 				DeleteDC(memDC);
  				EndPaint(_hWnd, &ps);
 				return lrRes;
  			}

But instead of my dreams, I get this:
User's image

Jumpin’ Jehoshaphat!

The first issue is: What on Earth could be wrong, Daddy-O?
And the 2nd issue is: I want to draw the TreeView + and - but they are not defined. Is DFCS_BUTTONPLUS a thing? I’m only using DFCS_BUTTONCHECK for testing.

Windows development | Windows API - Win32
Developer technologies | C++
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 90,681 Reputation points
    2023-12-17T09:16:13.5066667+00:00

    In your code, you replace the default drawing with your Button

    To draw above the default drawing, you can use Custom Draw

    +/- is drawn with DrawThemeBackground when themed (TVP_GLYPH, ...) or manually with PatBlt when not themed

    Or you can use the TreeList control from rasdlg.dll :

    TreeList

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.