AnnRTFText example for C++ 5 and later
// This sample loads a rich text annotation object with text
//It illustrates how AnnRTFText can treat the text as Rich Text, or plain text
// hObject: the Rich Text annotation object
// uFormat: the format of the retrieved text--one of
// RTF_FORMAT_TEXT
// RTF_FORMAT_RTF
#define RICH_STRING "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033\
{\\fonttbl{\\f0\\fnil\\fcharset0 Arial;}}{\\colortbl ;\ \\red255\\green0\\blue0;\\red255\\green255\\blue255;\
\\red51\\green102\\blue0;\\red0\\green0\\blue255;\
\\red0\\green0\\blue0;}\\viewkind4\\uc1\\pard\\cf1\
\\highlight2\\ul\\fs20 Rich \\cf3\\ulnone\\b Text \
\\cf4\\b0\\i String\\cf5\\i0\\par}"
void CAnnSample2Dlg::SampleAnnTextRTF(long hObject,long uFormat)
{
CString pszFormat;
CString RTF ;
long ulength ;
TCHAR *pText;
TCHAR szMsg[200];
switch (uFormat)
{
case RTF_FORMAT_TEXT:
pszFormat = TEXT("RTF_FORMAT_TEXT");
m_pRasterAnn->Flags = 0;
m_pRasterAnn->put_AnnRTFText(hObject, uFormat, (BSTR)RICH_STRING);
break;
case RTF_FORMAT_RTF:
pszFormat = TEXT("RTF_FORMAT_RTF");
m_pRasterAnn->Flags = 0;
m_pRasterAnn->put_AnnRTFText(hObject, uFormat ,(BSTR)RICH_STRING);
}
m_pRasterAnn->GetAnnRTFText(hObject, uFormat);
ulength = m_pRasterAnn->RTFTextLength;
pText = (CHAR *)malloc((ulength+1)*sizeof(CHAR));
lstrcpy (pText, m_pRasterAnn->GetAnnRTFText(hObject, uFormat));
wsprintf(szMsg, TEXT("Format: %s\nLength: %d"), pszFormat, ulength);
MessageBox(pText, szMsg, MB_OK);
free(pText);
}