Article ID: 205670
Article Last Modified on 11/21/2006
void CMyTestCtrl::SayHello()
{
AfxMessageBox("Hello"); //Add this statement.
}
long CMyTestCtrl::GetControlPointer()
{
return reinterpret_cast<long>(this);
}
void CMyTestCtrl::SetControlPointer(long /*nNewValue*/)
{
SetNotSupported();
}
#include "MyTestCtl.h"
void CMyTestPropPage::OnButton1()
{
// Add this code:
ULONG uNumControls;
// Get the array of IDispatchs stored in the property page.
LPDISPATCH *lpDispatchControls = GetObjectArray(&uNumControls);
for (ULONG i = 0; i < uNumControls; i++)
{
CMyTestCtrl *pMyCtrl = GetControl(lpDispatchControls, i);
if (pMyCtrl)
pMyCtrl->SayHello();
}
}
CMyTestCtrl* GetControl(LPDISPATCH *lpDispatchControls, ULONG iControlIndex)
{
CMyTestCtrl *pMyCtrl = NULL;
// Get the CCmdTarget object associated.
pMyCtrl = (CMyTestCtrl*) CCmdTarget::FromIDispatch(lpDispatchControls[iControlIndex]);
if (!pMyCtrl) // Above failed. Container must have aggregated the control.
{
long ControlPointer;
_DMyTest control(lpDispatchControls[iControlIndex]);
// GetObjectArray() docs state must not release pointer.
control.m_bAutoRelease = FALSE;
ControlPointer = control.GetControlPointer();
pMyCtrl = reinterpret_cast<CMyTestCtrl*>(ControlPointer);
}
return pMyCtrl;
}
143432 How to gain access to an ActiveX control from its property page
Additional query words: property
Keywords: kbcontainer kbctrlcreate kbhowto kbpropsheet KB205670