Article ID: 131845
Article Last Modified on 7/11/2005
65881 The Parts of a Windows Combo Box and How They Relate
81707 WM_CTLCOLOR Processing for Combo Boxes of All Styles
// Global declarations.
LRESULT CALLBACK NewComboProc (HWND hWnd, UINT message, WPARAM
wParam, LPARAM lParam ); // prototype for the combo box subclass proc
HANDLE hInst; // Current app instance.
BOOL bFirst; // A flag.
// Dialog procedure for the dialog containing the combo box.
BOOL __export CALLBACK DialogProc(HWND hDlg, UINT message, WPARAM
wParam, LPARAM lParam)
{
FARPROC lpfnNewComboProc;
switch (message)
{
case WM_INITDIALOG:
bFirst = TRUE; // Set flag here - see below for usage.
// Subclass the combo box.
lpfnOldComboProc = (FARPROC ) SetWindowLong (
GetDlgItem ( hDlg, IDC_COMBO1 ),
GWL_WNDPROC,
(LONG)NewComboProc );
break;
case WM_DESTROY:
(FARPROC ) SetWindowLong ( GetDlgItem ( hDlg, IDC_COMBO1 ),
GWL_WNDPROC,
(LONG)lpfnOldComboProc );
break;
default:
break;
}
return FALSE;
} // End dialog proc.
// Combobox subclass proc.
LRESULT CALLBACK NewComboProc (HWND hWnd, UINT message, WPARAM
wParam, LPARAM lParam );
{
static HWND hwndList;
static RECT rectList;
#ifdef WIN16
if ( WM_CTLCOLOR == message) // Combo controls are to be painted.
#else
if ( WM_CTLCOLORLISTBOX == message ) // 32 bits has new message.
#endif
{
// Is this message for the list box control in the combo?
#ifdef WIN16
if (CTLCOLOR_LISTBOX==HIWORD (lParam) ) // Need only for 16 bits.
{
#endif
// Do only the very first time, get the list
// box handle and the list box rectangle.
// Note the use of GetWindowRect, as the parent
// of the list box is the desktop window
if ( bFirst )
{
#ifdef WIN16
hwndList = LOWORD (lParam );
#else
hwndList = (HWND) lParam ; // HWND is 32 bits.
#endif
GetWindowRect ( hwndList, &rectList );
bFirst = FALSE;
}
// Resize listbox window cx by 50 (use your size here).
MoveWindow ( hwndList, rectList.left, rectList.top,
( rectList.right - rectList.left + 50 ),
rectList.bottom - rectList.top, TRUE );
#ifdef WIN16
}
#endif
}
// Call original combo box procedure to handle other combo messages.
return CallWindowProc ( lpfnOldComboProc, hWnd, message,
wParam, lParam );
}
Keywords: kbcombobox kbctrl kbhowto KB131845