如何用SendMessage()函数传递字符串
1个回答
展开全部
函数传递字符串
-----------------------------
一、两个参数都带字符串的形式:
void CAaaDlg::OnButton1(){char* p1 = "Willis";
char* p2 = "VCHelp";
SendMessage(WM_CURRENTINFO, (WPARAM)p1, (LPARAM)p2 );}LRESULT CAaaDlg::OnCurrentInfo(WPARAM wParam, LPARAM lParam ){MessageBox((LPSTR)wParam,(LPSTR)lParam,0);//
消息函数里接收字符串return 0;}--------
二、只带一个字符串的形式:
CString strPara = _T("fggg");
::SendMessage(hWnd,WM_XXXX,0,(LPARAM)(LPCTSTR)strPara);
OnMessageXXXX(WPARAM wParam,LPARAM lParam){CString strddd = (LPCTSTR)lParam; //
在消息处理函数里接收字符串}
////////how to use wm_copydata to pass string使用WM_COPYDATA:
CString str = _T( "Hello" );
HWND hWndReceived = FindWindow( "Receiver", NULL );
COPYDATASTRUCT cpd;
cpd.dwData = 0;
cpd.cbData = strDataToSend.GetLength();
cpd.pData = (void*)str.GetBuffer(cpd.cbData);
SendMessage( hWndReceived, WM_COPYDATA, 0, (LPARAM) & cpd );
str.ReleaseBuffer();
加入映射宏:
BEGIN_MESSAGE_MAP(CMyWnd, CWnd)
//{{AFX_MSG_MAP(CMyWnd)
ON_WM_COPYDATA()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询