PictureBox Custom Control

A overview of the PictureBox custom control contained in wlib.lib - created by John Findlay

library version 1.00 

Introduction:

The PictureBox control uses a normal window to display either an icon, bitmap, gif or jpg image. Each box can have its own cursor. (mouse pointer)

#include "PictureBox.h" and link with wlib.lib ole32.lib olepro32.lib uuid.lib 


There are three ways to create a PictureBox control.

1. Using the main creation API CreatePictureBox()

2. Using the normal Windows CreateWindow() API

3. Using a CONTROL statement in a dialog template.

When using CreatePictureBox the control is automatically initialized but when using CreateWindow() or the CONTROL statement in a dialog template you must use InitPictureBox first.

The image used for the PictureBox is either loaded from the resource section of the application or from disk. The identifier for the image is passed as a string when creation the control but can be changed later. In the case of a resource the string must be in the form "#xx", where xx is the resource ordinal number. When loading from disk the string must be the path + filename.

Examples using CreatePictureBox().

char globe[] = "#1";
HWND h = CreatePictureBox(WS_VISIBLE | PXS_JPG | PXS_SUNKEN | PXS_FITIMAGE,
            globe, 140, 10, 80, 80, hWnd, 2);

HWND h = CreatePictureBox(WS_VISIBLE | PXS_JPG | PXS_SUNKEN | PXS_FITIMAGE,
            "globe.jpg", 140, 10, 80, 80, hWnd, 2);

Examples using CreateWindow().

InitPictureBox();

char cables[] = "#2";
h = CreateWindow(PICTUREBOX, cables, 
        WS_CHILD | PXS_GIF | WS_VISIBLE | PXS_BORDER | PXS_FITBOX,
        20, 10, 80, 80, hWnd, (HMENU)1, hInstance, 0);
h = CreateWindow(PICTUREBOX, "cables.gif", 
        WS_CHILD | PXS_GIF | WS_VISIBLE | PXS_BORDER | PXS_FITBOX,
        20, 10, 80, 80, hWnd, (HMENU)1, hInstance, 0);

h = CreateWindowEx(WS_EX_CLIENTEDGE, PICTUREBOX, "cables.gif", 
        WS_CHILD | PXS_GIF | WS_VISIBLE | PXS_FITBOX,
        20, 10, 80, 80, hWnd, (HMENU)1, hInstance, 0);

Example using the Dialog CONTROL statement.

CONTROL "#3", 201, PICTUREBOX, PXS_JPG | PXS_BORDER | PXS_FITBOX, 2, 2, 120, 120

 

PictureBox Styles

At this time these are the styles possible with PictrureBox

PXS_ICON The PictureBox will have an icon loaded either from the resource section or from file.

PXS_ICON erases the background when necessary, other styles do not. Normally the whole box is always filled unless, as with an icon the, there are transparent sections of the image. Not erasing the background saves time.

PXS_BITMAP The PictureBox will have a bitmap image.
PXS_GIF The PictureBox will have a gif image.
PXS_JPG The PictureBox will have a jpg image.
PXS_BORDER Specifies a normal thin border.
PXS_SUNKEN The border will be recessed, 3D effect.
PXS_FITIMAGE The PictureBox will be resized to be the same dimeansions as the image.
PXS_FITBOX The image will be resized to fit the PictureBox.

 

PictureBox Messages

PXM_SETIMAGE The image can be changed using this message. Either use the SendMessage API of the custom API. Specify the type of image - BXS_BITMAP, PXS_GIF etc and the ordinal indentifier ("#x") or path and filename.

SendMessage(hCtrl, PXM_SETIMAGE, PXS_BITMAP, (LPARAM)"land.bmp");


PicBox_Image(hCtrl, PXS_BITMAP, "#2");

PXM_STYLE Change the style of the PictureBox between BXS_BODER / BXS_SUNKEN and PXS_FITBOX / PXS_FITIMAGE. If the 

The dimension of the box can be changed if PXS_FITBOX is specified and the LOWORD and HIWORD of the last parameter is set. 

Example
         cx  cy
MAKELONG(80, 60)

SendMessage(hCtrl, PXM_STYLE, PXS_BORDER | PXS_FITBOX, MAKELONG(80, 60));


PicBox_Style(hCtrl, PXS_BORDER | PXS_FITBOX, MAKELONG(80, 60));

PXM_CURSOR Set the cursor for the PictureBox at any stage after it has been created.

SendMessage(h, PXM_CURSOR, 0, (LPARAM)LoadCursor(NULL, IDC_WAIT));

PicBox_Cursor(h, LoadCursor(NULL, IDC_NO));

When linking library's be sure to link wlib.lib first - this is because lcclnk is a one pass linker.

Library's to be included are

    wlib.lib ole32.lib olepro32.lib uuid.lib 

See the example listing for usage. 


END