在vc++ 中 的 GUI 里面 只要 有 窗口句柄 那么就可以 在 进程内任何 地方 sendMessage/postmessage 通知 窗口
那么 在 codeblocks + wxWidgets 环境中 一个 工作 线程 类 如何 发送消息 通知 窗口 类
Code: Select all
//这个 函数中 的 wxEvtHandler 要如何 确定?????
inline void wxQueueEvent(wxEvtHandler *dest, wxEvent *event)
{
wxCHECK_RET( dest, "need an object to queue event for" );
dest->QueueEvent(event);
}
Code: Select all
class myFram public wxFrame
{
....其他代码 和 事件初始化....
void myFram ::OnShowLog(wxCommandEvent& event)
{
showLog(event.GetString());
}
void myFram ::showLog(wxString &txt)
{
ListBox1->Append(txt);
return;
}
void SyncFrame::OnButton1Click(wxCommandEvent& event)
{
wxCommandEvent evn(wxEVT_SHOWLOG);
evn.SetString(wxT("myFrame Success"));
QueueEvent(evn.Clone());
work wor((wxApp*)this);//传入 this 指针
wor.Output(wxT("work Success"))//---------------------------------------------问题所在-----------------------------------
}
}
//另一个CPP 不是 界面类
class work
{
............
//解决 办法 就是 在这里 添加了 一个 wxApp指针
work::work(wxApp * pApp):
mApp(pApp)
{
}
void Output(wxString &Str)//错误 在 这里 ----执行 后 并没有 显示 信息 到 列表控件上 求 问题 解决办法
{
//修改的代码
if(mApp)
{
wxCommandEvent evn(wxEVT_SHOWLOG);
evn.SetString(str);
mApp->QueueEvent(evn.Clone());///这改这样既可
}
//原来的代码
//wxCommandEvent evn(wxEVT_SHOWLOG);
//evn.SetString(str);
//wxTheApp->QueueEvent(evn.Clone());
}
wxApp *mApp;
}