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);
>