News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Codeproject - Embedding .PNG images into a RichEdit document

Started by aw27, April 05, 2019, 04:35:49 AM

Previous topic - Next topic

hutch--

Magnus,

Have a look at an editor in MASM32 called "uniedit.exe". It ran on XP and if you are using an OS from Win7 upwards, all of the east Asian fonts are present. On XP you had to load language packs but not on later OS versions. QE is an ASCII code editor, it will never be multi-lingual.

daydreamer

Quote from: hutch-- on April 06, 2019, 10:32:48 AM
Have a look at an editor in MASM32 called "uniedit.exe". It ran on XP and if you are using an OS from Win7 upwards, all of the east Asian fonts are present. On XP you had to load language packs but not on later OS versions. QE is an ASCII code editor, it will never be multi-lingual.
Thanks
In a way qeditor becomes multilingual when it's used by a multilingual coder,comments in their native language,, 5000+Japanese unicodes in. Data section, use it for java
my none asm creations
https://masm32.com/board/index.php?topic=6937.msg74303#msg74303
I am an Invoker
"An Invoker is a mage who specializes in the manipulation of raw and elemental energies."
Like SIMD coding

aw27

I have updated the article with a table of RichEdit controls by Windows OS and MS Office. People interested can also download the respective Excel sheet I am attaching here. I have also found a better way to advance the caret after embedding the image and have updated the article with that.

I have been talking that for older versions of the RichEdit we can embed .BMP files. I wasn't meaning display clickable links but show the real image. I also mentioned that it is difficult, in particular for bitmaps in the resources (it is easier when loaded from file or dropped from the clipboard). I know how to do it in C++ and in Delphi but I think it is extremely difficult to do it either in ASM or in C.
May be somebody want to try.  :idea:  :t  :biggrin:

aw27

Quote from: AW on April 08, 2019, 03:25:26 AM
I have been talking that for older versions of the RichEdit we can embed .BMP files. I wasn't meaning display clickable links but show the real image. I also mentioned that it is difficult, in particular for bitmaps in the resources (it is easier when loaded from file or dropped from the clipboard). I know how to do it in C++ and in Delphi but I think it is extremely difficult to do it either in ASM or in C.
May be somebody want to try.  :idea:  :t  :biggrin:

Let me answer to my own post  :lol:

I have solved it for C, which means that it is automatically solved for ASM, but I will not do it.

The real problem is that C does not handle classes.  However, C handles structures  :biggrin:

For people that want to try I will leave here a C++ reference link:
http://www.ucancode.net/VC_Library_Control_Tool/Insert-a-bitmap-file-HBITMAP-into-Rich-Edit-Control-COleDataSource-CF_BITMAP-STGMEDIUM-vc.htm

I will not post the C solution here, may be I will on CodeProject.

TimoVJL

Those who want to see C, a simple example of InsertBitmap and IDataObject in C code.
It just insert a one bitmap to richedit.
May the source be with you

aw27

Quote from: TimoVJL on April 09, 2019, 06:32:24 AM
Those who want to see C, a simple example of InsertBitmap and IDataObject in C code.
It just insert a one bitmap to richedit.

Well done.  :t
People could confirm that there is no easy way to do it.

jj2007

Quote from: TimoVJL on April 09, 2019, 06:32:24 AM
Those who want to see C, a simple example of InsertBitmap and IDataObject in C code.
It just insert a one bitmap to richedit.

Excellent, Timo :t

What's the difference between the two versions? Attached a version by Mike Lytle, unfortunately I can't get it to work on my C installations. There is also the old MSDN Q220844: HOWTO: Insert a Bitmap Into RTF Document Using RichEdit Control

TimoVJL

Last one is just a bit cleaner ;)
How to Use OLE in Rich Edit Controls
EDIT: OleCreateFromFile() needs full path name.
May the source be with you


aw27

I have updated the article with a demo, now using the  TOM2's TextRange2::InsertImage() method.
The demo loads a text then when you press the button replace spaces with .pngs.





The demo is in C++, but is easily translated to C and then to ASM, as usual.  :lol:

The real difference between C++ and C, in this case, is in the syntax for calling the interface methods.
For example, in C++:
hr = pDocument2->GetSelection2(&pSelection2);
in C:
hr = pDocument2->lpVtbl->GetSelection2(pDocument2 ,&pSelection2);
In ASM, using the coInvoke macro, it will become similar to the C syntaxe. If you don't use the coInvoke macro, it is a lot of fun but is difficult to figure out.





jj2007

Nice demo. Your program is Windows 8+ only, though. Depending on the Office installation, a Win7 user (like me) may find the ITextRange2 interface in C:\Program Files (x86)\Common Files\Microsoft shared\OFFICE12\RICHED20.DLL but not in C:\Program Files (x86)\Common Files\Microsoft shared\OFFICE12\RICHED20.DLL

aw27

I don't know if the problem for Windows 7 is the ITextRange2 or the ITextSelection2 interface, would need to check. I have used the ITextSelection2 to reach the ITextRange2 but it can be reached as well from the ITextDocument2.
You may be right, although I have doubts you can use InsertImage from pRange2 with Office 2007/Office 12. It is so old.

TimoVJL

MS Office 2013 riched20.dll is version 8, insert image works.
const GUID IID_ITextDocument2={0xC241F5E0,0x7206,0x11D8,0xA2,0xC7,0x00,0xA0,0xD1,0xD6,0xC6,0xB3};
IID_ITextDocument2 was exported from that dll.
In TLB InsertImage was hidden by missing line after GetMathFunctionType() HRESULT (STDMETHODCALLTYPE *InsertImage)(ITextRange2 *This,LONG,LONG,LONG,LONG,BSTR,IStream*);a silly test if (pDocument) {
IStream *pStream = NULL;
ITextRange2 *pTextRange2;
HRESULT hr = SHCreateStreamOnFile(L"test.png", STGM_READ | STGM_SHARE_DENY_NONE, &pStream);
hr = pDocument->lpVtbl->Range2(pDocument, 0, 0, &pTextRange2);
hr = pTextRange2->lpVtbl->InsertImage(pTextRange2, 1000, 1000, 0, 0, L"test.png", pStream);
}
BTW: Tested in Windows 7.
May the source be with you

aw27

For Office 2016, and probably 2019, InsertImage was the latest method added to ITextRange2. It seats just after GetMathFunctionType.
I have an old computer with Office 14 and its Riched20.dll has no InsertImage method. The latest one is GetMathFunctionType.

TimoVJL

If EM_INSERTIMAGE works, InsertImage might be there too.
15.0.4693.1000 was under test.
May the source be with you