PRB: CBS_SIMPLE ComboBox Repainting Problem

Last reviewed: September 29, 1995
Article ID: Q128110
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) version 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT version 3.5
        - Microsoft Win32s version 1.2
    

SYMPTOMS

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.

RESOLUTION

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.

Sample Code

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);
}

STATUS

This behavior is by design.

MORE INFORMAITON

Steps to Reproduce Behavior

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 reference words: 3.10 3.50 1.20
KBCategory: kbui kbcode kbprb
KBSubcategory: UsrCtl


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.