2

Using Visual Studio 2013 Community.

Added #include to source code. Added Shlwapi.lib to linker. Compile and link OK.

This is the code that uses EM_INSERTIMAGE:

static void insertimage( )
   {
   RICHEDIT_IMAGE_PARAMETERS rip;
   IStream *pStream = NULL;
   DWORD grfMode = STGM_READ | STGM_SHARE_DENY_NONE;
   HRESULT hr = SHCreateStreamOnFileA( "add.png", grfMode, &pStream );
   if (hr == S_OK)
      {
      ZeroMemory( &rip, sizeof( rip ) );
      rip.xWidth = 2000;   // unit 0.01mm
      rip.yHeight = 2000;
      rip.Type = TA_BASELINE;
      rip.pwszAlternateText = L"adding xyz";
      rip.pIStream = pStream;
      hr = SendMessage( hwndrichedit, EM_INSERTIMAGE, (WPARAM)0, (LPARAM)&rip );
      if (hr == S_OK)
         {
         // getting here, but not getting any image or alternate text
         // output on screen 
         }
      }
   }

but it does not output any image or alternative text on screen and does not put the image control words into the rtf file. I also tried SHCreateStreamOnFileEx with same negative result.

How can I make this work?

resander
  • 1,181
  • 2
  • 11
  • 15

2 Answers2

0

I forgot to mention I am using Windows 7.

I have been searching Google on EM_INSERTIMAGE and other keys and found a match that said EM_INSERTIMAGE requires Windows 8. I checked EM_INSERTIMAGE MSDN and found this in the Requirements section 'Minimum supported client Windows 8 [desktop apps only]'.

I did not expect this because Wordpad and Windows Office 10 on my Windows 7 PC can insert images. Also, the Linux TED richedit text editor can insert images in Ubuntu 12.04 released three years ago.

Maybe these programs just insert the image spec into rtf as required by the rtf format specification.

I assume EM_INSERTIMAGE issued by a user program would generate the image rtf part and insert it into the rtf format text.

I am happy with Windows 7 and will not change to Windows 8, so it seems I will not be able have images.

If EM_INSERTIMAGE only works on Windows 8, I think there should be an error returned when EM_INSERTIMAGE is issued from Windows 7, Windows XP etc.

resander
  • 1,181
  • 2
  • 11
  • 15
0

EM_INSERTIMAGE is only available from Windows 8 onwards. In Windows 7, you will need to use the RichEdit's OLE interface to insert images. That's how Wordpad does it. You can look up this example on MSDN:

RichEdit OLE sample

user173399
  • 464
  • 5
  • 21