SendMessage to another dialog window
-
I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.
-
I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.
You cannot do that with a string. The string is in the memory of your process, all that you are sending is the address, which the second process will not be able to read. To send a string send the WM_COPYDATA message instead. But this will not allow you to add it to a listbox like you are trying.
-
I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.
Make sure your message handler is prototyped as follows: in the header file:
afx_msg LRESULT OnHandleMyMessage(WPARAM wParam, LPARAM lParam);
and in the cpp file:
BEGIN_MESSAGE_MAP(CMyClass, CDialog)
ON_MESSAGE(LB_ADDSTRING, OnHandleMyMessage)
END_MESSAGE_MAP()LRESULT CMyClass::OnHandleMyMessage(WPARAM wParam, LPARAM lParam)
{
// your code goes herereturn 1L;
}
Also, you should call
PostMessage
unless you need to wait for the message handler to return."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
Make sure your message handler is prototyped as follows: in the header file:
afx_msg LRESULT OnHandleMyMessage(WPARAM wParam, LPARAM lParam);
and in the cpp file:
BEGIN_MESSAGE_MAP(CMyClass, CDialog)
ON_MESSAGE(LB_ADDSTRING, OnHandleMyMessage)
END_MESSAGE_MAP()LRESULT CMyClass::OnHandleMyMessage(WPARAM wParam, LPARAM lParam)
{
// your code goes herereturn 1L;
}
Also, you should call
PostMessage
unless you need to wait for the message handler to return."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001Thanks for the reply. I'm quite new at coding and can't quite decipher what you provided, but are you suggesting I subclass the control?
-
Thanks for the reply. I'm quite new at coding and can't quite decipher what you provided, but are you suggesting I subclass the control?
He means, make sure you have correctly configured the message handler. But this is only valid if you are using MFC.
-
He means, make sure you have correctly configured the message handler. But this is only valid if you are using MFC.
I see. I'm using Win32. Is there a workaround for this?
-
You cannot do that with a string. The string is in the memory of your process, all that you are sending is the address, which the second process will not be able to read. To send a string send the WM_COPYDATA message instead. But this will not allow you to add it to a listbox like you are trying.
He doesn't mention two windows from two processes here.
Prasad Notifier using ATL | Operator new[],delete[][^]
-
I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.
georgiek50 wrote:
SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString);
What value does this function returns ? I assume
hwnd
is handle to target list box.Prasad Notifier using ATL | Operator new[],delete[][^]
-
I see. I'm using Win32. Is there a workaround for this?
Not familiar with Win32, If you can, add something like the following: BOOL MyDialog::PreTranslateMessage(MSG* pMsg) { // catch any WM_USER messages if (pMsg->message == WM_USER) { // see if it's your message if (pMsg->wParam == LB_ADDSTRING) { ... process the message .... .....