mCtrl  0.10.0
imgview.h File Reference

Go to the source code of this file.

Detailed Description

Image view control (MC_WC_IMGVIEW).

Image view control is specialized control for displaying an image. Unlike the standard STATIC control which can only support bitmaps and icons, the image view control supports more image formats: BMP, ICON, GIF, JPEG, PNG, TIFF, WMF and EMF.

Attention
The image view control requires GDIPLUS.DLL version 1.0 or newer to work correctly. This library was introduced in Windows XP and Windows Server 2003. If your application needs to use this control on Windows 2000, you may need to distribute GDIPLUS.DLL along with your application. (Microsoft released GDIPLUS.DLL 1.0 as a redistributable for this purpose.)

Control Creation

The control can display images loaded from a file as well as images embedded as resources in a DLL or EXE module. Note that window text as passed into CreateWindow() is interpreted as a name of a resource in the same module as specified by the @ HMODULE handle passed into the function. It may also specify the integer ID of a resource with the MAKEINTRESOURCE, or in the form "#123".

This allows to create the control and associate an image directly in the resource script:

50 RCDATA path/to/image1.png
51 RCDATA path/to/image2.jpg
"imgname" RCDATA path/to/image3.bmp
IDD_DIALOG DIALOG 100, 100, 74, 150
STYLE WS_POPUP | WS_CAPTION | WS_SYSMENU | DS_MODALFRAME
EXSTYLE WS_EX_DLGMODALFRAME
CAPTION "mCtrl Example: IMGVIEW Control"
FONT 8, "MS Shell Dlg"
BEGIN
CONTROL 50, IDC_IMGVIEW_PNG, MC_WC_IMGVIEW, 0, 7, 7, 16, 16, WS_EX_STATICEDGE
CONTROL "#51", IDC_IMGVIEW_PNG, MC_WC_IMGVIEW, 0, 30, 7, 16, 16, WS_EX_STATICEDGE
CONTROL "imgname", IDC_IMGVIEW_PNG, MC_WC_IMGVIEW, 0, 51, 7, 16, 16, WS_EX_STATICEDGE
END

Note the control only looks for image resources of the following resource types: RT_RCDATA, RT_BITMAP (bitmaps only), "PNG" (PNG only) or RT_HTML. (The last option is the application uses the image also with the MC_WC_HTML control).

Setting the Image

It is also possible to set the image in the application run time.

Use message MC_IVM_LOADRESOURCE to set the image from the resource of a DLL or EXE module. Note the application is responsible to ensure the module is not unloaded while the image is in use by the control I.e. until the control is associated with different image, or until the control is destroyed.

To load the image from a file, use the message MC_IVM_LOADFILE.

Image Scaling

By default, the image is scaled so that its aspect ratio is preserved, and as much of the control area is utilized as possible.

Application can change this behavior by specifying the style MC_IVS_REALSIZECONTROL, which scales the image to the size of the control without preserving the aspect ratio; or by the style MC_IVS_REALSIZEIMAGE which suppresses the scaling altogether.

Initialization Functions

BOOL mcImgView_Initialize (void)
 
void mcImgView_Terminate (void)
 

Window Class

#define MC_WC_IMGVIEWW   L"mCtrl.imgView"
 
#define MC_WC_IMGVIEWA   "mCtrl.imgView"
 

Control Styles

#define MC_IVS_TRANSPARENT   0x00000001
 When set, the control background is transparent. More...
 
#define MC_IVS_REALSIZECONTROL   0x00000100
 When set, the image is scaled to dimensions of the control. More...
 
#define MC_IVS_REALSIZEIMAGE   0x00000200
 When set, the image is painted in its original dimensions. More...
 

Control Messages

#define MC_IVM_LOADRESOURCEW   (MC_IVM_FIRST + 0)
 Load image from a resource (Unicode variant). More...
 
#define MC_IVM_LOADRESOURCEA   (MC_IVM_FIRST + 1)
 Load image from a resource (ANSI variant). More...
 
