PostMessage problem
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
-
Don't you see the following comments just below the help of WM_COPYDATA in MSDN[^]
_An application must use the SendMessage function to send this message, not the PostMessage function_.
nave [OpenedFileFinder]
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
-
oh, that's why I wasn't success. thank you very much, Naveen. So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??
tataxin wrote:
So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??
Yes. :(
nave [OpenedFileFinder]
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
tataxin wrote:
It works, but while sending messeage, it locks the send dialog.
Since
SendMessage
is blocking call, it will return only after theWM_COPYMESSAGE
handler returns. So don't do any heavy processing in yourWM_COPYMESSAGE
handler. The best method is copy the data and trigger the processing in another thread so that the handler can return immediately.tataxin wrote:
It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage.
You should not use
PostMessage
forWM_COPYDATA
, since its asynchronous. This article might be helpful - http://www.codeguru.com/cpp/w-p/win32/article.php/c1429/[^] Regards, Jijo._____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
-
I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog
COPYDATASTRUCT cds;
.... // insert data here::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );
And receive dialog code:
BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
.....
ON_WM_COPYDATA()
END_MESSAGE_MAP()BOOL RcvDlg::OnCopyData(){
... // get data here
}It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)
You need a class that handles the post msgs....
void FACTORY::addWindow(HWND hWnd)
{
m_Windows.push_back(hWnd);
}thus, regsiter all the windows with this class with the function above. (FACTORY::instance().addWindow(m_hWnd);) then, you send these messages to the different classes that registered to this via the PostMessage function....
void FACTORY::PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
{list<HWND>::iterator i; int count = 0; HWND hWnd; for( i = m\_Windows.begin(); i != m\_Windows.end(); i++) { hWnd = \*i; ::PostMessage(hWnd, Msg, wParam, lParam); }
}
Then simply post the message and catch it in the class....
FACTORY::instance().PostMessage(THE_MESSAGE, (long)VAL1, (long)VAL2);
and "catch" it in you PretranslateMessage functions....
if(pMsg->message == THE_MESSAGE)
then get the vals...
int VAL1 = (long)pMsg->wParam;
int VAL2 = (long)pMsg->lParam;OR SOMETHING LIKE THAT....
modified on Tuesday, June 24, 2008 3:04 AM
-
tataxin wrote:
So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??
Yes. :(
nave [OpenedFileFinder]
-
You need a class that handles the post msgs....
void FACTORY::addWindow(HWND hWnd)
{
m_Windows.push_back(hWnd);
}thus, regsiter all the windows with this class with the function above. (FACTORY::instance().addWindow(m_hWnd);) then, you send these messages to the different classes that registered to this via the PostMessage function....
void FACTORY::PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
{list<HWND>::iterator i; int count = 0; HWND hWnd; for( i = m\_Windows.begin(); i != m\_Windows.end(); i++) { hWnd = \*i; ::PostMessage(hWnd, Msg, wParam, lParam); }
}
Then simply post the message and catch it in the class....
FACTORY::instance().PostMessage(THE_MESSAGE, (long)VAL1, (long)VAL2);
and "catch" it in you PretranslateMessage functions....
if(pMsg->message == THE_MESSAGE)
then get the vals...
int VAL1 = (long)pMsg->wParam;
int VAL2 = (long)pMsg->lParam;OR SOMETHING LIKE THAT....
modified on Tuesday, June 24, 2008 3:04 AM