进程通信实验报告Word文档格式.docx

上传人:b****2 文档编号:3252151 上传时间:2023-05-01 格式:DOCX 页数:36 大小:199.17KB
下载 相关 举报
进程通信实验报告Word文档格式.docx_第1页
第1页 / 共36页
进程通信实验报告Word文档格式.docx_第2页
第2页 / 共36页
进程通信实验报告Word文档格式.docx_第3页
第3页 / 共36页
进程通信实验报告Word文档格式.docx_第4页
第4页 / 共36页
进程通信实验报告Word文档格式.docx_第5页
第5页 / 共36页
进程通信实验报告Word文档格式.docx_第6页
第6页 / 共36页
进程通信实验报告Word文档格式.docx_第7页
第7页 / 共36页
进程通信实验报告Word文档格式.docx_第8页
第8页 / 共36页
进程通信实验报告Word文档格式.docx_第9页
第9页 / 共36页
进程通信实验报告Word文档格式.docx_第10页
第10页 / 共36页
进程通信实验报告Word文档格式.docx_第11页
第11页 / 共36页
进程通信实验报告Word文档格式.docx_第12页
第12页 / 共36页
进程通信实验报告Word文档格式.docx_第13页
第13页 / 共36页
进程通信实验报告Word文档格式.docx_第14页
第14页 / 共36页
进程通信实验报告Word文档格式.docx_第15页
第15页 / 共36页
进程通信实验报告Word文档格式.docx_第16页
第16页 / 共36页
进程通信实验报告Word文档格式.docx_第17页
第17页 / 共36页
进程通信实验报告Word文档格式.docx_第18页
第18页 / 共36页
进程通信实验报告Word文档格式.docx_第19页
第19页 / 共36页
进程通信实验报告Word文档格式.docx_第20页
第20页 / 共36页
亲,该文档总共36页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

进程通信实验报告Word文档格式.docx

《进程通信实验报告Word文档格式.docx》由会员分享,可在线阅读,更多相关《进程通信实验报告Word文档格式.docx(36页珍藏版)》请在冰点文库上搜索。

进程通信实验报告Word文档格式.docx

3.子进程编写

(1)发送消息

(2)读消息

三、实验结果

点击创建子进程按钮:

在创建子进程之后进行进程间的通信如下图

四、心得体会

1、从试验的角度了解了进程间是怎样利用管道进行通信的,了解了进程间通信的实际过程

2、进一步掌握了MFC的初步编程技巧,知道了怎样调试程序。

3进一步了解了,API函数的应用,明白了怎样进行界面编程。

4、进一步熟悉了在进行进程通信的编写过程中的各个细节。

六、附录

Process_Father.cpp

#include"

stdafx.h"

Process_Father.h"

//包含已编写的Process_Father.h头文件

Process_FatherDlg.h"

//包含已编写的Process_FatherDlg.h头文件

//进行宏定义

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

//创建父进程

BEGIN_MESSAGE_MAP(CProcess_FatherApp,CWinApp)

//{{AFX_MSG_MAP(CProcess_FatherApp)

//NOTE-theClassWizardwilladdandremovemappingmacroshere.

//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!

//}}AFX_MSG

ON_COMMAND(ID_HELP,CWinApp:

:

OnHelp)

END_MESSAGE_MAP()

//CProcess_FatherAppconstruction

CProcess_FatherApp:

CProcess_FatherApp()

{

//TODO:

addconstructioncodehere,

//PlaceallsignificantinitializationinInitInstance

}

//TheoneandonlyCProcess_FatherAppobject

CProcess_FatherApptheApp;

//CProcess_FatherAppinitialization

BOOLCProcess_FatherApp:

InitInstance()

AfxEnableControlContainer();

#ifdef_AFXDLL

Enable3dControls();

//CallthiswhenusingMFCinasharedDLL

#else

Enable3dControlsStatic();

//CallthiswhenlinkingtoMFCstatically

CProcess_FatherDlgdlg;

m_pMainWnd=&

dlg;

intnResponse=dlg.DoModal();

if(nResponse==IDOK)

{

//TODO:

Placecodeheretohandlewhenthedialogis

//dismissedwithOK

}

elseif(nResponse==IDCANCEL)

//dismissedwithCancel

