第二个demo.
/*******************************************************
*
* deom2---四个线程同时写一个文件( 有参数 )
*
*
***********************************************************/
#i nclude <windows.h>
#i nclude <process.h> /* _beginthread, _endthread */
#i nclude <iostream>
#i nclude <fstream>
#i nclude <string>
using namespace std;
ofstream out("out.txt");
void ThreadFunc1(PVOID param)
{
while(1)
{
char *p;
p=(char *) param;
Sleep(10);
out<<p<<"This was draw by thread l"<<endl;
}
}
void ThreadFunc2(PVOID param)
{
while(1)
{
Sleep(10);
out<<"This was draw by thread 2"<<endl;
}
}
void ThreadFunc3(PVOID param)
{
while(1)
{
Sleep(10);
out<<"This was draw by thread 3"<<endl;
}
}
void ThreadFun(PVOID param)
{
while(1)
{
Sleep(10);
out<<"This was draw by thread 4"<<endl;
}
}
int main()
{
char *pstr=" 参数传递成功";
_beginthread(ThreadFunc1,0,pstr);
_beginthread(ThreadFunc2,0,NULL);
_beginthread(ThreadFunc3,0,NULL);
_beginthread(ThreadFun,0,NULL);
Sleep(1000);
out<<"end";
return 0;
}
// demo2 end ------------------------------------------------
第三个demo( 一个win32 应用程序 )
/*******************************************************
*
* deom3--- 在屏幕上随机画出一系列矩形
*
*
***********************************************************/
#i nclude <windows.h>
#i nclude <process.h>
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
HWND hwnd ;
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-49702-6.html
却患了重病
成功了