int CDdddddDlg::SetStyle(int Style)
{
  //IDC_COMBO_BRANCHCODE 组合框ID

     DWORD  theStyle; 
     HWND  theChild;     theChild  =  ::GetWindow( GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd ,GW_CHILD);  
    theStyle = GetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE);  


if (Style == 0 )//可写
{
::SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, CBS_DROPDOWN , theStyle);  

::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
        0,
        0, 
        0, 
        0, 
        0,
        SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE); theStyle  &=  ~CBS_DROPDOWNLIST;// 去掉DROPDOWNLIST
theStyle  |=  CBS_DROPDOWN ; //添加DROPDOWN
::DestroyWindow(theChild);  
//  SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle); 
SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle); 
::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,
        NULL,
        0, 
        0, 
        0, 
        0,
        SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);
return 0;



if (Style == 1)//只读
{
::SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, CBS_DROPDOWNLIST , theStyle);  
  ::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
        NULL,
        0, 
        0, 
        0, 
        0,
        SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE);
      theStyle  &=  ~CBS_DROPDOWN ;//去掉DROPDOWN  
        theStyle  |= CBS_DROPDOWNLIST  ; //添加DROPDOWNLIST 
 
   
      ::DestroyWindow(theChild);  
        SetWindowLong(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd, GWL_STYLE , theStyle);
::SetWindowPos(GetDlgItem(IDC_COMBO_BRANCHCODE)->m_hWnd,//使SetWindowLong生效
        NULL,
        0, 
        0, 
        0, 
        0,
        SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOZORDER | SWP_NOMOVE); 
return 1;
}
return -1;
}

解决方案 »

  1.   

    EnableWindow(false);
    EnableWindow(true);
      

  2.   

    EnableWindow(false); 
    EnableWindow(true);
    不行啊。EnableWindow(false);这样的话用户就不能下拉,来看组合框里面的东西了。
      

  3.   

    用FindWindowEx获取ComboBox中的Edit子控件,用EnableWindow控制Edit子控件试试。
      

  4.   

    EnableWindow嘛,用EmunChildWindow查找Edit控件的句柄
      

  5.   

    //把Edit控件修改为只读和非只读属性
    //如果完全想和Combox控件一样,就得自己派生新类了,因为不同的Style在Comcobox创建时创建不同的子控件BOOL CALLBACK EnumComboboxEditChildProc(
      HWND hwnd,      // handle to child window
      LPARAM lParam   // application-defined value
    )
    {
      CEdit *pEdit = (CEdit *)CWnd::FromHandle(hwnd);
      pEdit->SetReadOnly(lParam);
      return false;
    }EnumChildWindows(m_ComboBox.m_hWnd, EnumComboboxEditChildProc, b_ReadOnly);