class CCauuid : public CAUUID
{
public:
CCauuid()
{
ZeroMemory(this, sizeof(this));
}
virtual ~CCauuid()
{
if (this->pElems != NULL)
{
::CoTaskMemFree(this->pElems);
}
}
};
// プロパティシートの表示
HRESULT ShowPropertySheet(
IUnknownPtr spUnk,
HWND hwndOwner, // Parent window of property sheet dialog box
UINT x, // Horizontal position for dialog box
UINT y, // Vertical position for dialog box
LPCOLESTR lpszCaption = NULL, // Pointer to the dialog box caption
LCID lcid = LOCALE_USER_DEFAULT) // Locale identifier for property sheet locale
{
HRESULT hr = S_OK;
try
{
ISpecifyPropertyPagesPtr spSpecifyPropertyPages = spUnk;
if (spSpecifyPropertyPages == NULL)
{
return E_FAIL;
}
// プロパティシートのCLSIDを取得する
CCauuid pages; // クラスなので、スコープが外れると自分で解放する
hr = spSpecifyPropertyPages->GetPages(&pages);
if (FAILED(hr))
{
return hr;
}
ATLTRACE(_T("pages.cElems : %d\n"), pages.cElems);
LPUNKNOWN lpUnks[1];
lpUnks[0] = spUnk;
hr = ::OleCreatePropertyFrame(
hwndOwner, x, y, lpszCaption, 1, lpUnks,
pages.cElems, pages.pElems, lcid, 0, NULL);
if (FAILED(hr))
{
return hr;
}
}
catch (...)
{
return E_FAIL;
}
return hr;
}
// タイトルの取得
tstring GetUserType(IOleObjectPtr spOleObject, DWORD dwFormOfType = USERCLASSTYPE_SHORT)
{
if (spOleObject == NULL)
{
return tstring();
}
LPOLESTR szTitle = NULL;
HRESULT hr = spOleObject->GetUserType(dwFormOfType, &szTitle);
if (FAILED(hr))
{
return tstring();
}
tstring strResult = (LPCTSTR)_bstr_t(szTitle);
::CoTaskMemFree(szTitle);
return strResult;
}
---------- プロパティシートを表示するサンプル ----------
HRESULT hr = S_OK;
IDispatchPtr spDispatch;
hr = this->GetDlgControl(IDC_MAPOCX, __uuidof(IDispatch), (void**)&spDispatch);
if (FAILED(hr))
{
return hr;
}
// タイトルの取得
// → USERCLASSTYPEは、どれを指定しても一緒みたい。。。
tstring strCaption = ::GetUserType(spDispatch, USERCLASSTYPE_SHORT);
// プロパティシートの表示
hr = ::ShowPropertySheet(spDispatch, m_hWnd, 0, 0, (LPCOLESTR)_bstr_t(strCaption.c_str()));
if (FAILED(hr))
{
return hr;
}