Displaying Enlarged Images in Popup Window

Murray Sargent

RichEdit clients may want to zoom images that the user clicks on. To satisfy this need, the Microsoft 365 version of RichEdit supports the EN_IMAGE notification, which notifies the RichEdit client when the mouse moves over an image or the image is clicked on. The client can then display an enlarged image in a new window by sending the RichEdit control an EM_DISPLAYIMAGE message. This approach is efficient since the image is already in the RichEdit control’s memory and doesn’t have to be streamed out and back into another control. RichEdit calls the Windows Imaging Component (WIC) to create a bitmap scaled to the new dimensions. This is important since otherwise the image would be blurry. The code assumes that the new window has the same resolution as the RichEdit window. This post documents the EN_IMAGE notification and the EM_DISPLAYIMAGE message.

EN_IMAGE notification

Enable the EN_IMAGE notification by sending an EM_SETEVENTMASK message with lParam equal to an event mask that includes the ENM_IMAGE flag defined by

#define ENM_IMAGE      0x00000400    // Event mask for mouse over image

In RichEdit window controls, the notification is sent to the parent window packaged in a WM_NOTIFY message with lParam being a pointer to an ENIMAGE struct defined by

typedef struct _enimage
   NMHDR         nmhdr;        // Notification header
   UINT          msg;          // Message causing notification, e.g. WM_LBUTTONDOWN
   WPARAM        wParam;       // Msg wParam
   LPARAM        lParam;       // Msg lParam
   IMAGEDATA     ImageData;    // Image Data

where nmhdr.code = EN_IMAGE defined by

#define EN_IMAGE       0x0721 // Notification when mouse is over an image

IMAGEDATA is defined by

typedef struct _imagedata
   LONG          cp;           // cp of image in RichEdit control
   IMAGETYPE     Type;         // Image type
   LONG          Width;        // Image width in HIMETRIC units
   LONG          Height;       // Image height in HIMETRIC units

and IMAGETYPE is defined by

typedef enum _IMAGETYPE
   IT_UNKNOWN                    // User installed WIC codec

In windowless RichEdit controls, EN_IMAGE is passed to the host via an ITextHost::TxNotify() call. If the image is singly selected, RichEdit doesn’t send EN_IMAGE notifications so that users can use the mouse to resize the image.


Clients can display an enlarged image whenever desired by sending the EM_DISPLAYIMAGE message defined by

#define EM_DISPLAYIMAGE                     (WM_USER + 386)

The message wParam is a pointer to an IMAGEDATA structure defined above. The message lParam is an ID2D1RenderTarget* for the target window. The client should supply the desired new IMAGEDATA::Width and Height in HIMETRIC units. For example, on receipt of an EN_IMAGE notification, the client can use the data in the IMAGEDATA struct included in the ENIMAGE notification struct. The Width and Height values determine the image aspect ratio, which should be maintained in the enlarged image.

Here is an example with an image of the Matterhorn in the edit control (upper image) and an enlarged image below it

Image MatterhornWithZoom


Discussion is closed.

Feedback usabilla icon