int RTFConcatenator::CollectCallback(HTREEITEM item, struct tree_node_t *node, void *cargo) { RTFConcatenator *that = (RTFConcatenator *)cargo; struct guide_nodedata_t *data = (struct guide_nodedata_t *)tree_get_data(node); ASSERT(node); ASSERT(cargo); ASSERT(item); // position cursor at end and clear selection HWND hWnd = that->m_hWnd; ::SendMessage(hWnd, EM_SETSEL, (WPARAM)-1, (LPARAM)-1); // get heading level int level = 0; // 0 => no other top nodes struct tree_node_t *node2 = node; while (tree_get_parent(node2) != that->m_pTopNode) { level++; node2 = tree_get_parent(node2); } // append heading rtf text CStringA heading = that->m_TemplateHelper.GetHeading( that->m_HeadingCounter.GetHeadingNumber(node), level, data->title, that->m_bLastTextEmpty, data->color, data->bgcolor); SETTEXTEX tex; tex.codepage = CP_ACP; // ??? tex.flags = ST_SELECTION; LRESULT lr = ::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)(const char *)heading); ASSERT(lr > 0); // check the number of characters in the text SetRTF(that->m_hZeroCheckWnd, data->text, false); LRESULT nChars = ::SendMessage(that->m_hZeroCheckWnd, WM_GETTEXTLENGTH, 0, 0); if (nChars > 0) { // append rtf text (only if some text is really present) if (data->text[0] != 0 && strcmp(theEmptyRTFText, data->text) != 0) //theEmptyRTFText != data->text) ::SendMessage(hWnd, EM_SETTEXTEX, (WPARAM)&tex, (LPARAM)data->text); } that->m_bLastTextEmpty = (nChars == 0); // continue return 0; }
void CRichEditCtrlGS::SetRTF(const UINT resID) { // Obtain a handle and the memory to the resource HINSTANCE hApp = ::GetModuleHandle(0); ASSERT(hApp); HRSRC hResInfo = ::FindResource(hApp, MAKEINTRESOURCE(resID), TEXT("RTF")); if( NULL == hResInfo ) return; HGLOBAL hRes = ::LoadResource(hApp, hResInfo); if( NULL == hRes ) return; LPVOID pRTFText = ::LockResource(hRes); if( NULL == pRTFText ) return; DWORD dwRTFSize = ::SizeofResource(hApp, hResInfo); if( 0 == dwRTFSize ) { ::FreeResource(hRes); return; } CByteArray arrbRTF; arrbRTF.SetSize(dwRTFSize); LPBYTE pArrRTF = arrbRTF.GetData(); ::CopyMemory(pArrRTF,pRTFText,dwRTFSize); ::FreeResource(hRes); SetRTF(arrbRTF); }
bool CDittoRulerRichEditCtrl::LoadItem(long lID, CString csDesc) { bool bSetText = false; CClipFormat Clip; m_lID = lID; m_csDescription = csDesc; //If creating a new clip if(m_lID < 0) { m_rtf.SetModify(FALSE); return false; } Clip.m_cfType = RegisterClipboardFormat(CF_RTF); if(theApp.GetClipData(lID, Clip) && Clip.m_hgData) { LPVOID pvData = GlobalLock(Clip.m_hgData); if(pvData) { SetRTF((char*)pvData); bSetText = true; } GlobalUnlock(Clip.m_hgData); Clip.Free(); Clip.Clear(); } if(bSetText == false) { Clip.m_cfType = CF_UNICODETEXT; if(theApp.GetClipData(lID, Clip) && Clip.m_hgData) { LPVOID pvData = GlobalLock(Clip.m_hgData); if(pvData) { CString csText = (WCHAR*)pvData; SetText(csText); bSetText = true; } GlobalUnlock(Clip.m_hgData); Clip.Free(); Clip.Clear(); } } if(bSetText == false) { Clip.m_cfType = CF_TEXT; if(theApp.GetClipData(lID, Clip) && Clip.m_hgData) { LPVOID pvData = GlobalLock(Clip.m_hgData); if(pvData) { CString csText = (char*)pvData; SetText(csText); bSetText = true; } GlobalUnlock(Clip.m_hgData); Clip.Free(); Clip.Clear(); } } m_rtf.SetModify(FALSE); return bSetText; }