一、创建应用工程 1、创建单文档应用工程 2、添加新单文档应用工程 二、编辑菜单项 1、编辑 Thread工程之菜单项 2、编辑 Child工程之菜单项 三、添加变量、函数 1、添加变量 a、为 CThreadView类添加变量 b、为 CChildView类添加变量 2、添加函数 a、为 CThreadView类添加菜单消息响应函数 b、为 CChildView类添加菜单消息响应函数 四、添加代码 1、为 CThreadView类添加代码 a、添加初始化代码 CThreadView::CThreadView() { // TODO: add construction code here pipe=NULL; } CThreadView::~CThreadView() { if(pipe) CloseHandle(pipe); } b、添加消息响应函数代码 void CThreadView::OnPipeCreate() { // TODO: Add your command handler code here pipe=CreateNamedPipe("\\\\.\\pipe\\mypipe",PIPE_ACCESS_DUPLEX|FILE_FLAG_OVERLAPPED,0,1,1024,1024,0,NULL); if(INVALID_HANDLE_VALUE==pipe) { MessageBox("管道创建失败"); pipe=NULL; return; } HANDLE event; event=CreateEvent(NULL,TRUE,FALSE,NULL); if(!event) { MessageBox("事件对象创建失败"); CloseHandle(pipe); pipe=NULL; return; } OVERLAPPED overlap; ZeroMemory(&overlap,sizeof(OVERLAPPED)); overlap.hEvent=event; ConnectNamedPipe(pipe,&overlap); //等待客户端连接 WaitForSingleObject(event,INFINITE); } void CThreadView::OnPipeRead() { // TODO: Add your command handler code here char readbuf[100]; DWORD dwread; ReadFile(pipe,readbuf,100,&dwread,NULL); MessageBox(readbuf); } void CThreadView::OnPipeWrite() { // TODO: Add your command handler code here char buf[]="你好,长江!"; DWORD dwwrite; WriteFile(pipe,buf,strlen(buf)+1,&dwwrite,NULL); } 2、为 CChildView类添加代码 a、添加初始化代码 CChildView::CChildView() { // TODO: add construction code here pipe=NULL; } CChildView::~CChildView() { if(pipe) CloseHandle(pipe); } b、添加消息响应函数代码 void CChildView::OnConnect() { // TODO: Add your command handler code here WaitNamedPipe("\\\\.\\pipe\\mypipe",NMPWAIT_WAIT_FOREVER); pipe=CreateFile"\\\\.\\pipe\\mypipe",GENERIC_READ|GENERIC_WRITE,0,NU...