Article ID: 146010
Article Last Modified on 8/31/2005
void CGridCtrl::SetPicture(LPDISPATCH propVal)
{
SetProperty(0x15, VT_DISPATCH, propVal);
}
CPicture CGridCtrl::GetPicture()
{
LPDISPATCH pDispatch;
GetProperty(0x15, VT_DISPATCH, (void*)&pDispatch);
return CPicture(pDispatch);
}
It is not intuitively clear how to use these methods to get or set the
picture property. The following steps show how to set the picture property of
an ActiveX control successfully in an AppWizard-generated application. The
particular control used in this example is the Microsoft Grid Control, and its
picture property is being set to the toolbar bitmap provided by AppWizard.
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Create and Initialize the CPictureHolder variable with the
// toolbar resource
CPictureHolder pictholder;
pictholder.CreateFromBitmap(IDR_MAINFRAME);
//Pass dispatch pointer to CPictureHolder
m_grid.SetPicture(pictholder.GetPictureDispatch());
// NOTE: GetPictureDispatch() QI()'s for the IPictureDisp
// interface, so the picture object will remain alive until
// the property is reset or the control is destroyed. When
// pictholder goes out of scope, it calls Release() on the
// picture object, but the previously mentioned QI() will have
// bumped the ref count, allowing it to remain alive until the
// control itself releases the picture object.
return TRUE;
}Additional query words: ocx
Keywords: kbhowto kboleapp kbproperties kbbitmap kbctrl kbcode KB146010