// ShareMemDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ShareMem.h"
#include "ShareMemDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShareMemDlg dialog
CShareMemDlg::CShareMemDlg(CWnd* pParent /*=NULL*/)
: CDialog(CShareMemDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CShareMemDlg)
m_strServer = _T("在此输入的内容将被拷贝到内存共享区");
m_strClient = _T("在此显示共享内存去的内容");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CShareMemDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShareMemDlg)
DDX_Control(pDX, IDC_BUTTON_SETCUSTOM, m_setcustom);
DDX_Control(pDX, IDC_BUTTON_DEFAULT, m_default);
DDX_Control(pDX, IDC_BUTTON_CUSTOM, m_custom);
DDX_Text(pDX, IDC_EDIT_SERVER, m_strServer);
DDX_Text(pDX, IDC_EDIT_CLIENT, m_strClient);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShareMemDlg, CDialog)
//{{AFX_MSG_MAP(CShareMemDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_DEFAULT, OnButtonDefault)
ON_EN_CHANGE(IDC_EDIT_SERVER, OnChangeEditServer)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON_SETCUSTOM, OnButtonSetcustom)
ON_BN_CLICKED(IDC_BUTTON_CUSTOM, OnButtonCustom)
ON_BN_CLICKED(IDC_BUTTON_RUNAG, OnButtonRunag)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShareMemDlg message handlers
BOOL CShareMemDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
m_custom.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CShareMemDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CShareMemDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CShareMemDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CShareMemDlg::OnChangeEditServer()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData();
//更新共享内存块数据
char *p = (char*)m_SFMS.GetBuffer();
if (p) strcpy(p, LPCTSTR(m_strServer));
}
void CShareMemDlg::OnButtonDefault()
{
// TODO: Add your control notification handler code here
//获取共享内存块数据
CSFMClient SFMC;
char *p = (char*)SFMC.GetBuffer();
if (p) m_strClient = p;
UpdateData(FALSE);
}
void CShareMemDlg::OnCancel()
{
// TODO: Add extra cleanup here
// CDialog::OnCancel();
}
void CShareMemDlg::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CShareMemDlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
CDialog::OnClose();
CDialog::OnOK();
}
void CShareMemDlg::OnButtonSetcustom()
{
// TODO: Add your control notification handler code here
m_strServer = "";
m_strClient = "";
UpdateData(FALSE);
m_SFMS.Create(NULL, "_ZZZ_OBJ_", 1);
m_custom.EnableWindow(TRUE);
m_default.EnableWindow(FALSE);
m_setcustom.EnableWindow(FALSE);
}
void CShareMemDlg::OnButtonCustom()
{
// TODO: Add your control notification handler code here
CSFMClient SFMC;
SFMC.Open(FILE_MAP_READ|FILE_MAP_WRITE, "_ZZZ_OBJ_");
char *p = (char*)SFMC.GetBuffer();
if (p) m_strClient = p;
UpdateData(FALSE);
}
void CShareMemDlg::OnButtonRunag()
{
// TODO: Add your control notification handler code here
CString strName;
::GetModuleFileName(NULL, strName.GetBuffer(256), 256);
//strName.ReleaseBuffer(-1);
STARTUPINFO si = {sizeof(si)};
PROCESS_INFORMATION pi = {NULL, NULL, 0, 0};
::CreateProcess(
strName,
NULL,
NULL,
NULL,
FALSE,
0,
NULL,
NULL,
&si,
&pi
);
}
void CShareMemDlg::OnButton1()
{
// TODO: Add your control notification handler code here
//CSFMServer *pCSFMS = new CSFMServer("c:\\obj_zzz.mem", "_OBJ_ZZZ_", 0);
CSFMServer *pCSFMS = new CSFMServer("c:\\obj_zzz.mem", "_OBJ_ZZZ_", 1);
char *p = (char*)pCSFMS->GetBuffer();
if (p)
{
strcpy(p, "1234567890");
::AfxMessageBox(p);
}
//delete pCSFMS;//不要释放
}
void CShareMemDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CSFMClient *pCSFMC = new CSFMClient(FILE_MAP_READ, "_OBJ_ZZZ_");
char *p = (char*)pCSFMC->GetBuffer();
if (p) strcpy(p, "1234567890");
delete pCSFMC;//释放
}
没有合适的资源?快使用搜索试试~ 我知道了~
多线程进程间交换数据使用的共享内存
共15个文件
h:5个
cpp:4个
dsp:1个
3星 · 超过75%的资源 需积分: 32 101 下载量 101 浏览量
2009-02-12
13:55:21
上传
评论
收藏 13KB ZIP 举报
温馨提示
多线程进程间交换数据使用的共享内存多线程进程间交换数据使用的共享内存多线程进程间交换数据使用的共享内存多线程进程间交换数据使用的共享内存多线程进程间交换数据使用的共享内存
资源推荐
资源详情
资源评论
收起资源包目录
ShareMem.zip (15个子文件)
StdAfx.cpp 210B
SFMMem.h 2KB
ShareMemDlg.h 2KB
SFMMem.cpp 4KB
Debug
StdAfx.h 1KB
ShareMem.h 1KB
ShareMem.dsp 4KB
ShareMemDlg.cpp 7KB
Resource.h 1008B
res
ShareMem.rc2 400B
ShareMem.ico 1KB
ShareMem.cpp 2KB
ShareMem.dsw 539B
ShareMem.rc 6KB
ShareMem.clw 1KB
共 15 条
- 1
资源评论
- liu8670908692014-04-14很好,很详细
- ennika2013-07-25没有pro文件的,也没有main文件,只有几个.h 和.cpp,感觉很深奥,不知道从哪里看起~
lwaif
- 粉丝: 13
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功