INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to send a Message to COleControl with m_hWnd = NULL?

How to send a Message to COleControl with m_hWnd = NULL?

(OP)
thread194-107864: How to send a Message to COleControl with m_hWnd = NULL?

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 --> VC++

// 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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close