Article ID: 166768
Article Last Modified on 7/1/2004
140592 How To Implementing Per-Property Browsing for a Custom Property
// CTestPropPage is the classname for the "dummy" property page.
BOOL CTestPropPage::OnInitDialog()
{
COlePropertyPage::OnInitDialog();
// Display the FileOpen dialog box because the property page is not
// visible yet.
CFileDialog dlg(TRUE);
int nRet = dlg.DoModal();
if(nRet == IDOK)
{
// Do something with the selected filename. For illustration
// purposes assume that the control associated with this property
// page has a property named FileName which is of type BSTR. The
// following code will set the FileName property in the associated
// control(s) to the filename selected by the user via the FileOpen
// dialog box.
DISPID dwFileNameDispID;
COleDispatchDriver PropDispDriver;
ULONG nObjects;
// Get the array of control IDispatch's stored in the property page.
LPDISPATCH FAR * lpObjectArray = GetObjectArray(&nObjects);
// Get the name of the selected file.
CString strFileName = dlg.GetFileName();
// Set the filename property for all the control objects currently
// associated with this property page.
for (ULONG i = 0; i < nObjects; i++)
{
// Get the Dispatch ID for the property and if successful set the
// value of the property.
LPCOLESTR lpOleStr = L"FileName";
if (SUCCEEDED(lpObjectArray[i]->GetIDsOfNames(IID_NULL,
(LPOLESTR*)&lpOleStr, 1, 0, &dwFileNameDispID)))
{
// Set the property.
PropDispDriver.AttachDispatch(lpObjectArray[i], FALSE);
PropDispDriver.SetProperty(dwFileNameDispID, VT_BSTR,
(LPCTSTR)strFileName);
PropDispDriver.DetachDispatch();
}
}
}
// We are done with the FileOpen dialog box. Now you need to kill
// the property page so the user won't see it.
EndDialog(-1);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE}
}
The following steps summarize how to show a custom dialog for a custom
property:Keywords: kbhowto kbinprocsvr kbuidesign kbcmndlgfileo kbctrl KB166768