Andrew Truckle
Andrew Truckle

Reputation: 19097

I am having problems trying to display a RTF data file in a rich text edit control in a MFC dialog

I saw a discussion here about displaying a RTF file in a rich text edit control. Maybe what I am trying to do it too much.

In my dialog class I define a static method:

static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG* pcb)
{
    std::ifstream* pFile = (std::ifstream*)dwCookie;
    pFile->read((char*)pbBuff, cb);
    return 0;
}

In my dialog OnInitDialog class I try to display the data:

std::ifstream  File("d:\\RevisionHistoryTest.rtf");
EDITSTREAM es = { 0 };
es.dwCookie = (DWORD)&File;
es.pfnCallback = MyStreamInCallback;
::SendMessage(m_rtfEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);

Now, here is a link to a sample project. I don't know where I can put this project in the long term, but my DropBox will do for now. The project does not include the RTF file. This is how I created it:

  1. I went to the following URL in a browser.
  2. I selected all the Revision History content and pasted it into a Microsoft Word file.
  3. I copied the Microsoft Word content and pasted it into a WordPad session and saved it.

Example:

enter image description here

Interestingly, when I subsequently open my RTF file in WordPad I get a popup message:

enter image description here

If I select Unblock then it still opens in the editor. I assume that is because all of the images must still be linked to those on my website. And I think this is related to the issue with my test project, because this is what I see:

enter image description here

I get no errors or anything. It just reads the first line and stops.

I am trying to find the easiest way to display my HTML history in a RTF window.


My original intention was to use a CHtmlView control instead (makes sense to do that) and directly read my Revision History file from the internet. But my help system is designed to permanently show the contents pane on the left. This is why I thought that RTF might be a suitable alternative. But struggling with it.


Update

Based on the comments made about 64 bit builds I located this tutorial which works for both 32 bit and 64 bit. They both display "Revision History" only.

BOOL FillRichEditFromFile(HWND hwnd, LPCTSTR pszFile)
{
    BOOL fSuccess = FALSE;

    HANDLE hFile = CreateFile(pszFile, GENERIC_READ,
        FILE_SHARE_READ, 0, OPEN_EXISTING,
        FILE_FLAG_SEQUENTIAL_SCAN, NULL);

    if (hFile != INVALID_HANDLE_VALUE)
    {
        EDITSTREAM es = { 0 };

        es.pfnCallback = MyStreamInCallback;
        es.dwCookie = (DWORD_PTR)hFile;

        if (SendMessage(hwnd, EM_STREAMIN, SF_RTF, (LPARAM)&es) && es.dwError == 0)
        {
            fSuccess = TRUE;
        }

        CloseHandle(hFile);
    }

    return fSuccess;

}

And in OnInitDialog:

FillRichEditFromFile(m_rtfEdit.GetSafeHwnd(), _T("d:\\RevisionHistoryTest.rtf"));

But my initial issue still remains.


Update

I had forgotten to set the control to multiline! That was part of the issue:

enter image description here

At least all of the text is visible now. Just not the images. And I don't like the way some of the links are displayed.

I have been able to edit the file and bring the indents over to the left to make it look better. But images still won't show.


Update

As a workaround to this I realised that I could simply duplicate my HTML Revision History as a standalone page. Then I can use CHtmlView:

enter image description here

The benefit is that the display is consistent wit what the user sees in the help system.

Upvotes: 1

Views: 636

Answers (0)

Related Questions