//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"));
}
请教各大侠帮忙啊.我已经试了好几个小时,未果啊.
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"));
}
请教各大侠帮忙啊.我已经试了好几个小时,未果啊.
解决方案 »
- 求一个VS2005的小例子,实现从麦克风对声音的捕捉并能即使听到
- PreTranslateMessage和ProcessMessageFilter 在处理消息中有什么区别
- 问一个有关WebBrowser控件的问题
- 请教:C++语法
- 有关于在树形控件中的图标背景和拖放的问题
- 请教一个关于APS.NET的调试问题(大送分)
- cmschart问题,高手帮忙
- 在TURBOC下如何将光标回到左上角?PRINTF(?)
- ADO问题??????????????????????
- 如何使数据窗口,只能增加数据,而不能修改和删除?
- WEBBROWER 如何截获request.send 引发的请求 和 接受?
- 浏览器的问题!狂晕!!!
SendDlgItemMessage(IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)"多功能电法接收机");如果不用MFC
::SendDlgItemMessage(m_hWnd,IDC_LIST_2WHOM,LB_INSERTSTRING,0,(LPARAM)"多功能电法接收机");
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("多功能电法接收机"));却不行呢?
==============================
重新派生一个类,在里面实现按钮操作看行不行。
如下:
afx_msg void OnSendMsg(); ON_COMMAND(IDC_SEND,&CMainFrame::OnSendMsg);现在是:假如各位是我,要实现以上功能要如何实现呢?
就是说,就是我想在我创建的最对话条(里面有设计好的编辑框,列表框)中,如何控制列表框,比如我现在要实现的增加列表框项目. 如何实现呢
#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);
}
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;
}
CListBox *lst=(CListBox*)(pMainFrame->m_wndCommPanel.GetDlgItem(IDC_LIST_2WHOM)); 试试吧,先找到主窗体,再找你要的LIST
我在自己这里试了可以
CMainFrame* pMainFrame = (CMainFrame *)GetParentFrame();
CListBox *lst=(CListBox*)(pMainFrame->m_wndCommPanel.GetDlgItem(IDC_LIST_2WHOM)); ASSERT(::IsWindow())处,感觉很奇怪。。
按up_down 所说的做,也能解决问题,但问题是其实我是想在创建后就
加入项目:多功能电法接收机,专用信号发生器,而不是点了某个按纽后,该放在哪儿呢?(假如按up_down建议的那样)
CListBox *lst=(CListBox*)m_wndCommPanel .GetDlgItem (IDC_LIST_2WHOM);
lst-> ResetContent ();
lst-> AddString (_T("多功能电法接收机"));
lst-> AddString (_T("专用信号发生器"));
用重载DialogBar的方法也可以用同样的方法AddString。
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;
}