//CMainFrame.h     

CDialogBar m_wndCommPanel;
//CMainFrame.cpp
void CMainFrame::OnSendMsg ()
{
       CListBox *lst=(CListBox*)m_wndCommPanel .GetDlgItem (IDC_LIST_2WHOM);
//ASSERT(lst);
//CListBox*lst=(CListBox*)m_wndCommPanel.GetDescendantWindow (IDC_LIST_2WHOM);也不行啊         //HWND hwnd=this->m_wndCommPanel .GetSafeHwnd ();//还不行啊.
//HWND hList=::GetDlgItem (hwnd,IDC_LIST_2WHOM);
//lst=(CListBox*)this->FromHandle (hList); lst->ResetContent ();
lst->AddString (_T("多功能电法接收机"));
lst->AddString (_T("专用信号发生器"));
lst->InsertString (0,_T("alsddksf"));
}
请教各大侠帮忙啊.我已经试了好几个小时,未果啊.

解决方案 »

  1.   

    意思是什么?仅仅插入几行字么,这样就可以了
    SendDlgItemMessage(IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)"多功能电法接收机");如果不用MFC
    ::SendDlgItemMessage(m_hWnd,IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)"多功能电法接收机");
      

  2.   

    OnSendMsg函数是什么情况下被调用的?
      

  3.   

    调试看看你的m_wndCommPanel 和lst的值
      

  4.   

    OnSendMsg 是在我点了对话条上的按纽后.
      

  5.   

    换言之,就是我想在我创建的最对话条(里面有设计好的编辑框,列表框)中,如何控制列表框,比如我现在要实现的增加列表框项目.
    OnSendMsg()
    中的
             m_wndCommPanel.UpdateData ();
    CString msg;
    CEdit *pEdit=(CEdit*)this->m_wndCommPanel .GetDlgItem (IDC_EDIT_CMD);
    //pEdit->SetWindowTextW (_T("just test"));
    pEdit->GetWindowTextW (msg);
    ::AfxMessageBox (msg);
    能实现,为什么
        列表框中的
    CListBox *lst=(CListBox*)m_wndCommPanel .GetDlgItem (IDC_LIST_2WHOM);
    //ASSERT(lst);
    //CListBox*lst=(CListBox*)m_wndCommPanel.GetDescendantWindow (IDC_LIST_2WHOM);
    lst->ResetContent ();
    lst->AddString (_T("多功能电法接收机"));
    lst->AddString (_T("专用信号发生器"));
    lst->InsertString (0,_T("alsddksf"));
    this->RecalcLayout ();
    //::SendDlgItemMessage(hwnd,IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)_T("多功能电法接收机"));却不行呢?
      

  6.   

    CDialogBar   m_wndCommPanel; 
    ==============================
    重新派生一个类,在里面实现按钮操作看行不行。
      

  7.   

    OnSendMsg我是通过自定义消息实现的.
    如下:
    afx_msg void OnSendMsg(); ON_COMMAND(IDC_SEND,&CMainFrame::OnSendMsg);现在是:假如各位是我,要实现以上功能要如何实现呢?
    就是说,就是我想在我创建的最对话条(里面有设计好的编辑框,列表框)中,如何控制列表框,比如我现在要实现的增加列表框项目.   如何实现呢
      

  8.   

    //add mydialogbar.h
    #include "resource.h"
    class CMyDialogBar : public CDialogBar
    {
    // Construction
    public:
    BOOL Create(CWnd* pParentWnd, UINT nIDTemplate,UINT nStyle);
    CMyDialogBar(CWnd* pParent = NULL);   // standard constructor
    // Dialog Data
    //{{AFX_DATA(CMyDialogBar)
    enum { IDD = IDD_DIALOG1 };
    // NOTE: the ClassWizard will add data members here
    //}}AFX_DATA
    // Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(CMyDialogBar)
    protected:
    //}}AFX_VIRTUAL
    // Implementation
    protected: // Generated message map functions
    //{{AFX_MSG(CMyDialogBar)
    afx_msg void OnButton1();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };
    //add mydialogbar.cpp
    #include "stdafx.h"
    #include "MyDialogBar.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    CMyDialogBar::CMyDialogBar(CWnd* pParent /*=NULL*/)
    : CDialogBar(/*CMyDialogBar::IDD, pParent*/)
    {
    }
    BEGIN_MESSAGE_MAP(CMyDialogBar, CDialogBar)
    //{{AFX_MSG_MAP(CMyDialogBar)
    ON_BN_CLICKED(IDC_SEND, OnButton1)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    BOOL CMyDialogBar::Create(CWnd *pParentWnd, UINT nIDTemplate, UINT nStyle)
    {
        return CDialogBar::Create(pParentWnd,nIDTemplate,nStyle,nIDTemplate);
    }
    void CMyDialogBar::OnButton1() 
    {
    CListBox   *lst=(CListBox*)GetDlgItem(IDC_LIST_2WHOM); 
    lst-> ResetContent   (); 
    lst-> AddString   (_T("多功能电法接收机")); 
    lst-> AddString   (_T("专用信号发生器")); 
    lst-> InsertString   (0,_T("alsddksf"));   
    }
    //CMainFrame.h   
    CMyDialogBar   m_wndCommPanel;
     //CMainFrame.cpp
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    .......
    if (!m_wndCommPanel.Create(this, IDD_DIALOG1, CBRS_LEFT))
    {
    TRACE0("Failed to create dialog bar\n");
    return -1;      // fail to create
    }    //m_wndCommPanel
    .....
         m_wndCommPanel.SetBarStyle(m_wndToolBar.GetBarStyle() |
                CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
             m_wndCommPanel.EnableDocking(CBRS_ALIGN_ANY);
             DockControlBar(&m_wndCommPanel);
    return 0;
    }  
    BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
    {
    // TODO: Add your specialized code here and/or call the base class
        if(m_wndCommPanel.OnCmdMsg(nID,   nCode,   pExtra,   pHandlerInfo))   
                      return   TRUE;   
              //return   CFrameWnd::OnCmdMsg(nID,   nCode,   pExtra,   pHandlerInfo);  
    return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
    }
      

  9.   

    你再把CMainFrame::OnCreate函数中的代码贴出来看看。
      

  10.   

    //.H
    CDialogBar m_wndCommPanel;
    afx_msg void OnSendMsg();
    //.CPP
    BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    ON_WM_CREATE()
    ON_COMMAND(IDC_SEND,&CMainFrame::OnSendMsg)
    ON_COMMAND(ID_HIDE_COMMPANEL, &CMainFrame::OnHideCommpanel)
    END_MESSAGE_MAP()void CMainFrame::OnSendMsg ()
    {
    /*
    HWND hwnd=this->m_wndCommPanel .GetSafeHwnd ();
    //HWND hList=::GetDlgItem (hwnd,IDC_LIST_2WHOM);
    //lst=(CListBox*)this->FromHandle (hList);
    CListBox *lst=(CListBox*)m_wndCommPanel .GetDlgItem (IDC_LIST_2WHOM);
    //ASSERT(lst);
    //CListBox*lst=(CListBox*)m_wndCommPanel.GetDescendantWindow (IDC_LIST_2WHOM);
    lst->ResetContent ();
    lst->AddString (_T("多功能电法接收机"));
    lst->AddString (_T("专用信号发生器"));
    lst->InsertString (0,_T("alsddksf"));
    this->RecalcLayout ();
    ::SendDlgItemMessage(hwnd,IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)_T("多功能电法接收机"));//也不行!!!
    */
    m_wndCommPanel.UpdateData ();
    CString msg;
    CEdit *pEdit=(CEdit*)this->m_wndCommPanel .GetDlgItem (IDC_EDIT_CMD);
    //pEdit->SetWindowTextW (_T("just test"));
    pEdit->GetWindowTextW (msg);
    ::AfxMessageBox (msg);
    }CMainFrame::OnCreate()中只加了如下:
    if(!this->m_wndCommPanel .Create (this,IDD_COMM_PANEL,
    CBRS_ALIGN_BOTTOM,AFX_IDW_DIALOGBAR+2))
    {
    TRACE0("未能创建消息对话栏");
    return -1;
    }
      

  11.   

    CMainFrame* pMainFrame = (CMainFrame *)GetParentFrame();
    CListBox   *lst=(CListBox*)(pMainFrame->m_wndCommPanel.GetDlgItem(IDC_LIST_2WHOM)); 试试吧,先找到主窗体,再找你要的LIST
    我在自己这里试了可以
      

  12.   

    看来只剩一种可能了,就是你的ListBox属性有问题,看看是不是设置了LBS_NODATA属性。
      

  13.   

    属性中has strings 和no data 的所有可以的组合都试过了,就是不行啊。
      

  14.   

    现在有点奇怪了,我用了dabie 的代码后:
    CMainFrame* pMainFrame   =   (CMainFrame   *)GetParentFrame(); 
    CListBox *lst=(CListBox*)(pMainFrame->m_wndCommPanel.GetDlgItem(IDC_LIST_2WHOM));  ASSERT(::IsWindow())处,感觉很奇怪。。
      

  15.   

    你这样试一下,在资源中把ListBox删掉,再重新添加一个,完全用默认属性,先看看有没有问题,如果没问题再逐一修改你要的属性。
      

  16.   

    按楼上cnzdgs 所言问题终于解决了!!!非常感谢!!!
    按up_down 所说的做,也能解决问题,但问题是其实我是想在创建后就
    加入项目:多功能电法接收机,专用信号发生器,而不是点了某个按纽后,该放在哪儿呢?(假如按up_down建议的那样)
    CListBox   *lst=(CListBox*)m_wndCommPanel   .GetDlgItem   (IDC_LIST_2WHOM); 
    lst-> ResetContent   (); 
    lst-> AddString   (_T("多功能电法接收机")); 
    lst-> AddString   (_T("专用信号发生器")); 
      

  17.   

    加在CMainFrame::OnCreate中m_wndCommPanel.Create之后。
      

  18.   

    不是,我是说按up_down说的做的话,该怎么做呢?
      

  19.   

    你的问题是ListBox的风格问题,无论是在Frame中响应事件还是重载DialogBar都必须设对风格才行能解决。
    用重载DialogBar的方法也可以用同样的方法AddString。
      

  20.   

    手动
    mydialogbar.h 
    //}}AFX_MSG
    afx_msg LONG OnInitDialog(UINT,LONG); //add 
    DECLARE_MESSAGE_MAP()
    mydialogbar.cpp
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_INITDIALOG, OnInitDialog) //add
    END_MESSAGE_MAP()LONG CMyDialogBar::OnInitDialog ( UINT wParam, LONG lParam)
    {
    LONG LRet = HandleInitDialog(wParam, lParam);
    CListBox   *lst=(CListBox*)GetDlgItem(IDC_LIST_2WHOM); 
    lst-> ResetContent   (); 
    lst-> AddString   ("多功能电法接收机"); 
    lst-> AddString   ("专用信号发生器"); 
    lst-> InsertString   (0,"alsddksf");   
    return LRet;
    }
      

  21.   

    <a herf="http://www.mmimm.com" />