Originally posted by: Daniel Smith
<p>As you've already pointed out, it's easier to simply call CComboBox::SetDroppedWidth(..) if all you want to do is make the droplist box wider than the combobox's editbox. HOWEVER, the droplist will always grow to the right-- not an ideal situation if your combobox is drawn on the right edge of a dialog.
<p>I wanted to have the droplist portion of the combo box line up with the editbox's right edge, so that the droplist grows to the left. By modifying your code, I was able to do this.
<PRE><TT><FONT COLOR="#990000"><PRE><TT><PRE><TT><PRE><TT><PRE><TT><PRE><TT><PRE><TT><PRE><TT><PRE><TT>
<font color="#009900">// TODO: Return a different brush if the default is not desired</font>
<p>Perfect results!
<p>Thanks for this code!
HBRUSH TVisualCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CComboBox::OnCtlColor(pDC, pWnd, nCtlColor);
<font color="#0000ff">switch</font> (nCtlColor) {
<font color="#0000ff">case</font> CTLCOLOR_EDIT:
<font color="#0000ff">break</font>;
<font color="#0000ff">case</font> CTLCOLOR_LISTBOX:
<font color="#0000ff">if</font> (ListWidth > 0) {
<font color="#009900">// New width of a listbox is defined</font>
CRect rect;
pWnd->GetWindowRect(&rect);
<font color="#0000ff">if</font> (rect.Width() != ListWidth) {
<B>rect.left = rect.right - ListWidth;<B>
pWnd->MoveWindow(&rect);
}
}
<font color="#0000ff">break</font>;
}
<font color="#0000ff">return</font> hbr;
}
</TT></PRE></TT></PRE></TT></PRE></TT></PRE></TT></PRE></TT></PRE></TT></PRE></TT></PRE></FONT></TT></PRE>
Originally posted by: Gorazd Kovacic
You can also change a width of a drop down list using WM_SETDROPPEDWIDTH message
Example:
::SendMessage(hwnd, WM_SETDOPPEDWIDTH, width, 0);