#define WM_CONTROLPRINT WM_USER+1001
2.发送端,获得其他窗口句柄的方法FindWindow();
void CAaDlg::OnButtonsend()
{
// TODO: Add your control notification handler code here
//通过窗体名称,获取其他进程窗口句柄
CWnd *pWnd=CWnd::FindWindow(NULL,_T("Bb"));
if(pWnd==NULL)
{
AfxMessageBox("接收程序没有运行!");
return ;
}
pWnd->SendMessage(WM_CONTROLPRINT,NULL,0);
}
{
// TODO: Add your control notification handler code here
//通过窗体名称,获取其他进程窗口句柄
CWnd *pWnd=CWnd::FindWindow(NULL,_T("Bb"));
if(pWnd==NULL)
{
AfxMessageBox("接收程序没有运行!");
return ;
}
pWnd->SendMessage(WM_CONTROLPRINT,NULL,0);
}
//消息响应函数
void OnControlPrint(WPARAM wParam, LPARAM lParam);
void CBbDlg::OnControlPrint(WPARAM wParam, LPARAM lParam)
{
if(wParam==0 && lParam==0)
AfxMessageBox("HelloWorld!");
return ;
}
//添加消息映射
BEGIN_MESSAGE_MAP(CBbDlg, CDialog)
//{{AFX_MSG_MAP(CBbDlg)
ON_MESSAGE(WM_CONTROLPRINT, OnControlPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void OnControlPrint(WPARAM wParam, LPARAM lParam);
void CBbDlg::OnControlPrint(WPARAM wParam, LPARAM lParam)
{
if(wParam==0 && lParam==0)
AfxMessageBox("HelloWorld!");
return ;
}
//添加消息映射
BEGIN_MESSAGE_MAP(CBbDlg, CDialog)
//{{AFX_MSG_MAP(CBbDlg)
ON_MESSAGE(WM_CONTROLPRINT, OnControlPrint)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()