Using the MFC Resource wizard, create a new dialog box. Derive a new class for it from an MFC dialog base class such as CDialog. You should create a placeholder control, such as a list box, that you will replace with your Property Inspector control when it is created. Use the same position and rectangular dimensions that you want to use to display the Property Inspector control.
Add the following protected member variable to hold a pointer to your PropertyInspector ActiveX control:
CComPtr<IPropertyInspector> mpInspector;
To support this control, include the AcPi.h file. This generated IDL file contains the declarations for all Property Inspector interfaces. In the implementation file for your dialog, you will include the AcPi_i.c file to define the GUIDs for the Property Inspector interfaces.
Also, you will need the following protected CWnd* member to act as a container for the Property Inspector control:
CWnd* mpInspectorWnd;
Basic dialog initialization is done for you by the MFC Project Wizard. You do not need to implement message handlers to see the point of this exercise. Likewise, the default implementation of DoDataExchange() is sufficient, because Property Inspector interfaces and controls—not MFC—will be handling data display and updates in this application.
In addition to the basic MFC setup, you must instantiate the Property Inspector control and set up the data structures that are required to initialize it. This can be done in your CDialog::InitDialog() override. In this function you should replace the dialog placeholder control that you created earlier with the Property Inspector control. Once you have gotten the window dimensions from the placeholder and applied them to the new Property Inspector instance, you can discard the placeholder.
To create the Property Inspector control, you first initialize your mpInspectorWnd member to point to a new CWnd object. You then call mpInspectorWnd->CreateControl() with the CLSID of the Property Inspector control as its first argument. To set the size of the Property Inspector window to match your dialog design, pass the rectangle coordinates of the placeholder as the rect argument.
Finally, pass the ID of the placeholder control as the nID argument. The nID argument tells Windows what ID to use to find your window. You also configure the new window to respond to this ID by calling SetWindowLongPtr(). The Property Inspector control now assumes the IDC_PI_PLACEHOLDER ID as its own. This sequence instantiates the Property Inspector ActiveX control and replaces the placeholder in your dialog box.
mpInspectorWnd = new CWnd; ASSERT(mpInspectorWnd != NULL); CWnd* pWnd = GetDlgItem(IDC_PI_PLACEHOLDER); CRect rect; pWnd->GetWindowRect(&rect); ScreenToClient(&rect); mpInspectorWnd->CreateControl(CLSID_PropertyInspector, NULL, WS_CHILD | WS_TABSTOP | WS_VISIBLE, rect, this, IDC_PI_PLACEHOLDER); SetWindowLong(mpInspectorWnd->m_hWnd, GWL_ID, IDC_PI_PLACEHOLDER);