Table of contents
1.
Introduction
2.
Component Object Model
3.
Uses of UI Support Classes
4.
IViewObjectExlmpl 
5.
Public Methods of IViewObjectExlmpl
5.1.
IViewObjectExImpl::Draw
5.2.
IViewObjectExImpl::Freeze
5.3.
IViewObjectExImpl::GetAdvise
5.4.
IViewObjectExImpl::GetColorSet
5.5.
IViewObjectExImpl::GetExtent
5.6.
IViewObjectExImpl::GetNaturalExtent
5.7.
IViewObjectExImpl::GetRect
5.8.
IViewObjectExImpl::GetViewStatus
5.9.
IViewObjectExImpl::QueryHitPoint
5.10.
IViewObjectExImpl::QueryHitRect
5.11.
IViewObjectExImpl::SetAdvise
5.12.
IViewObjectExImpl::Unfreeze
6.
Frequently Asked Questions
6.1.
What are COM objects?
6.2.
What does IViewObjectExlmpl class provide?
6.3.
What does S_OK return value mean?
6.4.
What is an IUnknown Interface?
6.5.
What is the difference between STL and ATL of C++?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

UI Support Class-IViewObjectExImpl

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

Introduction

The set of template-based C++ classes developed by Microsoft is known as Active Template Classes (ATL). These classes are used for the simplification of programming of the Component Object Model (COM) objects. Microsoft Visual C++ supports the COM, allowing developers to create a variety of COM Objects, tear-off interfaces, ActiveX Controls, and OLE(Object Linking and Embedding) Automation. Object wizard in ATL sets up the primary structure of the objects without much hand coding.

UI Support Class-IViewObjectExImpl

In this article, we will discuss one of the libraries in the UI (User Interface) Support Class called the IViewObjectExImpl.

Component Object Model

Component Object Model (COM) is a distributed, platform-independent, object-oriented system which creates binary software components that can interact. It is a standard and not an Object Oriented language. It defines the nature of a COM object. A COM object is the one in which an object’s data gets the access using a set of related functions called the interfaces.

Uses of UI Support Classes

UI Support classes provide functionalities and support using different classes. Each class has its own benefit. Following are those classes that provide general UI support:

  • IDocHostUIHandlerDispatch: An interface to the Microsoft HTML parsing and rendering engine.
     
  • IOleObjectImpl: Delivers the main methods through which a container communicates with a control. Manages the activation and deactivation of in-place controls.
     
  • IOleInPlaceObjectWindowlessImpl: Assists in the reactivation of in-place controls. Enables a windowless control to accept messages as well as to participate in drag-and-drop operations.
     
  • IOleInPlaceActiveObjectImpl: Manages contact between an in-place control and its container.
     
  • IViewObjectExImpl: Enables a control to display itself directly and to notify the container of changes in its display. Provides support for flicker-free drawing, non-rectangular and fine controls, and hit testing.

IViewObjectExlmpl 

IViewObjectExlmpl is one of the classes provided by ATL. The class allows a control to display itself directly and to notify the container when its display changes. 

This class implements IUnknown. The IUnknown interface enables the clients to get a pointer to the other interfaces on the given object through the QueryInterface method. The class also provides default implementations of the IViewObject (enables an object to display itself directly), IViewObject2 (an extension to the IViewObject interface and returns the size of the drawing), and IViewObjectEx (an extension of IViewObject2 and provides flicker-free drawing) interfaces.

The syntax for using IViewObjectExlmpl class:

template<class T>
class ATL_NO_VTABLE IViewObjectExImpl: public IViewObjectEx


Here, T is the class derived from the IViewObjectExlmpl class.

This class provides various methods. Let us take a look at some of the Public Methods available in IViewObjectExlmpl.

Public Methods of IViewObjectExlmpl

Below is the list of all the public methods available in IViewObjectExlmpl.

Name

Description

IViewObjectExImpl::Draw It represents the control on a device context.
IViewObjectExImpl::Freeze It freezes the representation of the control drawn.
IViewObjectExImpl::GetAdvise If recoups the existing advisory sink connection on the control, if there is one.
IViewObjectExImpl::GetColorSet It returns the logical palette used for drawing by the control.
IViewObjectExImpl::GetExtent It recoups the size of control display in HIMETRIC (0.01 mm per unit) units
IViewObjectExImpl::GetNaturalExtent It provides the sizing hints for the object from the container.
IViewObjectExImpl::GetRect It returns a rectangle that describes the requested drawing aspect.
IViewObjectExImpl::GetViewStatus It returns the information about the object’s opacity and tells what drawing aspects are supported.
IViewObjectExImpl::QueryHitPoint It checks whether the specified point lies in the specified rectangle.
IViewObjectExImpl::QueryHitRect It checks if there is overlapping between the control’s display rectangle and any point in the specified location rectangle.
IViewObjectExImpl::SetAdvise It sets up the connection and an advise sink between the control so that the sink gets notified about any changes in the control’s view.
IViewObjectExImpl::Unfreeze It unfreezes the representation of the control drawn.

This was the short description of all the public methods available in IViewObjectExImpl class. Let’s see each of these methods in detail.

IViewObjectExImpl::Draw

This method is used for representing the control on the device context.

Syntax:

