thread194-107864
In a previously closed thread a Guest user asked a an interesting question I had to face myself:
-----------------
hi all!
I'm developing a multithreaded MFC activex control and want to send messages
to my COleControl object from one of the threads.
My idea was to use WM_USER messages, but SendMessage requires the
destination window's handle and my m_hWnd is NULL...
has anybody a solution for this?
ciao
holger
-----------------
Well, I had this same problem and I found the solution:
The main MFC class from which an OCX derives is COleControl.
COleControl is a subclass of CWnd, so one could think that it has a proper m_hWnd.
But it does not! As Holger sais, m_hWnd is NULL. And if m_hWnd is NULL, SendMessage fails.
But if you add this snippet to your COleControl derived class, it gets a proper m_hWnd and everything is solved!
Next time you read m_hWnd, you will see it has a correct value. And, therefore, SendMessage & PostMessage will work.
I hope this helps!
Ricardo Vázquez.
Madrid, Spain.
In a previously closed thread a Guest user asked a an interesting question I had to face myself:
-----------------
hi all!
I'm developing a multithreaded MFC activex control and want to send messages
to my COleControl object from one of the threads.
My idea was to use WM_USER messages, but SendMessage requires the
destination window's handle and my m_hWnd is NULL...
has anybody a solution for this?
ciao
holger
-----------------
Well, I had this same problem and I found the solution:
The main MFC class from which an OCX derives is COleControl.
COleControl is a subclass of CWnd, so one could think that it has a proper m_hWnd.
But it does not! As Holger sais, m_hWnd is NULL. And if m_hWnd is NULL, SendMessage fails.
But if you add this snippet to your COleControl derived class, it gets a proper m_hWnd and everything is solved!
Code:
// Create a Notification Sink (to be enable message handling)
m_hWnd = NULL;
if (!CreateEx(0, AfxRegisterWndClass(0), _T("My OCX Notification Sink"), WS_OVERLAPPED, 0, 0, 0, 0, NULL, NULL))
{
AfxThrowResourceException();
}
Next time you read m_hWnd, you will see it has a correct value. And, therefore, SendMessage & PostMessage will work.
I hope this helps!
Ricardo Vázquez.
Madrid, Spain.