GetDlgItem fails for an ActiveX control

Was working with a customer yesterday who was having this issue of GetDlgItem failing to return a valid window handle for an ActiveX control placed on a dialog. The ActiveX control is visible though but curiously the handle was always showing up as NULL.

While debugging saw this particular line in the Visual Studio 2010 output window…

image

Hmm interesting. Why is the control saying I want to be windowless. Customer never mentioned he wants a windowless control.

So when creating an ActiveX control the wizard provides a checkbox which says the following…

image

When the above checkbox is checked the wizard adds the following line of code into your ActiveX control’s constructor…

image

In my customer’s case this was the reason for GetDlgItem not returning a valid window object for the ActiveX control.

Another way this problem can manifest is when you turn off m_bWindowOnly in your activex control class. This variable will be off if you are creating a windowless control.

In short I would say: always keep an eye on the visual studio output window. 🙂

Appreciate your comments...