A Journey 2 Eternity

Modify the width and height of the drop down list in a combo box

Posted on: December 18, 2008

In MFC, you can simply subclass the combo-box and override the WM_CTLCOLOR message handler. This handler is used because Windows sends a message to set the colors for each of the children of the combo (the edit and the list-box), and you can easily grab the list-box HWND at this time.

HBRUSH CMyComboBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	if (nCtlColor == CTLCOLOR_LISTBOX) {
		HWND hwndList = pWnd->GetSafeHwnd() ;
		if ( hwndList != NULL ) {
			CRect rectList ;
			::GetWindowRect( hwndList, rectList ) ;
			::MoveWindow( hwndList, rectList.left, rectList.top, (rectList.right – rectList.left + EXTRA_WIDTH), rectList.bottom – rectList.top + EXTRA_HEIGHT, TRUE ) ;
		}
	}

	return CComboBox::OnCtlColor( pDC, pWnd, nCtlColor ) ;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Pages

Categories

December 2008
M T W T F S S
« Sep   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

Blog Stats

  • 26,968 hits
%d bloggers like this: