📄 clientdlg.cpp
字号:
// ClientDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Client.h"
#include "ClientDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CClientDlg dialog
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/)
: CDialog(CClientDlg::IDD, pParent)
, m_msg(_T("Message Content"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CClientDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_Edit1, m_msg);
}
BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_btnSendMessage, &CClientDlg::OnBnClickedbtnsendmessage)
ON_BN_CLICKED(IDC_btnSendToMem, &CClientDlg::OnBnClickedbtnsendtomem)
ON_BN_CLICKED(IDC_btnExit, &CClientDlg::OnBnClickedbtnexit)
END_MESSAGE_MAP()
// CClientDlg message handlers
BOOL CClientDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CClientDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
DRA::RelayoutDialog(
AfxGetInstanceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_CLIENT_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_CLIENT_DIALOG));
}
#endif
void CClientDlg::OnBnClickedbtnsendmessage()
{
CString str=_T("Server");
CWnd *pWnd=CWnd::FindWindow(NULL,str);
UpdateData(TRUE);
if(pWnd && m_msg!=_T(""))
{
COPYDATASTRUCT buf;
buf.lpData =m_msg.GetBuffer(m_msg.GetLength());
buf.cbData =m_msg.GetLength()*2;//lstrlen((LPTSTR)m_msg.GetBuffer(m_msg.GetLength()));
pWnd->SendMessage(WM_COPYDATA,0,LPARAM(&buf));
}
else
MessageBox(_T("No such Message"));
}
void CClientDlg::OnBnClickedbtnsendtomem()
{
HANDLE hMapping;
LPTSTR lpData;
hMapping=CreateFileMapping(HANDLE(0xFFFFFFFF),NULL,PAGE_READWRITE,0,1024,_T("MyShare"));
if(hMapping==NULL)
{
AfxMessageBox(_T("Create FileMapping Failed"));
return;
}
lpData=(LPTSTR)MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0);
if(lpData==NULL)
{
AfxMessageBox(_T("MapViewOfFile Failed"));
return;
}
UpdateData(TRUE);
if(m_msg!=_T(""))
wsprintf(lpData,m_msg);
else
AfxMessageBox(_T("Message is empty!"));
}
void CClientDlg::OnBnClickedbtnexit()
{
CClientDlg::OnOK();
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -