HOWTO: Implementing a Custom Property Showing a FileOpen DialogLast reviewed: October 9, 1997Article ID: Q166768 |
The information in this article applies to:
SUMMARYThis article demonstrates a way to show the FileOpen dialog box for a custom property in an ActiveX control. The custom property is implemented by using per-property browsing in an ActiveX control. For information on implementing such a custom property, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q140592 TITLE : HOWTO: Implementing Per-Property Browsing for a Custom PropertyWhen the custom property is selected for editing in a design environment such as Microsoft Visual Basic, an ellipsis button (or three-dots button) will be shown on the Properties window for the property. Clicking the ellipsis button in the Properties window displays a FileOpen dialog box associated with the property.
MORE INFORMATIONBecause the Windows FileOpen common dialog box is not a COM object, it doesn't have a CLSID associated with it. However, if you follow the instructions in Knowledge Base article Q140592 to add a custom property to an ActiveX control, the MFC framework calls OnMapPropertyToPage() to obtain the CLSID of a property page that implements editing of the specified property. To achieve the goal of showing the FileOpen dialog box, create a "dummy" property page and return its CLSID in the OnMapPropertyToPage() function. Then, using ClassWizard, add an OnInitDialog() function to the "dummy" property page class and add the following code:
// 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 : MfcOLE Technology : kbole Version : WINNT:4.2,4.2b,5.0; Platform : NT WINDOWS Issue type : kbhowto |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |