在使用WTL的CComboBoxEx时,InsertItem之后,运行程序,ComboBox显不了问题,其原因如下:
I guess you want to place combo box to dialog template.
Your combo box will collaborate :-) under the next conditions:
1. A "ComboBoxEx32" class must be initialized by calling
the InitCommonControlsEx function, specifying ICC_USEREX_CLASSES
in the accompanying INITCOMMONCONTROLSEX structure:
#if (_WIN32_IE >= 0x0300)
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(iccx);
iccx.dwICC = ICC_USEREX_CLASSES;
BOOL bRet = ::InitCommonControlsEx(&iccx);
bRet;
ATLASSERT(bRet);
#else
::InitCommonControls();
#endif
2. In the resource script file your control will descripted approximately as
"CONTROL "Combo1", IDC_COMBO1, "ComboBoxEx32",
CBS_DROPDOWN | WS_TABSTOP, 7, 77, 56, 41"
This description generated by wizard, if you put up "Customize control"
to your dialog and type WC_COMBOBOXEX in the Class property.
来自[http://tech.groups.yahoo.com/group/wtl/message/388]
产生这种问题原因在于:
在vs2010中,使用工具箱中的CComboBox不能代替CComboBoxEx,而应使用Custom Control,同时将其属性设置类似于CComboBox(但不同)。
其在资源文件中差别对比如下:
CONTROL "", IDC_COMBO1,"ComboBoxEx32", CBS_DROPDOWN | WS_TABSTOP, 7,144,100,58
COMBOBOX IDC_COMBO2, 7,144,100,30, CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
其中上面为CComboBoxEx在资源文件中的定义,下面为对应CComboBox在资源中的文件中定义。
因工具箱不支持定义CComboBoxEx,故只能修改资源文件中的定义。
另外,要设置其合适的大小,下列框才能显示正常。