//Sincethedialoghasbeenclosed,returnFALSEsothatweexitthe

//application,ratherthanstarttheapplication'

smessagepump.

returnFALSE;

Process_FatherDlg.cpp

//Process_FatherDlg.cpp:

implementationfile

//

/////////////////////////////////////////////////////////////////////////////

//CAboutDlgdialogusedforAppAbout

classCAboutDlg:

publicCDialog

public:

CAboutDlg();

//DialogData

//{{AFX_DATA(CAboutDlg)

enum{IDD=IDD_ABOUTBOX};

//}}AFX_DATA

//ClassWizardgeneratedvirtualfunctionoverrides

//{{AFX_VIRTUAL(CAboutDlg)

protected:

virtualvoidDoDataExchange(CDataExchange*pDX);

//DDX/DDVsupport

//}}AFX_VIRTUAL

//Implementation

protected:

//{{AFX_MSG(CAboutDlg)

DECLARE_MESSAGE_MAP()

};

CAboutDlg:

CAboutDlg():

CDialog(CAboutDlg:

IDD)

//{{AFX_DATA_INIT(CAboutDlg)

//}}AFX_DATA_INIT

voidCAboutDlg:

DoDataExchange(CDataExchange*pDX)

CDialog:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CAboutDlg)

//}}AFX_DATA_MAP

BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)

//{{AFX_MSG_MAP(CAboutDlg)

//Nomessagehandlers

//}}AFX_MSG_MAP

//CProcess_FatherDlgdialog

CProcess_FatherDlg:

CProcess_FatherDlg(CWnd*pParent/*=NULL*/)

:

CDialog(CProcess_FatherDlg:

IDD,pParent)

//{{AFX_DATA_INIT(CProcess_FatherDlg)

//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32

m_hIcon=AfxGetApp()->

LoadIcon(IDR_MAINFRAME);

voidCProcess_FatherDlg:

//{{AFX_DATA_MAP(CProcess_FatherDlg)

DDX_Control(pDX,IDC_BT_CreateChildProcess,m_BT_CreateChildProcess);

DDX_Control(pDX,IDC_Send,m_Send);

DDX_Control(pDX,IDC_LISTBOX_Record,m_LISTBOX_Record);

DDX_Control(pDX,IDC_EDIT_Message,m_EDIT_Message);

BEGIN_MESSAGE_MAP(CProcess_FatherDlg,CDialog)

//{{AFX_MSG_MAP(CProcess_FatherDlg)

ON_WM_SYSCOMMAND()

ON_WM_PAINT()

ON_WM_QUERYDRAGICON()

ON_BN_CLICKED(IDC_BT_CreateChildProcess,OnBTCreateChildProcess)

ON_BN_CLICKED(IDC_Send,OnSend)

ON_MESSAGE(WM_CHILD_SEND,OnReceiveMsg)

//CProcess_FatherDlgmessagehandlers

BOOLCProcess_FatherDlg:

OnInitDialog()

OnInitDialog();

//Add"

About..."

menuitemtosystemmenu.

//IDM_ABOUTBOXmustbeinthesystemcommandrange.

ASSERT((IDM_ABOUTBOX&

0xFFF0)==IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX<

0xF000);

CMenu*pSysMenu=GetSystemMenu(FALSE);

if(pSysMenu!

=NULL)

CStringstrAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if(!

strAboutMenu.IsEmpty())

{

pSysMenu->

AppendMenu(MF_SEPARATOR);

AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);

}

//Settheiconforthisdialog.Theframeworkdoesthisautomatically

//whentheapplication'

smainwindowisnotadialog

SetIcon(m_hIcon,TRUE);

//Setbigicon

SetIcon(m_hIcon,FALSE);

//Setsmallicon

Addextrainitializationhere

returnTRUE;

//returnTRUEunlessyousetthefocustoacontrol

OnSysCommand(UINTnID,LPARAMlParam)

if((nID&

0xFFF0)==IDM_ABOUTBOX)

CAboutDlgdlgAbout;

dlgAbout.DoModal();

else

CDialog:

OnSysCommand(nID,lParam);

//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow

//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,

//thisisautomaticallydoneforyoubytheframework.

OnPaint()

if(IsIconic())

CPaintDCdc(this);

//devicecontextforpainting

SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);

