Adding Command Buttons (Visual C++ Tutorial) [Office 2003 SDK Documentation]

Previous  Creating a Smart Document Using Microsoft Visual C++

The following steps show you how to add command buttons to the SimpleSample smart document.

  1. The first thing you need to do is add a constant for the commandbutton element in the SimpleSample schema. Insert the following code into the general declarations section of your code module, below the existing constants.

    #define  cBUTTON(xmlns) xmlns L"#commandbutton"
    
  2. Next you need to add 1 to the cTYPES constant. Remove the existing cTYPES constant, and enter the following code or change your code to match.

    #define cTYPES 2
    
  3. Now you are ready to modify the existing code to insert the command button. The subroutines you need to modify are SmartDocXMLTypeName, SmartDocXMLTypeCaption, ControlCount, ControlID, ControlTypeFromID, and ControlCaptionFromID.

    In the SmartDocXMLTypeName property subroutine, insert the following code.

                case 2:
                    *Name = SysAllocString(cBUTTON(cNAMESPACE));
                    break;
    

    In the SmartDocXMLTypeCaption property subroutine, insert the following code.

                case 2:
                    *Caption = SysAllocString(L"Click");
                    break;
    

    In the ControlCount property subroutine, insert the following code.

            else if (wcscmp(XMLTypeName,cBUTTON(cNAMESPACE)) == 0)
            {           
                *Count = 1;
            }
    

    In the ControlID property subroutine, insert the following code.

            else if (wcscmp(XMLTypeName,cBUTTON(cNAMESPACE)) == 0)
            {           
                *ControlID = ControlIndex + 100;
            }
    

    In the ControlTypeFromID property subroutine, insert the following code.

                case 101:
                    *Type = C_TYPE_BUTTON;
                    break;
    

    Finally, in the ControlCaptionFromID property subroutine, insert the following code.

                case 101:
                    *Caption = SysAllocString(L"Test button");
                    break;
    
  4. Next, you need to enter the code that operates the button you added earlier. In the InvokeControl method, insert the following code. The InvokeControl method is used to specify code that you want to run for command buttons, hyperlinks, and, in Microsoft Office Word 2003 only, clicking document fragments.

            switch (ControlID)
            {
                case 101:
                    MessageBox(NULL,"This is an example of a button.", "InvokeControl", MB_OK);
                    break;
            }
    
  5. 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, you may need to click Update on the XML Expansion Packs tab in the Templates and Add-ins dialog box. You may also need to reattach the XML expansion pack to the document.

Next  Adding Help Content