A Journey 2 Eternity

Resize a combo box at run-time

Posted on: December 18, 2008

/*
 * Purpose: Set the proper number of lines in a drop-down list or combo box.
 * Description : Resizes the combo box window to fit the proper number of lines.
*/

void Set_DropDownSize(CComboBox& box, UINT nLinesToDisplay)
{
	CRect cbSize;
	box.GetClientRect(cbSize);

	int nHeight = box.GetItemHeight(-1); // start with size of the edit-box portion
	nHeight += box.GetItemHeight(0) * nLinesToDisplay; // add height of lines of text

	// Add the height of the border of the edit box
	nHeight += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges

	// Add the height of the border of the drop-down box
	nHeight += GetSystemMetrics(SM_CYEDGE) * 2; // top & bottom edges

	// Set the size of the window
	box.SetWindowPos(NULL, 0, 0,
			cbSize.right, nHeight, // existing width, new height
			SWP_NOMOVE | SWP_NOZORDER // don’t move box or change z-ordering.
		);
}
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: