【发布时间】:2012-04-13 05:11:10
【问题描述】:
我正在阅读与在 windows 上使用 c++ 中的 wxwidgets 进行线程创建相关的内容,但是我无法理解以下代码的 sn-p 含义:-
以下内容是项目的一部分:-
Myfirm.cpp
My thread.h
Mythread.cpp
in Myfirm.cpp
the following code is not understood by me:-
BEGIN_EVENT_TABLE(MyFrm,wxFrame)
EVT_COMMAND(wxID_ANY, wxEVT_MYTHREAD, MyFrm::OnMyThread)
END_EVENT_TABLE()
void MyFrm::PerformCalculation(int someParameter){//not sure what is it
MyThread *thread = new Mythread(this, someParameter);
thread->Create();
thread->Run();
}
void MyFrm::OnMyThread(wxCommandEvent& event)//here also the clarity is not good
{
unsigned char* temp = (unsigned char*)event.GetClientData();
delete[] temp;
}
in this exampe what is even more confusing is that , it does not contain a main()
function
in Mythread.h
BEGIN_DECLARE_EVENT_TYPES()
DECLARE_EVENT_TYPE(wxEVT_MYTHREAD, -1)
END_DECLARE_EVENT_TYPES()
in Mythread.cpp
DEFINE_EVENT_TYPE(wxEVT_MYTHREAD)
MyThread::MyThread(wxEvtHandler* pParent, int param) : wxThread(wxTHREAD_DETACHED),
m_pParent(pParent)
{
m_param = param;
}
void* MyThread::Entry()
{
wxCommandEvent evt(wxEVT_MYTHREAD, GetId());
evt.SetInt(r);
evt.SetClientData(data);
wxPostEvent(m_pParent, evt);
return 0;
}
i am atill wondering how does the following code works and have no idea about where
where the main function is?
谢谢
【问题讨论】:
-
在 wxWidget 应用程序中,没有您自己编写的
main函数,而是包装在一个特殊的 wxWidget 宏IMPLEMENT_APP中。还有什么不明白的? wxWidget 线程是如何工作的?形式?事件?你读过手册和教程吗? -
我以这个为例在我的 qwn 项目中使用它,我知道需要定义一个像#define IMPLEMENT_APP 这样的宏,但它在这里的相关性和使用我无法猜测,也建议在这里使用它。
标签: c++ multithreading wxwidgets mutex locks