Table of contents
1.
Introduction
2.
Component Object Model
3.
Classes and Structs 
4.
CDialogImpl Class
4.1.
Modal and Modeless Dialog Box
4.2.
Methods 
4.2.1.
CDialogImpl::Create
4.2.2.
CDialogImpl::DestroyWindow
4.2.3.
CDialogImpl::DoModel
4.2.4.
CDialogImpl::EndDialog
5.
Frequently Asked Questions
5.1.
What does Active Template Library mean?
5.2.
What are C++ templates?
5.3.
What are some ATL applications?
5.4.
What does Windows' COM object mean?
6.
Conclusion
Last Updated: Mar 27, 2024
Easy

Windows support class-CDialogImpl

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

Based on the Standard Template Library (STL), Active Template library extends the Visual Studio development environment with COM object automation wizards. 

ATL can produce many objects, including dialogue boxes and Internet Explorer controls. ActiveX controls, dual interfaces, and connection points are all supported by ATL. By this, only we can understand how powerful ATL is. 

ATL

So, Microsoft Active Template Library is a C++ template class specially made to make it easier to code and develop for the Component Object Model (COM) and ActiveX.

Working knowledge of COM is highly recommended to fully utilize ATL. 

So, let us understand COM first: 

Component Object Model

Computer frameworks are reusable templates that improve software programming, reliability and productivity. The component object model (COM) is a computer framework that integrates components with Microsoft® programming languages.

The component object model is a Microsoft® implementation of object-oriented programming (OOP) that allows developers to reuse COM components without knowing the underlying software language.

The component object model is a beautiful way to incorporate modular design into a software program.

What is a MODULAR DESIGN?

Modular design is an architectural approach based on creating small, simple software components. Each module is designed to serve a specific purpose and can operate independently of the application. 

printer

A printer connected to a computer that communicates via a printer driver is a good example of this technique in action.

Each COM framework component is an independent service that can be accessed by unrelated software programs. Programmers can thus reuse COM objects.

A variety of programming languages can be used to create COM objects. Object-oriented languages, such as C++, offer programming mechanisms that make it easier to implement COM objects. These objects can exist within the same process, in other processes, or even on remote computers.

This must have provided you with great insight into the Component Object Model

Let us quickly jump to today’s discussion: Windows Support class - CDialoglmpl

DialogIMPL

The Active Template Library (ATL) contains various classes and structs. One of them is CDialogImpl. 

Before we start learning about CDialogImpl, let us quickly recap what are classes and structs. 

Classes and Structs 

Classes and structs are the constructs used to define your own types. Classes and structs can both have data members and member functions that allow you to describe the type's state and behavior.

  • The struct is a user-defined data type that incorporates logically related data items of different data types such as float, char, int, and so on.
     
  • All struct elements are stored in contiguous memory locations. Structure type variables allow you to store multiple data items of varying data types under one name.
     
  • A class is a blueprint or instructions for creating a specific object type. It is a fundamental concept of Object-Oriented Programming that revolves around real-world entities. 
     
  • In a programming language, a class determines how an object behaves and what it contains.
     
  • A class is a user-defined data type containing various data types and member functions.
     

Now that we have understood classes and structs let us quickly jump to understanding CDialoglmpl

CDialogImpl Class

This class contains methods for generating modal or modeless dialog boxes. A dialog box is a common type of window in the GUI of an operating system (also spelled dialogue box and called a dialogue). In addition to providing more details, the dialogue box also requests input from the user. 

For example: When you use a program and want to open a file, you interact with the "File Open" dialog box. 
 

dialog box

credit: cadence.com

Syntax
 

template <class T,
    class TBase = CWindow>
    class ATL_NO_VTABLE CDialogImpl : public CDialogImplBaseT<TBase>


Parameters

T = It is your class that is derived from CDialogImpl.

TBase = It is the base class of your new class. Although, the default base class is CWindow. 

Now, there are two types of Dialog Boxes: Model and Modeless

Modal and Modeless Dialog Box

A modal dialog prevents you from accessing the rest of the application until it is closed. When a modal dialogue box is open, it is always active and prevents opening any other dialogue boxes or windows until it is closed.

While the modeless dialogue is open, you can use the rest of the application. Other application windows may hide it.

So, as we discussed above, CDialogImpl class contains methods for generating both types of Dialog Boxes: Modal and Modeless

Let us quickly jump to how it creates the Dialog box: 

Model and modelless dialog box

Methods 

In the below-mentioned image, different methods are there for generating Dialog Boxes. We have briefly described each method in the image below to differentiate between the model and modeless dialog box. 

Methods

Let us see the working of each method one by one: 

CDialogImpl::Create

Create creates a modeless dialog box.

create

HWND Create(
    HWND hWndParent,
    LPARAM dwInitParam = NULL );
HWND Create(
    HWND hWndParent,
    RECT&,
    LPARAM dwInitParam = NULL);


Parameters

hWndParent: It is the handle to the owner window.

RECT& rect:  A RECT structure specifying the size and position of the Dialog.

dwInitParam: It specifies the value to be passed to the dialogue box in the WM INITDIALOG message's lParam parameter.

Return Value: It returns the handle to the newly created dialog box.

CDialogImpl::DestroyWindow

It destroys a modeless dialog box.

destroy

BOOL DestroyWindow();


Return Value: If the dialogue box was successfully destroyed, TRUE; otherwise, FALSE.

CDialogImpl::DoModel

DoModel creates a modal dialog box.

create

INT_PTR DoModal(
    HWND hWndParent = ::GetActiveWindow(),
    LPARAM dwInitParam = NULL);


Parameters

hWndParent: The handle to the owner window. The default value is the return value of the GetActiveWindow Win32 function.

dwInitParam: It specifies the value to pass to the dialog box in the lParam parameter of the WM_INITDIALOG message.

Return Value: If successful, the value of the nRetCode parameter specified in the EndDialog call is returned. Else, -1.

CDialogImpl::EndDialog

It destroys a modal dialog box.

destroy

BOOL EndDialog(int nRetCode);


Parameters

nRetCode: The value to be returned by CDialogImpl::DoModal.

Return Value: TRUE if the dialog box is destroyed; otherwise, FALSE.

Frequently Asked Questions

What does Active Template Library mean?

The Active Template Library is a collection of Microsoft C++ template classes (program routines) that are specially made to make it easier to code and develop for the Component Object Model (COM) and ActiveX.

What are C++ templates?

In C++, templates are an effective tool for passing data types as parameters to generalized functions.

What are some ATL applications?

The Active Template Library (ATL), a wrapper library that facilitates COM development, is frequently used to create ActiveX controls. Applications written in MFC or ATL can be made using Visual Studio Community Edition or higher.

What does Windows' COM object mean?

The Microsoft Component Object Model is a distributed, object-oriented method for creating binary software components that can communicate (COM).

Conclusion

Congratulations on finishing the blog! We have discussed the Windows support class-CDialogImpl in the active template library. Further, we have discussed various member functions in composite control classes.

This blog has helped to enhance your knowledge of the composite control classes in the active template library. Do not stop learning! We recommend you read some of our articles on the Active template library: 


Check out our Data Structures and Algorithms-guided path to learn Data Structures and Algorithms. Also, check out some of the Guided PathsContests, and Interview Experiences to gain an edge only on Coding Ninjas Studio.

Cheers!

Live masterclass