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.
然后m_display.AddString(s);
但是我的程序中f()是通过while循环产生字符串的,我想在字符串生成后马上把它显示在m_display中(显然在f()中是不能调用m_display变量的)而不是把生成的字符串全部放到一个变量里头等f()执行完再调用。请问有没有什么好的方法可以实现啊?m_display.AddString显示。请问有什么
设置一个定时器:SetTimer(1,100,NULL);//100毫秒一次
添加OnTimer消息响应函数:
if(1==nIDEvent)
{
m_display.AddString(s);
}
在f()函数中改变CString变量就可以了
(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.