arghh, stupid rich edit

This is a discussion on arghh, stupid rich edit within the Windows Programming forums, part of the Platform Specific Boards category; ok, well I am working on streaming rtf and I'm basically clueless on where to go from here. I got ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    4

    arghh, stupid rich edit

    ok, well I am working on streaming rtf and I'm basically clueless on where to go from here. I got rich edit working with selecting the text and all that, but for what I'm trying to accomplish its not very practical.

    Unfortunately theres not much that I could find on streaming this, but from what I did find, I came to the following conclusions.

    1) You have to stream from an actual file (Although i try not to do this in the code)
    2) The callback serves absolutely no purpose
    3) Richedit doesnt like me (ehe)

    heres snippets of the code so you can see how badly I dunno what I'm doin.

    Code:
    // The callback
    DWORD CALLBACK EditStreamCallback(DWORD dwCookie, LPBYTE lpbBuff, LONG cb, LONG FAR *pcb)
    {
        return 0;
    }
    
    // Trying to add the text
    BOOL StreamIn(HWND hwndCtrl, LPCTSTR lpszPath)
    {
        EDITSTREAM es;
    
        es.dwCookie = (DWORD)"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fcharset0 Lucida Console;}}";
        es.dwError = 0;
        es.pfnCallback = EditStreamCallback;
    
        SendMessage(hwndCtrl, EM_STREAMIN,(WPARAM)SF_TEXT, (LPARAM)&es);
    
        return(es.dwError? FALSE : TRUE);
    }
    When I try to run it, the program errors and gives me an Access Violation.

    Any ideas/links/comments are appreciated.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    4

    got it..well sorta

    Someone helped me out, this is what they did for anyone that cares:

    Code:
    long SetRTF(HWND hRicheditWnd, char* szData)
    {
    	ZeroMemory(&yummyCookie, sizeof yummyCookie);
    	ZeroMemory(&es, sizeof es);
    
    	yummyCookie.dwError = NULL;
    	yummyCookie.pbStart = (LPBYTE)szData;
    	yummyCookie.pbCur = yummyCookie.pbStart;
    	yummyCookie.bCount = strlen(szData);
    	es.dwError = NULL;
    	es.dwCookie = (DWORD)&yummyCookie;
    	es.pfnCallback = (EDITSTREAMCALLBACK)EditStreamCallback;
    	return SendMessage(hRicheditWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
    }
    
    // -------------------------- Callback, woot.
    CALLBACK EditStreamCallback(long *dwCookie, char *szBuffer, long lLength, long *lpBytesTransferred)
    {
    	PCOOKIE pCookie = (PCOOKIE)dwCookie;
    	long   bytesLeft, bytesRead;
    
    	bytesRead = pCookie->pbCur - pCookie->pbStart;
    	if (bytesRead < pCookie->bCount)
    		bytesLeft = pCookie->bCount - bytesRead;
    	else
    		bytesLeft = 0;
    	if (lLength > bytesLeft) lLength = bytesLeft;
    
    	*lpBytesTransferred = lLength;
    
    	if (lLength)
    	{
    		memcpy(szBuffer, pCookie->pbCur, lLength);
    		pCookie->pbCur += lLength;
    	}
    
    	return 0;
    }


    (thanks to vcv - http://sirc.tk)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 07-02-2007, 12:32 AM
  2. Replies: 3
    Last Post: 07-23-2005, 08:00 AM
  3. Rich edit
    By Garfield in forum Windows Programming
    Replies: 10
    Last Post: 07-10-2002, 04:08 PM
  4. Edit Control problem
    By Malek in forum Windows Programming
    Replies: 3
    Last Post: 06-16-2002, 01:12 AM
  5. Rich Edit
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 06-02-2002, 10:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21