Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I paint a child window with FillRect()?
    primarykey
    data
    text
    <p>I have a main window which is created with the following styles<br> <code>WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_TABSTOP | WS_GROUP | WS_VISIBLE</code><br> and with ex-stles<br> <code>WS_EX_ACCEPTFILES | WS_EX_CONTROLPARENT | WS_EX_LEFT | WS_EX_LTRREADING</code>.</p> <p>This main window has a child window on it, which is an edit control created with styles<br> <code>WS_VISIBLE | WS_CHILD | ES_READONLY</code><br> and ex-style<br> <code>WS_EX_CLIENTEDGE</code>.</p> <p>I am going to use this edit control as a progress-bar control. I don't want to use standard Wind32 progress-bar control (<code>PROGRESS_CLASS</code>), because I want to do a some custom painting on it (e.g.; dynamically changing fill color, displaying text on it, etc).</p> <p>I can paint any region of the main window by the following code:</p> <pre><code>// hWnd: Handle of the main window case WM_PAINT: hDc = BeginPaint(hWnd, &amp;Ps); Rect = AFunctionToGetCornerThePointsOfTheEditControl(); Rect.right = Rect.left + 3 * (Rect.right - Rect.left) / 4; // Fill 3/4 (75%) of it Rect.left -= 10; // Enlarge the paint region a little Rect.top -= 10; // so that we can see it if it stays Rect.bottom += 10; // under the edit control. hBrush = CreateSolidBrush(RGB(50,100,255)); ret = FillRect(hDc, &amp;Rect, hBrush); // ret = 1 always ler = GetLastError(); // ler = 0 EndPaint(hWnd, &amp;Ps); break; </code></pre> <p>It looks like this:<br> <img src="https://i.stack.imgur.com/sZyPa.png" alt="appearance of the painted window"></p> <p>I changed this code a little to paint the child control instead:</p> <pre><code>// hWndEdit: Handle of the edit control case WM_PAINT: hDc = BeginPaint(hWndEdit, &amp;Ps); Rect = AFunctionToGetCornerThePointsOfTheEditControl(); Rect.right = Rect.left + 3 * (Rect.right - Rect.left) / 4; // Fill 3/4 (75%) of it Rect.left -= 10; Rect.top -= 10; Rect.bottom += 10; hBrush = CreateSolidBrush(RGB(50,100,255)); ret = FillRect(hDc, &amp;Rect, hBrush); // ret = 0 always ler = GetLastError(); // ler = 6 (ERROR_INVALID_HANDLE) EndPaint(hWndEdit, &amp;Ps); break; </code></pre> <p>This time it doesn't work. The main windows completely disappears as soon as I drag some part it out of the screen area, and it becomes totally unresponsive. Desktop icons under it are visible, but are not clickable.</p> <p>So, what do I have to do in order to paint the child window (the edit control)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload