描述:
现在不会,请高手相助,有源程序,如肯帮忙,发个信到sqjlxj@163.com,回复时我给带上源程序。如能解决,给100分。小弟初涉组件对象模型编程,如果那位大侠能指点一二,让小弟有所提高,小弟再送100分。
解决方案1:
发了,收到没有?
解决方案2: 显示属性页
若要显示此页,需要创建一个简单的帮助器对象。帮助器对象将提供一个方法,该方法简化 OleCreatePropertyFrame API 以显示与单个对象连接的单个页。此帮助器将被设计为可以从 Visual Basic 中使用。
使用“添加类”对话框和 ATL 简单对象向导生成一个新类,并将 Helper 用作其简称。一旦创建,就照下表所示添加一个方法。
项值
方法名称ShowPage
参数[in] BSTR bstrCaption, [in] BSTR bstrID, [in] IUnknown* pUnk
bstrCaption 参数是将作为对话框标题显示的标题。bstrID 参数是表示要显示的属性页的 CLSID 或 ProgID 的字符串。pUnk 参数是属性将由该属性页配置的对象的 IUnknown 指针。
按如下所示实现该方法:
STDMETHODIMP CHelper::ShowPage(BSTR bstrCaption, BSTR bstrID,
IUnknown* pUnk)
{
if (!pUnk)
return E_INVALIDARG;
// First, assume bstrID is a string representing the CLSID
CLSID theCLSID = {0};
HRESULT hr = CLSIDFromString(bstrID, &theCLSID);
if (FAILED(hr))
{
// Now assume bstrID is a ProgID
hr = CLSIDFromProgID(bstrID, &theCLSID);
if (FAILED(hr))
return hr;
}
// Use the system-supplied property frame
return OleCreatePropertyFrame(
GetActiveWindow(), // Parent window of the property frame
0, // Horizontal position of the property frame
0, // Vertical position of the property frame
bstrCaption, // Property frame caption
1, // Number of objects
&pUnk, // Array of IUnknown pointers for objects
1, // Number of property pages
&theCLSID, // Array of CLSIDs for property pages
NULL, // Locale identifier
0, // Reserved - 0
NULL // Reserved - 0
);
}
重写 IPropertyPageImpl::Apply
当用户要将他们的更改应用到对象时,属性页站点将调用 Apply 方法。在此处执行与 Activate 中的代码相反的工作,Activate 是从对象中获取值并将它们推到属性页上的控件中,而 Apply 却从属性页上的控件中获取值并将它们推到对象中。
STDMETHOD(Apply)(void)
{
// If we don't have any objects, this method should not be called
if (!m_ppUnk)
return E_UNEXPECTED;
// Use Apply to validate the user's settings and update the objects'
// properties
// Check whether we need to update the object
// Quite important since standard property frame calls Apply
// when it doesn't need to
if (!m_bDirty)
return S_OK;
HRESULT hr = E_UNEXPECTED;
// Get a pointer to the document
CComQIPtr<EnvDTE::Document> pDoc(m_ppUnk[0]);
if (!pDoc)
return hr;
// Get the read-only setting
VARIANT_BOOL bReadOnly = IsDlgButtonChecked(IDC_READONLY) ? VARIANT_TRUE : VARIANT_FALSE;
// Get the file name
CComBSTR bstrName;
if (!GetDlgItemText(IDC_NAME, bstrName.m_str))
return E_FAIL;
// Set the read-only property
if (bReadOnly != m_bReadOnly)
{
hr = pDoc->put_ReadOnly(bReadOnly);
if (FAILED(hr))
return hr;
}
// Save the document
if (bstrName != m_bstrFullName)
{
EnvDTE::vsSaveStatus status;
hr = pDoc->Save(bstrName, &status);
if (FAILED(hr))
return hr;
}
// Clear the&nb