How can I use SetProperty(DISPID dwDispID, VARTYPE vtProp, ...) to change the
properties of a Combo Box?

During run time, I want to be able to change the Combo Box from a Drop Down
type to a Drop List type, and back again.

Assume the ID is ID_COMBO1.

Any thoughts? Can this be done? What keywords should I research?

Thanks in advance.

Re: ComboBox and SetProperty by voidcoder

voidcoder
Fri Aug 18 03:54:39 CDT 2006


Try SetWindowLong() with GWL_STYLE index. I'm not sure
CB style (Drop Down, Drop List) can be changed at runtime.

HWND hCB =3D GetDlgItem(hWndParent, ID_COMBO1);
LONG lStyle =3D GetWindowLong(hCB, GWL_STYLE);

lStyle &=3D ~CBS_DROPDOWN;
lStyle |=3D CBS_DROPDOWNLIST;

SetWindowLong(hCB, GWL_STYLE, lStyle);



On Wed, 16 Aug 2006 20:47:02 +0200, Joe <Joe@discussions.microsoft.com> =
wrote:

> How can I use SetProperty(DISPID dwDispID, VARTYPE vtProp, ...) to cha=
nge the
> properties of a Combo Box?
>
> During run time, I want to be able to change the Combo Box from a Drop=
Down
> type to a Drop List type, and back again.
>
> Assume the ID is ID_COMBO1.
>
> Any thoughts? Can this be done? What keywords should I research?
>
> Thanks in advance.
>


Re: ComboBox and SetProperty by Joe

Joe
Fri Aug 18 11:49:02 CDT 2006

Thanks voidcoder,

It took a little debugging, but I was able to make your code work with very
little modifications. Your information also guided me to some new topics to
look under in the Help (Since I come from Borland C++, MFC mentality is
counter intuitive).

I was able to call the style change at runtime, but it did not take.

I also cast the CComboBox to a CEdit control (see *Note in code), and
attempted to write my text to it that way. This works if the CComboBox has
property CBS_DROPDOWN set, but not when CBS_DROPDOWNLIST is set. No error is
thrown, which I thought was odd.

void CMainDlg::OnAlarmChange() {
int retVal = int(GWL_STYLE);
CString str;
CWnd* cbo = GetDlgItem(IDC_CBO_ALARM);
LONG lStyle = GetWindowLong(cbo->m_hWnd, retVal);
CEdit* pAlarm;
pAlarm = (CEdit*)GetDlgItem(IDC_CBO_ALARM);
pAlarm->SetWindowText(L"Testing 1, 2, 3"); // *Note
if (lStyle != 0) {
lStyle &= ~CBS_DROPDOWN;
lStyle |= CBS_DROPDOWNLIST;
SetWindowLong(cbo->m_hWnd, retVal, lStyle);
if (retVal == 0) {
str.Format(L"SetWindowLong() returned %d", GetLastError());
MessageBox(str, L"Set Error", MB_OK | MB_ICONERROR);
}
}
// other code
}


"voidcoder" wrote:

>
> Try SetWindowLong() with GWL_STYLE index. I'm not sure
> CB style (Drop Down, Drop List) can be changed at runtime.
>
> HWND hCB = GetDlgItem(hWndParent, ID_COMBO1);
> LONG lStyle = GetWindowLong(hCB, GWL_STYLE);
>
> lStyle &= ~CBS_DROPDOWN;
> lStyle |= CBS_DROPDOWNLIST;
>
> SetWindowLong(hCB, GWL_STYLE, lStyle);
>