#define MC_IVM_LOADFILEW   (MC_IVM_FIRST + 2)
 Load image from a file (Unicode variant). More...
 
#define MC_IVM_LOADFILEA   (MC_IVM_FIRST + 3)
 Load image from a file (ANSI variant). More...
 

Unicode Resolution

#define MC_WC_IMGVIEW   MCTRL_NAME_AW(MC_WC_IMGVIEW)
 
#define MC_IVM_LOADRESOURCE   MCTRL_NAME_AW(MC_IVM_LOADRESOURCE)
 
#define MC_IVM_LOADFILE   MCTRL_NAME_AW(MC_IVM_LOADFILE)
 

Macro Definition Documentation

#define MC_WC_IMGVIEWW   L"mCtrl.imgView"

Window class name (Unicode variant).

#define MC_WC_IMGVIEWA   "mCtrl.imgView"

Window class name (ANSI variant).

#define MC_IVS_TRANSPARENT   0x00000001

When set, the control background is transparent.

#define MC_IVS_REALSIZECONTROL   0x00000100

When set, the image is scaled to dimensions of the control.

Note
This style cannot be used together with MC_IVS_REALSIZEIMAGE.
#define MC_IVS_REALSIZEIMAGE   0x00000200

When set, the image is painted in its original dimensions.

If the control is too small, only part of the image is painted.

Note
This style cannot be used together with MC_IVS_REALSIZECONTROL.
#define MC_IVM_LOADRESOURCEW   (MC_IVM_FIRST + 0)

Load image from a resource (Unicode variant).

Parameters
[in]wParam(HINSTANCE) Module providing the resource.
[in]lParam(const WCHAR*) Resource name.
Returns
(BOOL) TRUE on success, FALSE otherwise.
Note
The message can be used to reset the control so it does not display any image, if both parameters are set to zero.
#define MC_IVM_LOADRESOURCEA   (MC_IVM_FIRST + 1)

Load image from a resource (ANSI variant).

Parameters
[in]wParam(HINSTANCE) Module providing the resource.
[in]lParam(const char*) Resource name.
Returns
(BOOL) TRUE on success, FALSE otherwise.
Note
The message can be used to reset the control so it does not display any image, if both parameters are set to zero.
#define MC_IVM_LOADFILEW   (MC_IVM_FIRST + 2)

Load image from a file (Unicode variant).

Parameters
wParamReserved, set to zero.
[in]lParam(const WCHAR*) File path.
Returns
(BOOL) TRUE on success, FALSE otherwise.
Note
The message can be used to reset the control so it does not display any image, if both parameters are set to zero.
#define MC_IVM_LOADFILEA   (MC_IVM_FIRST + 3)

Load image from a file (ANSI variant).

Parameters
wParamReserved, set to zero.
[in]lParam(const char*) File path.
Returns
(BOOL) TRUE on success, FALSE otherwise.
Note
The message can be used to reset the control so it does not display any image, if both parameters are set to zero.
#define MC_WC_IMGVIEW   MCTRL_NAME_AW(MC_WC_IMGVIEW)

Unicode-resolution alias.

See also
MC_WC_IMGVIEWW MC_WC_IMGVIEWA
#define MC_IVM_LOADRESOURCE   MCTRL_NAME_AW(MC_IVM_LOADRESOURCE)

Unicode-resolution alias.

See also
MC_IVM_LOADRESOURCEW MC_IVM_LOADRESOURCEA
#define MC_IVM_LOADFILE   MCTRL_NAME_AW(MC_IVM_LOADFILE)

Unicode-resolution alias.

See also
MC_IVM_LOADFILEW MC_IVM_LOADFILEA

Function Documentation

BOOL mcImgView_Initialize ( void  )

Registers window class of the control.

Returns
TRUE on success, FALSE on failure.
void mcImgView_Terminate ( void  )

Unregisters window class of the control.