How to use VC to get the properties of ActiveX controls on the container

zhaozj2021-02-08  204

How to get the attribute values ​​for ActiveX controls

We need to get the value of the attribute value of the ActiveX control in the container, which requires the interface provided by some COM libraries. This article is mainly introduced to this process, making everyone understand and learn to use these interfaces.

First we need to add a function to the container's ColeClientItem class, such as initcontrolinfo ().

What to pay attention to, this function is to be called after creating a control (ie cocreateInstance ()), is called before the control (ie QuickActive () or setClientSite ()).

In this function, we will use the following major interfaces: iProvideClassInfoptr, iProvideClassInfoptr, please note: Both interfaces are smart pointers, so you don't have to take care of their living cycle.

First, we want to use the M_LPObject member variable, this variable is implemented inside the ColeClientItem. It is actually a pointer to the IoleObject. You need to assign it to later use when you create a control. Now we can use it directly.

(One):

m_lpobject-> queryinterface (iid_iprovideclassinfo, (void **) & ppci); // So we got iProvideClassInfoptr PPCI

PPCI-> getClassInfo (& PCLassinfo); // Get itypeInfoptr PCLassinfo

PclassInfo-> gettypeattr (& ptypeattr) // typeattr * ptypeattr typettr Use a structure that describes the type attribute, which contains many values, specifically refer to MSDN.

#define importype_mask (ImplTypeflag_fdefault & brvbarimpltypeflag_fsource| / imprtypeflag_frestricted)

#define implatype_defaultsource (ImplTypeflag_fdefault & BrvbarimplTypeflag_fsource)

#define importype_defaultinterface (ImplTypeflag_fdefault)

Bool tfounddefaultsource = false;

Bool TFoundDefaultInterface = false;

// This loop is used to find a resource or interface, ptypeattr-> cimplatypes is the number of stated types.

For (ITYPE = 0; (iType cimpltypes) &&! (tfounddefaultsource && tfounddefaultinterface); iTYPE )

{

HRESULT = PCLASSINFO-> GetIMPLTYPEFLAGS (ITYPE, & iflags); // This is the flag bit of the type specified by serial number

if (succeeded))

{

IF (iflags & imprty_mask == ImplType_defaultsource) // is resource

{

Assert (! Tfounddefaultsource);

TFoundDefaultsource = True;

HRESULT = PCLASSINFO-> getRefTypeOfImplType (ITYPE, & HREFTYPE); // get a handle of a statement

IF (FAILED) {Return (HRESULT);

HRESULT = PCLASSINFO-> getRefTypeInfo (HreftypeInfo); // Using the handle to get TypeInfo Note: These two steps must be used like this. IF (Failed (HRESULT);}

Trace ("Events: / N");

HRESULT = m_infoevents.init (ptypeinfo); // Using the Event Attribute of the PTYPEINFO to initialize the control

// Note: m_infoevents is a custom class CinterfaceInfo, which will tell the INIT (ITYPEINFO * PTYPEINFO) function later.

IF (HRESULT) {Return (HRESULT);

ptypeinfo.release ();

}

ELSE IF (iflags & impType_mask == ImplType_defaultinterface) // Is the interface

{

Assert (! Tfounddefaultinterface);

TFoundDefaultInterface = true;

HRESULT = PCLassinfo-> getRefTypeOfImplType (ITYPE, & HREFTYPE);

IF (FAILED) {Return (HRESULT);

HRESULT = PclassInfo-> getRefTypeInfo (HREFTYPE, & PTYPEINFO);

IF (FAILED) {Return (HRESULT);

TRACE ("Methods / N");

HRESULT = M_INFMETHODS.INIT (PTYPEINFO); // Using the method properties of the initialization control

IF (FAILED) {Return (HRESULT);

ptypeinfo.release ();

}

}

}

(2): This is a custom class CINTERFACEINFO to save the properties of the control. Here, we mainly get the properties of the control in its INIT (ITYPEINFO * PTYPEINFO).

PtypeInfo-> getFuncDesc (IMETHOD, & PFUNCDESC) // This function is used to obtain a description of the function of the specified number

PtypeInfo-> getvardesc (ivar, & pvardesc) // This function is used to obtain a description of the specified number of variables

Note: You can refer to MSDN about FuncDesc and VARDESC structures.

Here we mainly pay attention to how to take the attribute value, and the function is actually similar.

Dispid m_dispid;

BSTR BSTRNAME;

Int nnames;

m_dispid = pvardesc-> memid; // acquirted with DISPID

PtypeInfo-> getNames (m_dispid, & bstrname, 1, "); // Use the name of the attribute using Dispid

CString M_StrName = BSTRNAME;

Sysfreestring (bstrname); // Release Resources

We may need some parameters for PropertyPuts we may also need to get attributes

Pvardesc-> ElemDescvar is the parameter description information of the property

Note: You can refer to MSDN about ElemDesc.

In this class, we can assign a list of lists for controls to save all the properties obtained from the controls. So we can use it.

I will roughly describe the method of acquiring control attributes in the container, there is anything I don't know how I can e-mail.

转载请注明原文地址:https://www.9cbs.com/read-2641.html

New Post(0)