You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
I tried the one you posted that is older, and it does handle closing correctly.
Unfortunately it does not eliminate the factor I am having.
Hopefully in the other forum I will have a post shortly as to how to replicate the problem.
I am trying to leave the INC file alone so you can see exactly what the differences are between original intent and what I caused to happen somehow.
It's older code but i took a brief peek.
I used this code somewhere else and ever made some modification to that one.
I have uploaded a new zip.
The addref and release contents are skipped.
The ..storage at the end does no longer releases the object.
Edwin,
You may want to take a look at Invalid Memory Location which started out as my problems using your Inc in a larger project, but now is boiled down to if I turn Trace On, I get an invalid memory error, but if its off I do not.
I do believe that if you want to do images via richtext, you have to make sure you have called either OleInitialize of CoInitialize[Ex] on the current thread.
While (thru 8x anyway) the compiler automatically calls CoInitialize on the primary thread, it does not automatically do so on any secondary threads you create.
Then again we have no way of knowing if this is going to be required here because... "code not shown. "
Duhh, now he won't see my products (and purchase them all)
Quite right , I almost missed it...but the example was soooo Excellent!!!!
I had to copy just the 1st part of the link....aka HelloBasic
(Had to plug for ya since even I fogot HelloBasic is yours (either I had a blonde moment or something) )
I must say THANK YOU!!!! for the example....it shows me that it is possible. (Although it uses COM interface and yet another DLL that I was trying to avoid....but when I think about it....I am already using richedit, so its not that big a deal)
To alleviate my fears, (in the back of my mind I could SWEAR that OLE32.DLL was installed only if you installed a program that needed it, and not part of the OS itself???) I could be wrong with that thought, but had to ask
I have a few questions about HelloBasic but aside from asking if there is a trial download? (could not find one), that those questions should be better fit for a different thread.
I forgot that richcom.inc also includes stream-in and stream-out functions. I didn't use them because I already had equivalents elsewhere, but richcom.inc is a complete solution.
I forgot that richcom.inc also includes stream-in and stream-out functions. I didn't use them because I already had equivalents elsewhere, but richcom.inc is a complete solution.
Find RichCom.zip, it's a no-brainer (I couldn't believe that it was that simple to use). Just include the INC in your program, make one call as you create the RichEdit control, then use standard stream-in code, as posted by MCM or as you are already using. Magic! Embedded images appear!
Thank you
--
(Code is still a bit old style, just changed it a little by adding BYVAL here and there..)
Find RichCom.zip, it's a no-brainer (I couldn't believe that it was that simple to use). Just include the INC in your program, make one call as you create the RichEdit control, then use standard stream-in code, as posted by MCM or as you are already using. Magic! Embedded images appear!
Thank you guys but I think I missed a few key points
Search for richcom.zip in the common download folder on my board.
I just updated it for PB8
Edwin, where would that be??? (sorry I should know but I dont)
MCM... are the 2 files meant as INC files??? Its been a long day so I am having trouble piecing together the info with what I know as being rtf files to see if the code works so I can learn how it works. (I know I know... , but I can't seem to find docs that straight out tell me....1 do this...2 do that, and 3 here is WHY you did 1 and 2)
That is always the way I see docs so I should NOT be suprised.
usually its...heres how to do it (if its straight forward, or cryptic if its not), but seldom do I see WHY??? I do something
Not that I question how it works, but when something goes wrong, I like to know how and why so I can fix it if I can
Cliff, there's examples here to stream that richtext.
Search on '%EM_STREAMIN' within the message text.
Oh, hell, I'm in a good mood, let me dig out my code...
Code:
' ===========================================================================
' ADDED BY MCM:
' Functions for don dickinson's RTF printer.
' This is a version of SetRTFText and the associated callback which allows
' passing a text string instead of an external file to the "setRTF" routine
' MCM 8/18/03
' TESTED, WORKS GOOD.
' ============================================================================
TYPE SetRtfBufferParmType
dwAddr AS LONG 'pointer to data
cch AS LONG ' total length of data
offset AS LONG 'current offset in data
END TYPE
FUNCTION SetRTFTextBuffer ( rtfEdit AS LONG, szBUffer AS ASCIIZ , iAttrib AS LONG ) AS LONG
'
' Purpose:
' Loads an RTF control with the contents of a string buffer
' given control handle and an NTS buffer
'
' Parameters:
' rtfEdit = Handle of a rich edit control
' szBuffer = Address of NTS containing text
' iAttrib = Either %SF_TEXT or %SF_RTF - specifies the
' type of text pointed to by szBuffer.
'
' Returns:
' %True on success
' %False if failure
'
DIM eStream AS EDITSTREAM
DIM Parm AS SetRTFBufferParmType
Parm.dwAddr = VARPTR(szBuffer) ' address of NTS
parm.cch = lStrlen(szBuffer) ' Total LEN of data to be sent to control
Parm.Offset = 0 ' how much as been sent so far from callback
eStream.dwCookie = VARPTR (Parm) ' address so we can update in callback
eStream.pfnCallback = CODEPTR(ReadStreamBufferCallback)
eStream.dwError = 0
SendMessage rtfEdit, %EM_STREAMIN, iAttrib, VARPTR(eStream)
'- The text box is dirty now ...
SendMessage rtfEdit, %EM_SETMODIFY, 1, 0
FUNCTION = %True
END FUNCTION
' PARAMS PASSED TO EM_STREAMIN CALLBACK PROC
' parm1, dwcookie In this case, address of a SetRTFBufferParmType structure
' parm2, pbBuffer Address of buffer to which to write the data
' parm3, cb Max number of bytes the control wants to accept on this call
' parm4, pCb LONG to tell control how many bytes actually written to pbBuffer
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTION ReadStreamBufferCallback ( Parm AS SetRTFBufferParmType, _
BYVAL pbBuffer AS DWORD, _
BYVAL cb AS LONG, _
pcb AS LONG) AS DWORD
LOCAL dwSource AS DWORD, BytesLeft AS LONG
BytesLeft = parm.cch - parm.offset ' how much have we NOT sent yet?
' we can send cb or bytesleft, whichever is less
pcb = MIN(BytesLeft, cb)
IF PCB THEN ' this will be zero if we have already sent EXACTLY the length of the file!
dwSource = parm.dwAddr + Parm.offset ' start of data + what's already sent
'Copy the memory to the directed buffer
copyMemory BYVAL pbBuffer, BYVAL dwSource, pcb ' use BYVALs on source, dest to avoid
' problems with conflicting Win32api.INC
' increment the offset for next trip
parm.offset = parm.offset + pcb
END IF
FUNCTION = 0
' DON'S NOTES RE RETURN
'- I always return 0. This if non-zero is returned,
' it indicates an error occured. For a "real-application"
' you probably want to check err for a read error
' during the Get operation.
' [MCM note: original code was reading a disk file for text]
'
' The edit control itself will stop calling this call-back
' if one of the following occurs ...
'
' 1. Non-zero is returned
' 2. zero returned in pcb
' 3. pcb is less than cb upon return
' 4. an error occurs transferring data into buffer (out
' of memory, etc.)
' 5. rtf data is invalid.
' 6. If the edit control is single line and a
' crlf pair is copied into the buffer.
'
END FUNCTION
Yes, it originally came from Don Dickinson.
Here's a version which uses a file instead of a string:
Code:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTION SetRTFText ( rtfEdit AS LONG, sFileName AS STRING, iAttrib AS INTEGER ) AS INTEGER
'
' Purpose:
' Loads an RTF control with the contents of an RTF file given
' the control's window handle and the name of the file.
'
' Parameters:
' rtfEdit = Handle of a rich edit control
' sFileName = File name to read
' iAttrib = Either %SF_TEXT or %SF_RTF - specifies the
' type of file to be read.
'
' Returns:
' %True on success
' %False if failure
'
DIM hFile AS LONG
DIM eStream AS EDITSTREAM
DIM ofS AS OFSTRUCT
ON ERROR RESUME NEXT
hFile = FREEFILE
OPEN sFileName FOR BINARY AS #hFile
IF ERR THEN
'- unable to open file
FUNCTION = %False
ELSE
eStream.dwCookie = hFile
eStream.pfnCallback = CODEPTR(ReadStreamCallback)
eStream.dwError = 0
SendMessage rtfEdit, %EM_STREAMIN, iAttrib, VARPTR(eStream)
'- The text box is dirty now ...
SendMessage rtfEdit, %EM_SETMODIFY, 1, 0
CLOSE #hFile
FUNCTION = %True
END IF
END FUNCTION
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FUNCTION ReadStreamCallback ( BYVAL dwCookie AS DWORD, _
BYVAL pbBuffer AS BYTE PTR, _
BYVAL cb AS LONG, _
pcb AS LONG) AS DWORD
DIM rOver AS OVERLAPPED
DIM sInput AS STRING
DIM iBuf AS LONG
DIM iCopyLen AS LONG
'- Find out if the amount requested is
' beyond the end of the file.
'
IF LOF(dwCookie) - LOC(dwCookie) < 0 THEN
iCopyLen = LOF(dwCookie) - LOC(dwCookie)
ELSE
iCopyLen = cb
END IF
sInput = SPACE$(iCopyLen)
'- Incoming data
GET #dwCookie, , sInput
pcb = iCopyLen
'- Yes, this is sort of slow, but
' I just whipped this together. You
' could use rtlCopyMemory to transfer
' the memory more quickly, but I can't
' remember it's syntax, so I'll use pointers.
'
FOR iBuf = 0 TO iCopyLen - 1
@pbBuffer = ASC(MID$(sInput, iBuf + 1, 1))
pbBuffer = pbBuffer + 1
NEXT iBuf
'- I always return 0. This if non-zero is returned,
' it indicates an error occured. For a "real-application"
' you probably want to check err for a read error
' during the Get operation.
'
' The edit control itself will stop calling this call-back
' if one of the following occurs ...
'
' 1. Non-zero is returned
' 2. zero returned in pcb
' 3. pcb is less than cb upon return
' 4. an error occurs transferring data into buffer (out
' of memory, etc.)
' 5. rtf data is invalid.
' 6. If the edit control is single line and a
' crlf pair is copied into the buffer.
'
FUNCTION = 0
END FUNCTION
I am hoping someone has the answer. The closest I have found is an old post from Borge Hagsten about displaying an image in the richedit, but it eluded to OLE (as well as all the googling I have done the past few days)
Could PB9 be the answer? (I am still waiting for my copy to see all the new features)
Currently I am attempting (and have attempted, and have attempted many many MANY times in the past) to load an RTF file into a richedit. But it only works with actual text, and not a hex representation of the image (like you would see if you open an RTF in notepad)
Should be a simple concept....but I can not find it....Am I missing something? or Is PB9 to be an answer for what I am missing? or is it not possible? (has to be possible because many editors can read RTF with images, and they all use the RichEdit, so obviously I am missing SOMETHINNNNNNG???? but what I do not know)
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: