question

AdamTopel-5714 avatar image
0 Votes"
AdamTopel-5714 asked ·

How to create a custom control in a dialog with ATL

Hi, I was wondering if anyone can describe the steps for adding an ATL window class as a control to a dialog resource. I found an article discussing it here, but that involves MFC, so I was hoping to get some clarification on how to do it with ATL.

So far I have (a) a dialog class derived from CDialogImpl, which includes a dialog resource, and (b) another class derived from CWindowImpl, which I'd like to add as the custom control in the dialog.

I've added DECLARE_WND_CLASS to the latter class, so that it has an identifiable class name. From what I understand, this class name should be used for the custom control in the dialog resource editor.

But I'm not sure how to go about doing the rest. Do I still call Create on the control class? And if so, where? It seems that no matter what I try, ATL throws an assertion error about some HWND not existing.

Thank you very much for any assistance.






c++
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JeanineZhang-MSFT avatar image
0 Votes"
JeanineZhang-MSFT answered ·

Hi,

As far as I'm concerned, ATL throws an assertion error, which seems to indicate that registration wasn't successful. I suggest you could try to use RegisterClassExA function.

1,You could try to use DECLARE_WND_CLASS and RegisterClassEx API to register class by name and custom control reference in dialog template to instantiate control through class name.

2,You should implement window class.Inheriting from CWindowImpl, and create control manually, duing OnCreate/OnInitDialog.

For more details about registering an ATL window class, I suggest you could refer to the link: https://stackoverflow.com/questions/575532/pre-registering-an-atl-window-class

Thank you!


·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RLWA32-6355 avatar image
0 Votes"
RLWA32-6355 answered ·

There are samples of creating controls with ATL at VC2010Samples/ATL/Controls



·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.