Design of ActiveX Control Using MFC-Step 2

Source: Internet
Author: User
I just flipped through CodeGuru and found that the control property page was displayed at runtime.
Http://www.codeguru.com/cpp/com-tech/activex/controls/article.php/c2649/

Try to do it as it looks.

Also, the example tppb in the previous step

1. Add HRESULT GetPages (CAUUID * pPages)

HRESULT CTppbCtrl: GetPages (CAUUID * pPages)
{
GUID * pGUID;
Const unsigned CPROPPAGES = 4;

PPages-> cElems = 0;
PPages-> pElems = NULL;

PGUID = (GUID *) CoTaskMemAlloc (CPROPPAGES * sizeof (GUID ));

If (NULL = pGUID)
{
Return ResultFromScode (E_OUTOFMEMORY );
}

// Fill the array of property pages now
PGUID [0] = CTestPropPage: guid;
PGUID [1] = CLSID_CFontPropPage;
PGUID [2] = CLSID_CColorPropPage;
PGUID [3] = CLSID_CPicturePropPage;

// Fill the structure and return
PPages-> cElems = CPROPPAGES;
PPages-> pElems = pGUID;
Return NOERROR;
}
This is a common member function. The main function is to obtain how many property pages are displayed and what property pages are available.

2. Add the control method void ShowProperties ()

Void CTppbCtrl: ShowProperties ()
{
// TODO: Add your dispatch handler code here
CAUUID caGUID;
HRESULT hr;
LPDISPATCH pIDispatch = GetIDispatch (TRUE );
LCID lcid = AmbientLocaleID ();

GetPages (& caGUID );

Hr = OleCreatePropertyFrame (
M_hWnd,
10,
10,
OLESTR ("Do something control "),
1,
(IUnknown **) & pIDispatch,
CaGUID. cElems,
CaGUID. pElems,
Lcid,
0L,
NULL );
If (FAILED (hr ))
{
AfxMessageBox ("unable to display attribute pages", MB_ OK | MB_ICONERROR, 0 );
}

CoTaskMemFree (void *) caGUID. pElems );
Return;
}

The function used to display the property page is OleCreatePropertyFrame, which is obtained through the GetPages function. The information of the property page is stored in the CAUUID caGUID structure.
The prototype of the OleCreatePropetyFrame function is
STDAPI OleCreatePropertyFrame (
HWND
HwndOwner,// The parent window of the property page dialog box
UINT
X,// Horizontal position of the property page relative to the parent window
UINTY,// Vertical position of the property page relative to the parent window
LPCOLESTRLpszCaption, // Attribute page title
ULONG
CObjects,// Number of controls that can be set on the property page
Lpunknown far *
LplpUnk, // An array of all configurable controls on the property page
ULONG
CPages,// Number of displayed property pages
LPCLSID
LpPageClsID, // CLSID array on the property page
LCIDLcid,// Language flag. If you do not care about it, you can set it to 0.
DWORD
DwReserved,// Reserved
LPVOID
LpvReserved// Reserved);

For more information, see.

3. Compile and create a VB project, add the tppb control, and add the Code as follows:
Private Sub Form_Load ()
Tppb1.ShowProperties
End Sub
The properties page is displayed after running.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.