//Centericoninclientrectangle

intcxIcon=GetSystemMetrics(SM_CXICON);

intcyIcon=GetSystemMetrics(SM_CYICON);

CRectrect;

GetClientRect(&

rect);

intx=(rect.Width()-cxIcon+1)/2;

inty=(rect.Height()-cyIcon+1)/2;

//Drawtheicon

dc.DrawIcon(x,y,m_hIcon);

OnPaint();

//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags

//theminimizedwindow.

HCURSORCProcess_FatherDlg:

OnQueryDragIcon()

return(HCURSOR)m_hIcon;

OnBTCreateChildProcess()

//创建管道

SECURITY_ATTRIBUTESsa;

sa.nLength=sizeof(SECURITY_ATTRIBUTES);

sa.lpSecurityDescriptor=NULL;

sa.bInheritHandle=TRUE;

CreatePipe(&

hPipeRead,&

hPipeWrite,&

sa,0);

hPipeRead2,&

hPipeWrite2,&

//创建子进程

STARTUPINFOStartupInfo;

memset(&

StartupInfo,0,sizeof(STARTUPINFO));

StartupInfo.cb=sizeof(STARTUPINFO);

StartupInfo.dwFlags=STARTF_USESTDHANDLES;

StartupInfo.hStdInput=hPipeRead;

StartupInfo.hStdOutput=hPipeWrite;

StartupInfo.hStdError=GetStdHandle(STD_ERROR_HANDLE);

PROCESS_INFORMATIONProcessInfo;

CreateProcess("

Process_Child.exe"

NULL,NULL,NULL,TRUE,0,NULL,NULL,&

StartupInfo,&

ProcessInfo);

m_BT_CreateChildProcess.EnableWindow(FALSE);

OnSend()

CStringstr;

charss[20]="

Father:

"

;

m_EDIT_Message.GetWindowText(str);

DWORDdwWritten;

if(!

WriteFile(hPipeWrite,str,40,&

dwWritten,NULL))

MessageBox(TEXT("

写错误"

),"

警告"

MB_OK|MB_ICONWARNING);

CStringstrWinName="

Process_Child"

CWnd*pWnd=CWnd:

FindWindow(NULL,strWinName);

if(pWnd)

pWnd->

SendMessage(WM_FATHER_SEND,0,0);

strcat(ss,str);

m_LISTBOX_Record.InsertString(-1,ss);

m_EDIT_Message.SetWindowText("

);

else

MessageBox("

没有发现子进程"

"

错误"

}

OnReceiveMsg(WPARAMwParam,LPARAMlParam)

DWORDdwRead;

TCHARs[40];

HANDLEhPipeRead2;

hPipeRead2=GetStdHandle(STD_INPUT_HANDLE);

ReadFile(hPipeRead,s,40,&

dwRead,NULL))

读错误!

charstr[60]="

Child:

"

strcat(str,s);

m_LISTBOX_Record.InsertString(-1,str);

Process_Father.h

//Process_Father.h:

mainheaderfileforthePROCESS_FATHERapplication

#if!

defined(AFX_PROCESS_FATHER_H__1F9659A2_2B93_4C1E_89C5_5A88971D3DDA__INCLUDED_)

#defineAFX_PROCESS_FATHER_H__1F9659A2_2B93_4C1E_89C5_5A88971D3DDA__INCLUDED_

#if_MSC_VER>

1000

#pragmaonce

#endif//_MSC_VER>

#ifndef__AFXWIN_H__

#errorinclude'

stdafx.h'

beforeincludingthisfileforPCH

resource.h"

//mainsymbols

//CProcess_FatherApp:

//SeeProcess_Father.cppfortheimplementationofthisclass

classCProcess_FatherApp:

publicCWinApp

CProcess_FatherApp();

//Overrides

//{{AFX_VIRTUAL(CProcess_FatherApp)

public:

virtualBOOLInitInstance();

//{{AFX_MSG(CProcess_FatherApp)

//NOTE-theClassWizardwilladdandremovememberfunctionshere.

//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!

//{{AFX_INSERT_LOCATION}}

//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.

#endif//!

Process_FatherDlg.h

//Process_FatherDlg.h:

headerfile

defined(AFX_PROCESS_FATHERDLG_H__69E2942A_

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2