如何检查组合框是下拉列表还是下拉列表?

fre*_*tje 2 c++ mfc combobox

有没有办法检索CComboBox的类型?

我需要知道它是"Dropdown"还是"Drop List".

我尝试过以下方法:

if (m_MyComboBox.GetStyle() & CBS_DROPDOWN)
   // do some stuff
Run Code Online (Sandbox Code Playgroud)

if (m_MyComboBox.GetStyle() & CBS_DROPDOWNLIST)
   // do some stuff
Run Code Online (Sandbox Code Playgroud)

但是无论CComboBox是下拉列表还是下拉列表,这两个表达式似乎都评估为TRUE.

Ser*_*ier 5

来自 winuser.h:

#define CBS_DROPDOWN          0x0002L
#define CBS_DROPDOWNLIST      0x0003L
Run Code Online (Sandbox Code Playgroud)

你需要:

switch(m_MyComboBox.GetStyle() & CBS_DROPDOWNLIST)
{
  case CBS_SIMPLE:
    // do stuff
    break;

  case CBS_DROPDOWN:
    // do stuff
    break;

  case CBS_DROPDOWNLIST:
    // do stuff
    break;
}
Run Code Online (Sandbox Code Playgroud)


Shi*_*C G 5

使用以下代码

if ((m_MyComboBox.GetStyle() & 3) == CBS_SIMPLE)
{
    //SIMPLE
}
if ((m_MyComboBox.GetStyle() & 3) == CBS_DROPDOWN)
{
    //DROPDOWN
}
if ((m_MyComboBox.GetStyle() & 3) == CBS_DROPDOWNLIST)
{
    //DROPDOWNLIST
}
Run Code Online (Sandbox Code Playgroud)