我看书上讲,用CWinThread可以启动一个用户界面线程,但又没给例子,不知哪位大侠能提供一个例子。因为现在做的项目中涉及到该问题,所以很急,谢谢了。
解决方案 »
- 动态去掉(隐藏)标题栏 的问题
- 小问题
- 字符指针简单问题
- 一个关于WSAAsyncSelect的奇怪问题,那位大侠援手一把
- 在datagrid中显示_RecordsetPtr记录集的问题(在线等)
- 请问如何用CSocket进行文件的传输
- 急!等待高手解救菜鸟小弟!!关于dll
- 现可以枚举出odbc数据源的名称和类别,问:如何得到该数据源的存储路径?
- vc中成员变量的使用问题,例如创建edit控键的成员变量的类型为CEdit与CString的区别
- 高手都在哪呀:如何在VC++里编写的DLL中调用另外一个DLL中的函数??
- 高位为 0x80 和 0x20 的颜色值,如何获得其 R、G、B 分量?
- MFC COM编程中,"早绑定"与"晚绑定"的问题
{
CMyDlg *pDlg=new CMyDlg;
pDlg->Create(IDD_GUIDLG,CWnd::FromHandle(GetDesktopWindow()));//指定其父窗口为桌面就正常了.
pDlg->ShowWindow(SW_SHOW);
m_pMainWnd = pDlg;
return TRUE;
}
You find your dialog resource ID from the "Dialog Properties" by entering on the Dialog resource from the keyboard or by right clicking on the dialog resource and choosing Properties from the pop op menu. Step 7:Click on class view, expand the thread class and double click on the InitInstance() function. Now we create a dialog object in this function and assign the m_pMainWnd member variable of the thread class to this object.( By doing this ,our thread class associates with a user interface object ). Add the following code into the IniInstance() function. m_pMainWnd=new CYourDialogClassName;
m_pMainWnd->SetForegroundWindow();
m_pMainWnd->ShowWindow(SW_SHOW);
Remember to include the header file of your dialog class to the currently opened file. Step 8:It will be a god idea to make an array of CWinThread pointers and assign these pointers to the created threads, so it would be easy to get our thread objects whenever necessary so open the class view, double click on the CYourProjectNameApp class and in the class definition add the following code:CWinThread* m_pThread[5];(Remember to add: extern CYourProjectNameApp theApp; at the bottom of the currently opened file, after DECLARE_MESSAGE_MAP()};)Step 9:Put a button in the main dialog window in order to create and run the user interface threads.Step 10:With this new button selected, open the class wizard by entering CTRL+W from the keyboard, and make a command handler function.Step 11:Open this newly created handler function and add the following code in order to create 5 User interface threads: for(int i=0;i<5;i++)
theApp.m_pThread[i]=AfxBeginThread(RUNTIME_CLASS(CYourThreadClassName));
(Remember to include the header file of your thread class (YourThreadClassName.h) at the top of the currently opened file)That's it, Save your project and build it .