STDMETHOD(Draw)(
    DWORD dwDrawAspect,
    LONG lindex,
    void* pvAspect,
    DVTARGETDEVICE* ptd,
    HDC hicTargetDev,
    LPCRECTL prcBounds,
    LPCRECTL prcWBounds,
    BOOL(_stdcall* /* pfnContinue*/) (DWORD_PTR dwContinue),
    DWORD_PTR /* dwContinue */);


Return value: Nothing

IViewObjectExImpl::Freeze

This method is used for freezing the drawn representation of the control so that it won’t change until an Unfreeze is used.

Syntax:

STDMETHOD(Freeze)(
    DWORD /* dwAspect */,
    LONG /* lindex */,
    void* /* pvAspect */,
    DWORD* /* pdwFreeze */);


Return value: E_NOTIMPL is returned by the ATL implementation.

IViewObjectExImpl::GetAdvise

This method finds an advisory sink connection on a control, if any exists.

Syntax:

STDMETHOD(GetAdvise)(
    DWORD* /* pAspects */,
    DWORD* /* pAdvf */,
    IAdviseSink** /* ppAdvSink */);


Return value: Nothing

IViewObjectExImpl::GetColorSet

This method is used for returning the logical palette which is used by the control for drawing.

Syntax:

STDMETHOD(GetColorSet)(
    DWORD /* dwAspect */,
    LONG /* lindex */,
    void* /* pvAspect */,
    DVTARGETDEVICE* /* ptd */,
    HDC /* hicTargetDevice */,
    LOGPALETTE** /* ppColorSet */);


Return value: E_NOTIMPL is returned by the ATL implementation.

IViewObjectExImpl::GetExtent

This method uses CComControlBase::m_sizeExtent data member from the control class for finding the display size of the control in HIMETRIC (0.01 mm per unit) units.

Syntax:

STDMETHOD(GetExtent)(
    DWORD /* dwDrawAspect */,
    LONG /* lindex */,
    DVTARGETDEVICE* /* ptd */,
    LPSIZEL* lpsizel);


Return value: It does not return anything.

IViewObjectExImpl::GetNaturalExtent

This method provides the user with sizing hints from the container for resizing an object.

Syntax:

STDMETHOD(GetNaturalExtent)(
    DWORD dwAspect,
    LONG /* lindex */,
    DVTARGETDEVICE* /* ptd */,
    HDC /* hicTargetDevice */,
    DVEXTENTINFO* pExtentInfo,
    LPSIZEL psizel);


Return Value: It may return HRESULT, an error.

IViewObjectExImpl::GetRect

Syntax:

STDMETHOD(GetRect)(DWORD /* dwAspect */, LPRECTL /* pRect */);


Return Value: E_NOTIMPL

IViewObjectExImpl::GetViewStatus

This method is used for informing about the object's opacity and drawing capabilities.

Syntax:

STDMETHOD(GetViewStatus)(DWORD* pdwStatus);


Return value: Nothing

IViewObjectExImpl::QueryHitPoint

This method is used for providing a HITRESULT value to the pHitResult if the specified point is in the specified rectangle.

Syntax:

STDMETHOD(QueryHitPoint)(
    DWORD dwAspect,
    LPCRECT pRectBounds,
    POINT ptlLoc,
    LONG /* lCloseHit */,
    DWORD* /* pHitResult */);


Return value: It returns S_OK if dwAspect is equal to DVASPECT_CONTENT. Else, it returns E_FAIL. 

IViewObjectExImpl::QueryHitRect

This method is used for providing a HITRESULT value to the pHitResult if the control’s display rectangle is overlapping to any point of the specified location rectangle.

Syntax:

STDMETHOD(QueryHitRect)(
    DWORD dwAspect,
    LPCRECT pRectBounds,
    LPRECT prcLoc,
    LONG /* lCloseHit */,
    DWORD* /* pHitResult */);


Return value: It returns S_OK if dwAspect is equal to DVASPECT_CONTENT. Else, it returns E_FAIL.

IViewObjectExImpl::SetAdvise

This method is used for connecting the control to the sink so that the sink can be notified when the control's view changes.

Syntax:

STDMETHOD(SetAdvise)(
    DWORD /* aspects */,
    DWORD /* advf */,
    IAdviseSink* pAdvSink);


Return value: Nothing

IViewObjectExImpl::Unfreeze

This method is used for unfreezing the control’s drawn representation.

Syntax:

STDMETHOD(Unfreeze)(DWORD /* dwFreeze */);


Return value: E_NOTIMPL is returned by the ATL implementation.

Frequently Asked Questions

What are COM objects?

The COM object is one in which the object's data is accessed using a set of related functions.

What does IViewObjectExlmpl class provide?

It provides flicker-free drawing, hit testing, and non-rectangular and transparent controls.

What does S_OK return value mean?

It signifies the successful creation or retrieval of the service.

What is an IUnknown Interface?

IUnknown interface allows us to get pointers to other interfaces on a given object.

What is the difference between STL and ATL of C++?

STL (Standard Template Library) is a set of classes meant to ease and reduce coding time for a standard set of containers. Whereas, ATL (Application Template Library) is based on COM for connectivity between different types of applications.

Conclusion

In this article, you learned about ATL, COM and the UI support class-IViewObjectExImpl. You also gained knowledge about different public methods available in the IViewObjectExImpl class.

Recommended readings:

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

Happy Learning :)

Live masterclass