How to create a custom control in a dialog with ATL

loop123123 1 Reputation point
2020-08-06T21:20:47.78+00:00

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++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,760 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 9,786 Reputation points Microsoft Vendor
    2020-08-07T05:16:46.413+00:00

    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!

    0 comments No comments

  2. RLWA32 45,701 Reputation points
    2020-08-09T11:18:05.843+00:00

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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.