锐英源软件
第一信赖

精通

英语

开源

擅长

开发

培训

胸怀四海 

第一信赖

当前位置:锐英源 / 英语翻译 / 用内存映射文件、互斥和HWND_BROADCAST消息实现进程间通信
服务方向
人工智能数据处理
人工智能培训
kaldi数据准备
小语种语音识别
语音识别标注
语音识别系统
语音识别转文字
kaldi开发技术服务
软件开发
运动控制卡上位机
机械加工软件
软件开发培训
Java 安卓移动开发
VC++
C#软件
汇编和破解
驱动开发
联系方式
固话:0371-63888850
手机:138-0381-0136
Q Q:396806883
微信:ryysoft

锐英源精品开源心得,转载请注明:“锐英源www.wisestudy.cn,孙老师作品,电话13803810136。”需要全文内容也请联系孙老师。

进程间通信教程
使用内存映射文件、互斥和HWND_BROADCAST消息实现进程间通信
简介
In this tutorial I build a dialog-based application with an edit box. When the number of instances of such an application are running, changes made by the user in one edit box are reflected in all other instances. That means, all instances always have the same text in their edit box. It looks like this: 在本教程中,我建立一个基于对话框的应用程序,程序还带有一个编辑框。当应用程序实例运行时,用户在一个编辑框的输入会反映到所有其他实例。这意味着,在所有实例的编辑框中总是有相同的文字。它看起来像这样:
样品图片
Tutorial contains four steps: 教程包含四个步骤:

  • Step 1 - posting registered window message with HWND_BROADCAST parameter to notify other instances when text is changed.
  • Step 2 - using memory-mapped file to set the same text in all instances.
  • Step 3 - synchronizing access to common memory block between all instances.
  • Step 4 - advanced synchronization using inter-process Single Writer/Multiple Reader Guard. (New)
  • 第1步-当编辑框内文本修改时,以HWND_BROADCAST参数形式发送已注册的窗口消息,通知其他实例。
  • 第2步 - 在所有实例内,使用内存映射文件设置相同的文本。
  • 第3步 – 在所有实例之间同步访问共用内存块。
  • 第4步-使用跨进程的一写多读保护体进行高级同步。(

The projects are built using MFC, this allows to concentrate on interprocess communication features and not on boring implementation details. 这些项目的创建使用了MFC,这使得重点能放在进程间通信的特性上,而不是枯燥的实现细节。
第1步。通知。
On this step we build dialog-based application which notifies other instances that text in edit box is changed by user. Dialog which receives such message handles it by some way - for example, adds "*" to text in edit box. 在这个步骤中,我们建立基于对话框的应用程序,程序间有互相通知,把用户是否更改编辑框中的文本让其他实例知道。收到此消息的对话框,通过某种方式处理它 - 例如,向编辑框中添加“*”文本。

  • Create new MFC dialog-based application. Call in SameText. Remove Cancel button from dialog template; set "Close" text to IDOK button. Add edit box to dialog and set it's ID to IDC_EDIT_BOX. Arrange controls on dialog template.创建新的基于对话框的MFC应用程序。命名为SameText。从对话框模板删除“取消”按钮,IDOK按钮文本设置为“关闭”。添加编辑框到对话框上,并以 IDC_EDIT_BOX设置它的ID。排列对话框模板上的控件 。
  • Using MFC Class Wizard, add member CEdit m_edit_box to CSameTextDlg class. Member is connected to IDC_EDIT_BOX edit box.使用MFC类向导,添加成员CEdit m_edit_box到 CSameTextDlg类里。关联到IDC_EDIT_BOX 编辑框。
  • Add protected member BOOL m_bNotify to CSameTextDlg class and set it to TRUE in constructor. This member will be used in EN_CHANGE message handler to prevent program reaction when text in edit box is changed by SetWindowText and not by user.添加受保护的布尔成员m_bNotify到 CSameTextDlg类里,在构造函数内将其设置为TRUE。这名成员将用于EN_CHANGE 消息处理程序,以防止在编辑框中的文本由SetWindowText函数改变而不是由用户的输入改变时再次反应。
  • Add next constant to the start of SameTextDlg.cpp file:添加下边的常量到SameTextDlg.cpp文件开始处:
/ /注册窗口消息,当用户在编辑框中输入时发送,
const  UINT    wm_Message =
RegisterWindowMessage(_T("CC667211-7CE9-40c5-809A-1DA48E4014C4"));
  • String constant is copied using GUIDGen utility which comes with Microsoft Visual Studio.字符串常量使用GUIDGEN工具复制生成,在Microsoft Visual Studio套件里有此工具。
  • Using MFC Class Wizard, add EN_CHANGE message handler to CSameTextDlg class for IDC_EDIT_BOX control. This function is called when user changes text in edit box.使用MFC类向导,添加IDC_EDIT_BOX控件的EN_CHANGE消息处理函数到 CSameTextDlg类内。当用户修改编辑框中文本时,这个函数被调用 。
  • Add manually handling of registered window message wm_Message to CSameTextDlg class. Add OnMessageTextChanged function definition to SameTextDlg.h:向CSameTextDlg类手动添加注册窗口消息wm_Message的处理函数。在SameTextDlg.h内定义OnMessageTextChanged函数为:
/ / }} AFX_MSG
AFX_MSG LRESULT OnMessageTextChanged(WPARAM WPARAM,LPARAM lParam的);
DECLARE_MESSAGE_MAP()

Add entry to CSameTextDlg message map in SameTextDlg.cpp: 在CSameTextDlg类对应的SameTextDlg.cpp内添加消息映射入口:

/ / }} AFX_MSG_MAP
ON_REGISTERED_MESSAGE(wm_Message,OnMessageTextChanged)
END_MESSAGE_MAP() 

Add OnMessageTextChanged function to SameTextDlg.cpp: 新增OnMessageTextChanged到SameTextDlg.cpp :

LRESULT  CSameTextDlg::OnMessageTextChanged(WPARAM wParam, LPARAM lParam)
{
return 0;
} 
  • Write implementation of message handlers:写消息处理函数:
友情链接
版权所有 Copyright(c)2004-2021 锐英源软件
公司注册号:410105000449586 豫ICP备08007559号 最佳分辨率 1024*768
地址:郑州大学北校区院(文化路97号院)内