★★★★★★★★怎样使用AfxBeginThread实现界面线程(在线等待,给分)★★★★★★★★★ 如果可以,请详细说明使用过程。我将高分相送………………在线等待☆☆☆☆☆☆☆☆☆☆☆☆☆☆ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 up for mei have waiting the message for long time 很简单啊,用classwizard从CWinThread派生一个类,比如CUserThread,在它的InitInstance中创建窗口,比如:BOOL CUserThead::InitInstance(){ CFrameWnd* pWnd=new CFrameWnd; pWnd->Create(NULL,"this is a test"); pWnd->ShowWindow(SW_SHOWNORMAL); m_pMainWnd=pWnd; return TRUE;}然后就可以启动线程了:AfxBeginThread(RUNTIME_CLASS(CUserThead)); EMAIL:?给你发一个现成的工程 AfxBeginThread(RUNTIME_CLASS(CUserThead)); 届面线程AfxBeginThread((AFX_THREADPROC)(CUserThead)); 工作者线程 界面线程嘛,从CWinThread派生就行了,如何启动类似。 CWinThread* AfxBeginThread( AFX_THREADPROC pfnThreadProc, LPVOID pParam, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );这个函数用于启用worker线程,看上去是十个参数,复杂至极,其实只有两个是我们要关心的pfnThreadProc 函数名称,用来启动线程pParam 任意4字节数值,用来传给新进程,它可以是个整数,或指针,或单纯只是个0 // th.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "th.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// The one and only application objectCWinApp theApp;UINT ThreadFunc(LPVOID);using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){ int nRetCode = 0; // initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { // TODO: change error code to suit your needs cerr << _T("Fatal Error: MFC initialization failed") << endl; nRetCode = 1; } else { for(int i = 0; i < 5; i++) { if(AfxBeginThread(ThreadFunc, (LPVOID)i)) printf("Thread launched %d\n", i); } //wait for the threads to complets Sleep(2000); return 0; } return nRetCode;}UINT ThreadFunc(LPVOID n){ for(int i = 0; i < 10; i++) printf("%d%d%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n,n,n); return 0;} 结帖: 在结帖前我要感谢所有给我很都好的意见的朋友们,所以只要来者都有分。在此我特别感谢发送EMAIL源代码给我的 librastar2001,提出好的意见的webber84 ,还有在其他帖子中给我很多帮助的nonocast。 希望大家继续支持我……%…… readfile读取ReadMe.txt出现乱码,但是新建一个文本文件后,将ReadMe.txt文件里的内容复制到新建的一个文本文件,就不是乱码了。即使将这个文 VC 2005 我想把 单位编号 单位名称 存在 下拉列表中 选择单位名称 也能得到 单位编号 有关OPENDATASOURCE的问题!急..... 在动态库中添加资源 指针数组成员的访问问题.急急急~~~!!! [求助]如何排序中文字符串,按拼音! 我要用ACCESS实现数据库 CRC校验的问题? 参数的问题!非常的急呀!!! 怎么实现象VC底部那样的编译提示窗口? 关于游戏外挂,请高手帮助 一个和文件有关的问题
i have waiting the message for long time
BOOL CUserThead::InitInstance()
{
CFrameWnd* pWnd=new CFrameWnd;
pWnd->Create(NULL,"this is a test");
pWnd->ShowWindow(SW_SHOWNORMAL);
m_pMainWnd=pWnd;
return TRUE;
}
然后就可以启动线程了:AfxBeginThread(RUNTIME_CLASS(CUserThead));
给你发一个现成的工程
AfxBeginThread((AFX_THREADPROC)(CUserThead)); 工作者线程
这个函数用于启用worker线程,看上去是十个参数,复杂至极,其实只有两个是我们要关心的
pfnThreadProc 函数名称,用来启动线程
pParam 任意4字节数值,用来传给新进程,它可以是个整数,或指针,或单纯只是个0
//#include "stdafx.h"
#include "th.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// The one and only application objectCWinApp theApp;
UINT ThreadFunc(LPVOID);using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0; // initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
for(int i = 0; i < 5; i++)
{
if(AfxBeginThread(ThreadFunc, (LPVOID)i))
printf("Thread launched %d\n", i);
}
//wait for the threads to complets
Sleep(2000); return 0;
} return nRetCode;
}
UINT ThreadFunc(LPVOID n)
{
for(int i = 0; i < 10; i++)
printf("%d%d%d%d%d%d%d%d%d%d\n",n,n,n,n,n,n,n,n,n,n);
return 0;
}
在结帖前我要感谢所有给我很都好的意见的朋友们,所以只要来者都有分。
在此我特别感谢发送EMAIL源代码给我的 librastar2001,提出好的意见的webber84 ,还有在其他帖子中给我很多帮助的nonocast。
希望大家继续支持我……%……