对话框A的函数OnButton()调用类B的方法f(),怎么将f()执行的结果显示在对话框A的ListBox中

对话框A的函数OnButton()调用类B的方法f(),如何将f()执行的结果显示在对话框A的ListBox中
对话框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);
------解决方案--------------------
探讨
你的意思应该是把生成的字符串放到变量CString s中,等b.f();执行完后再执行语句m_display.AddString(s)。
但是我的程序中f()是通过while循环产生字符串的,我想在字符串生成后马上把它显示在m_display中(显然在f()中是不能调用m_display变量的)而不是把生成的字符串全部放到一个变量里头等f()执行完再调用。请问有没有什么好的方法可以实现啊?m_d……

------解决方案--------------------
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.