Adding Labels, Separator Lines, and Hyperlinks (Visual C++ Tutorial) [Office 2003 SDK Documentation]

Previous  Adding Document Fragments

The following steps show you how to add labels, separator lines, and hyperlinks to the SimpleSample smart document.

  1. You'll add the label, separator line, and hyperlink to the example element, so you don't need any additional constants, and you don't need to increase the number of types in the cTYPES constant. However, you do need to insert the following code.

    In the ControlCount property subroutine, add 3 to the control count number for the cEXAMPLE constant.  Replace the existing code in the cEXAMPLE case with the following code, or change your code to match.

            else if (wcscmp(XMLTypeName,cEXAMPLE(cNAMESPACE)) == 0)
            {           
                *Count = 4;
            }
    

    In the ControlTypeFromID property subroutine, insert the following code.

                case 202:
                    *Type = C_TYPE_LABEL;
                    break;
    
                case 203:
                    *Type = C_TYPE_SEPARATOR;
                    break;
    
                case 204:
                    *Type = C_TYPE_LINK;
                    break;
    

    In the ControlCaptionFromID property subroutine, insert the following code.

                case 202:
                    *Caption = SysAllocString(L"This is a label. Below you will find a separator line and a hyperlink to the Microsoft home page.");
                    break;
    
                case 203:
                    *Caption = SysAllocString(L"This text doesn't show");
                    break;
    
                case 204:
                    *Caption = SysAllocString(L"Microsoft.com");
                    break;
    
  2. Use the InvokeControl method to specify actions for the hyperlink.  For the SimpleSample smart document, you need to add a reference to the Microsoft Internet Controls type library. Then add the following variable and insert the following code into the switch statement in the InvokeControl method subroutine.

            VARIANT vDummy = {0},url;
            IWebBrowser2* pWebBrowser = NULL;
    
    ... [code between]
    
                case 204:
                    url.vt=VT_BSTR;
                    url.bstrVal=SysAllocString(L"http://www.microsoft.com");
    
                    CoCreateInstance(CLSID_InternetExplorer,NULL, CLSCTX_SERVER, IID_IWebBrowser2,(LPVOID*)&pWebBrowser);
    
                    pWebBrowser->put_Visible(VARIANT_TRUE);
                    pWebBrowser->Navigate2(&url, &vDummy, &vDummy,&vDummy, &vDummy);
                    VariantClear(&url);                
    
                    if (pWebBrowser)
                        pWebBrowser->Release();            
                    break;
    

    Note  You can adjust the size of a separator line or the appearance of text in a label by placing code in the PopulateOther method and by using the Props parameter to specify the ISmartDocProperties key and value pairs.

  3. Recompile your SimpleSample smart document dynamic-link library (DLL), and copy it to the deployment location that you specified earlier. When you reopen your SimpleSample smart document, delete the SimpleSample XML expansion pack, and then re-add it to the document.

Next  Creating a Smart Document Using Microsoft Visual C++