对话框A的函数OnButton()调用类B的方法f(),怎么将f()执行的结果显示在对话框A的ListBox中
对话框A的函数OnButton()调用类B的方法f(),如何将f()执行的结果显示在对话框A的ListBox中
对话框A的函数OnButton()调用类B的方法f(),如何将f()执行的结果显示在对话框A的ListBox中?
注意该ListBox对应关联成员变量m_display
------解决方案--------------------
先把字符串放进CString变量s中
然后m_display.AddString(s);
------解决方案--------------------
------解决方案--------------------
I suggest you transfer the pointer of the CListBox control to B.f(), as a parameter of it, then you will be able to add strings to the list box. Also there's another method to implement the function:
(1) Declare a function pointer in class A:
typedef static void __stdcall (*ADDSTRING_TOLISTBOX) (LPVOID pA,const CString& strTxt);
(2) Define a function in class A:
static void __stdcall AddStringToListBox(LPVOID pA,const CString& strTxt)
{
CA* pDlg=(CA*)pA;
pA->m_clstBox.AddString(strTxt);
}
(3) Define b.f() in such a type:
void func(ADDSTRING_TOLISTBOX pfnAddStringToListBox, LPVOID pParam){}
(4) Call b.f() in class A:
b.f(AddStringToList,this);
I suggest you program in the second method, for a function pointer is able to deal with more situations.
对话框A的函数OnButton()调用类B的方法f(),如何将f()执行的结果显示在对话框A的ListBox中?
注意该ListBox对应关联成员变量m_display
- C/C++ code
void CADlg::OnButton(){ B b; b.f(); ... }
------解决方案--------------------
先把字符串放进CString变量s中
然后m_display.AddString(s);
------解决方案--------------------
------解决方案--------------------
I suggest you transfer the pointer of the CListBox control to B.f(), as a parameter of it, then you will be able to add strings to the list box. Also there's another method to implement the function:
(1) Declare a function pointer in class A:
typedef static void __stdcall (*ADDSTRING_TOLISTBOX) (LPVOID pA,const CString& strTxt);
(2) Define a function in class A:
static void __stdcall AddStringToListBox(LPVOID pA,const CString& strTxt)
{
CA* pDlg=(CA*)pA;
pA->m_clstBox.AddString(strTxt);
}
(3) Define b.f() in such a type:
void func(ADDSTRING_TOLISTBOX pfnAddStringToListBox, LPVOID pParam){}
(4) Call b.f() in class A:
b.f(AddStringToList,this);
I suggest you program in the second method, for a function pointer is able to deal with more situations.