How to Use Tab Methods in TOM

The following example provides C functions that illustrate the use of the tab methods in the Text Object Model (TOM). It is assumed that most applications include a toolbar that shows the current position and type of the tabs for the currently selected paragraph.

What you need to know



  • C/C++
  • Windows User Interface Programming


Use a Tab Method

The following code example demonstrates how to update a toolbar with the current tab details.

HRESULT UpdateToolbar(ITextSelection *pSel)
    HRESULT hr       = S_OK;        
    ITextPara *pPara = 0;
    float f;
    long tbt;            // tab type
    long tbp;

    hr = pSel->GetPara(&pPara);
    if (FAILED(hr))
        goto cleanup;    // Paragraph properties are not supported
    f = (float) -1.0;    // Start at beginning
    while (pPara->GetTab(tbgoNext, &f, &tbt, NULL) == S_OK)
            // Do something like draw tab icon on toolbar here
            // DrawTabPicture(f, tbt);

    if (pPara)
    return hr;

Copy Tab Information

The following example shows how to copy only the tab information from one ITextPara interface to another. It takes two parameters: ITextPara * pParaFrom (the paragraph from which to copy tabs) and ITextPara * pParaFrom (the paragraph to which to copy tabs).

HRESULT CopyOnlyTabs(ITextPara *pParaFrom, ITextPara *pParaTo)
    float f;
    short tbt;
    short style;
    f = (float) -1.0;
    while (pParaFrom->GetTab(tbgoNext, &f, &tbt, &style) == S_OK)
        pParaTo->AddTab(f, tbt, style);
    return S_OK;                

Using The Text Object Model

Using Rich Edit Controls

Windows common controls demo (CppWindowsCommonControls)