Message from worker-thread to several Dialogs
Hi together!
I'm currently implementing a program which does CAN-communication in a worker-thread and all other things in the Dialog-box.
Now I want to react on Messages that come out of the CAN-Bus-thread in the dialog.
I implemented a message, a message handler and so on, and it works fine. I receive the messages in the MainGui.
But when I listen in some other Gui-Classes they don't receive the message. There is everything implemented in the same way.
Can I receive one Message just in a thread (Gui) or is it possible to receive one message in different GUIs in the same thread?
I have also removed the receive-Method in the MainGui but also didn't received some messages in other GUIs.
Can me someone explain, why??
WorkerThread-Code:
::PostMessage(HWND_BROADCAST, CAN_MESSAGE, (WPARAM)pCanMessage, 0);
And the Client-Code (In each GUI-Class the same)
.cpp File
BEGIN_MESSAGE_MAP(CKontrolle, CDialog)
//{{AFX_MSG_MAP(CKontrolle)
ON_BN_CLICKED(IDC_BUTTON_DEFAULT, OnButtonDefault)
....
//}}AFX_MSG_MAP
ON_MESSAGE(CAN_MESSAGE, test)
END_MESSAGE_MAP()
long CKontrolle::test(WPARAM wParam, LPARAM lParam)
{
wprintf(_T("test!!!!!!!!!!!!!!!!!!!!!!\n"));
return 0;
}
.h File
long test(WPARAM wParam, LPARAM lParam);
CAN_MESSAGE definition:
#define CAN_MESSAGE WM_USER + 0x10
Hope someone can help me...
Andy
[1531 byte] By [
Kaiserle] at [2007-11-18 13:41:16]

# 2 Re: Message from worker-thread to several Dialogs
I have already read the FAQ.
The problem is, when I sent a message from the worker-thread to my gui thread.
In this gui-thread I have several GUIs and in each GUI there is a test() method to receive this Message. Unfortunately I just receive in one GUI the message. All other GUIs which also have this test() method implemented are not called?
Can I implement in one thread (gui-thread) just one receive-Method?
What is the problem that just one receive-method is called?
Thanx
# 3 Re: Message from worker-thread to several Dialogs
from MSDN:
Applications that need to communicate using HWND_BROADCAST should use the RegisterWindowMessage function to obtain a unique message for inter-application communication.
Did you follow this? I think not.
Your message is defined like:
#define CAN_MESSAGE WM_USER + 0x10
Try to RegisterWindowMessage() your message and see what happens. Maybe this is the problem.
Alin at 2007-11-11 2:11:25 >

# 4 Re: Message from worker-thread to several Dialogs
I think I found the problem:
From MSDN:
HWND_BROADCAST:
The message is posted to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows. The message is not posted to child windows.
So my new question: How can I tell this child windows to change.
Do I have to make some function-calls by myself or is there a better solution?
Thnx
# 7 Re: Message from worker-thread to several Dialogs
Originally posted by Kaiserle
So first I have to register all my GUI-Handles in the worker-thread?!
OK, thanks for your answers ...
Andy
you can pass them as thread data:
in the .h:
struct TWndGroup
{
HWND m_hwnd1;
HWND m_hwnd2;
};
TWndGroup m_wndGroup;
in the .cpp:
m_wndGroup.m_hwnd1 = m_pChildWnd1->GetSafeHwnd();
m_wndGroup.m_hwnd2 = m_pChildWnd2->GetSafeHwnd();
m_pThread = AfxBeginThread( AfxThread, static_cast<LPVOID>(&m_wndGroup) );
UINT CMainFrame::AfxThread(LPVOID pVoid)
{
TWndGroup *pWndGroup = static_cast<TWndGroup*>(pVoid);
::PostMessage (pWndGroup->m_hwnd1, CAN_MESSAGE, 1, 1);
::PostMessage (pWndGroup->m_hwnd2, CAN_MESSAGE, 2, 2);
return 0;
}
Alin at 2007-11-11 2:15:29 >
