ID: Q128110
The information in this article applies to:
- Microsoft Windows NT version 3.5
When a CBS_SIMPLE combo box has a WS_CLIPCHILDREN parent, the area below the edit control and left to the list box is not repainted correctly. This problem exists for 16-bit as well as 32-bit applications.
To work around this problem, subclass the combo box, calculate the blank area, and then repaint to the desired color.
The following ComboBox subclass procedure is written for a 16-bit application, but you can use the same idea in 32-bit applications.
LRESULT CALLBACK NewComboProc(
HWND hWnd,
UINT uMessage,
WPARAM uParam,
LPARAM lParam)
{
HDC myDC;
HPEN hPen, hOldPen;
HBRUSH hBrush;
HBRUSH hOldBrush;
COLORREF myColor=RGB(255,255,255); //It can be any color. Here
//the area is painted white.
HWND hEdit, hList;
RECT comboRect, editRect, listRect;
char *wndClassName="Edit";
if (uMessage == WM_PAINT)
{
CallWindowProc(lpfnOldComboProc, hWnd, uMessage, uParam,
lParam);
myDC = GetDC(hWnd);
hBrush = CreateSolidBrush(myColor);
hPen = CreatePen (PS_SOLID, 1, myColor);
hOldBrush = SelectObject(myDC, hBrush) ;
hOldPen = SelectObject(myDC, hPen);
//This code obtains the handle to the edit control of the
//combobox.
hEdit = GetWindow(hWnd, GW_CHILD);
GetClassName (hEdit, wndClassName, 10);
if (!lstrcmp (wndClassName, "Edit"))
hList=GetWindow(hEdit, GW_HWNDNEXT);
else
{
hList=hEdit;
hEdit=GetWindow(hList, GW_HWNDNEXT);
}
//The dimensions of the Edit Control, ListBox control and
//the Combobox are calculated and then used
//as the base dimensions for the Rectangle() routine.
GetClientRect (hWnd, &comboRect);
GetClientRect (hEdit, &editRect);
GetClientRect (hList, &listRect);
Rectangle (myDC,
comboRect.left,
editRect.bottom,
comboRect.right-listRect.right,
comboRect.bottom);
//Also paint the gap, if any exists, between the bottom
//of the listbox and the bottom of the ComboBox rectangle.
Rectangle (myDC,
comboRect.right-listRect.right,
editRect.bottom +
listRect.bottom,
comboRect.right,
comboRect.bottom);
DeleteObject(SelectObject(myDC, hOldBrush)) ;
DeleteObject(SelectObject(myDC, hOldPen)) ;
ReleaseDC(hWnd, myDC);
return TRUE;
}
return CallWindowProc(lpfnOldComboProc, hWnd, uMessage, uParam,
lParam);
}
This behavior is by design.
To reproduce this behavior, use AppStudio to create a dialog with the WS_CLIPCHILDREN style, put a CBS_SIMPLE combobox in the dialog, and click the test button so you can test the dialog. Then move something on top of the dialog, and move the object on top of the combobox away. You can then see that area to the left of the listbox is not repainted correctly.
Additional query words:
Keywords : kbComboBox kbCtrl kbNTOS350 kbGrpUser kbWinOS310
Issue type : kbprb
Last Reviewed: January 2, 1999