HWND   g_hWndDlg, g_hWndCombox;
BOOL CUIDemoDlg::OnInitDialog()
{
g_hWndDlg = this->m_hWnd;
g_hWndCombox = ::GetDlgItem (this->m_hWnd, IDC_COMBO_BTDEV);((CComboBox*)g_hWndCombox)->InsertString(0, L"11111");

((CComboBox*)g_hWndCombox)->AddString(L"11111");<----这样 OK
}-------换一种以下形式,不行,为什么?-----------------------------void CSR_insertRecord(const char* szName, uint16 nId)
{g_hWndCombox = ::GetDlgItem (g_hWndDlg , IDC_COMBO_BTDEV);((CComboBox*)g_hWndCombox)->InsertString(0, L"11111");

((CComboBox*)g_hWndCombox)->AddString(L"11111");<----这样 不行,为什么,要如何改?
}

解决方案 »

  1.   

    void CSR_insertRecord(const char* szName, uint16 nId)
    =======
    这个是全局函数吧,肯定不行。
      

  2.   

    你的g_hWndCombox是HWND,你怎么强制转成了CComboBox*指针了
    要转也不是这样啊
    用CWnd::FromHandle()/FromHandlePermanent()得到CWnd*指针,再强制转成CComboBox*指针
      

  3.   


    void CSR_insertRecord(const char* szName, uint16 nId)
    {
       g_hWndCombox = ::GetDlgItem (g_hWndDlg , IDC_COMBO_BTDEV);
       ((CComboBox*)g_hWndCombox)->InsertString(0, L"11111");
       或
       ((CComboBox*)g_hWndCombox)->AddString(L"11111");
       <----这样 不行,为什么,要如何改?}
    }void CSR_insertRecord(const char* szName, uint16 nId)
    {
       g_hWndCombox = ::GetDlgItem (g_hWndDlg , IDC_COMBO_BTDEV);
       SetWindowText(g_hWndCombox, str);
       <---这样可以, 为什么?}
      

  4.   

    好像看过一篇文章,大概意思是:
            Edit Static 是简单控件, 直接GetDlgItem(ID..)得到句柄后, 可直接操作赋值等.
            Combobox ListControl 是复合控件, 要Create后, 得到句柄, 再操作赋值等.请知情者指正.