CWndImage can display a Windows Bitmap at arbitrary scales. It provides default scale
and alignment modes for easy use, while free scaling and shifting, and a tile mode, is
also available. This control can be handy if you have problems with the size of bitmaps in
dialogs at different systems.
No image processing, rotating, shearing available or intended.
- Easy use: put a static control on a dialog resource, then call
CWndImage::CreateFromStatic, to replace it with the
HBITMAP, Resource ID, or
SetBltMode for predefined scaling modes
SetAlign for predefined alignment (left/center/right, top/center/bottom)
SetZoom and SetOrigin for custom placement
SetSourceRect for displaying only a clipped rectangle of the bitmap
- add the WndImage.h and wndImage.cpp to your project,
where you need it
- add a static or "picture" control to one of your dialogs. Give it an
- Add a
CWndImage m_img member variable to your dialog
- Add the following lines to
m_img.CreateFromStatic( GetDlgItem(IDC_ST_IMG) );
(if you used a picture control, and already specified a bitmap, you can even omit the
second and third line)
BOOL Create(RECT const & r, CWnd * parent, UINT id,
DWORD dwStyle = WS_CHILD | WS_VISIBLE)
BOOL CreateFromStatic(CWnd * static)<br>
CreateFromStatic will use a static control's style, position, and ID, and
replace it with the wndImage control. If a bitmap was specified for the static control
(you nedd to choose 'picture control' in the resource editor for this), this bitmap is
FitXY mode (stretched proportional to fit without clipping).
Not that only window-specific styles (like
WS_BORDER) will be visible with the
control. Window styles specific to static controls have no effect
void SetImg(HBITMAP bmp, bool shared = false)
void SetImg(CBitmap * bmp)
bool SetImg(LPCTSTR resID, HINSTANCE instance = 0)
bool SetImg(UINT resID, HINSTANCE instance = 0)
bool SetImgFile(LPCTSTR fileName)
: if true, the WndImage control will not
provided upon destruction. The prototypes 2..5 do not share the bitmap.
: if not NULL, specifies the module handle from which to load the
Standard Blit Modes
void SetBltMode(int mode)
| || |
| ||the image is drawn in it's original size ||a/r |
| || |
| ||the image is stretched to fit the entire window || |
| || |
| ||the image is scaled proportional, to horizontally fit the window ||a/r |
| || |
| ||the image is scaled proportional, to vertically fit the window ||a/r |
| || |
| ||the image is scaled proportional to the largest possible size that does not
clip the image ||a/r |
| || |
| ||the image is scaled proportional so that one coordinate fits the window and the
other is clipped |
(this mode is good for small views whose aspect ratio differs strongly from the
| || |
| ||the image is repeated in it's original size to fit the window ||a/r |
Note: the constants must be prefixed with "CWndImage::"
Note: a/r: These modes preserve the image's aspect ratio
void SetAlign(int alignX, int alignY)<br>
void SetAlignX(int alignX)<br>
void SetAlignY(int alignY)
Valid alignments are: bltLeft,
bltTop, bltCenter, bltRight, bltBottom (I hope you can figure out their meaning)
void SetZoom(double zoomX, double zoomY)<br>
void SetZoom(double zoom)<br>
Sets a zoom factor (1.0 == original size, <1 smaller, >1 larger).
The second prototypwe sets a proportional zoom with
zoomX == zoomY
Custom Zoom cannot be used together with bltTile mode.
void SetOrigin(int origX, int origY)<br>
void SetOriginX(int origX)<br>
void SetOriginY(int origY)<br>
Sets the position of the images left upper corner in the window. positive
values move the image to the center, negative values move it out of sight.
Custom alignment can be used with tiling, too
void SetSourceRect(RECT const & r)<br>
SetSourceRect, you can specify a clipping rectangle for the
bitmap. This can be used with all modes. The coordinates are in bitmap pixels. The secnod
prototype restores the setting to the entire bitmap.
When the image is changed (SetImg, SetImgFile), all settings except the Source
window are preserved. Source window is reset to the entire image.
void SetBackgroundBrush(int sysColorIndex)<br>
void SetBackgroundBrush(CBrush & brush)<br>
Sets the brush used to fill background not occupied by the image. For
valid sysColorindex values, see
GetSysColor Win32 API documentation (e.g.
default window background color, or
COLOR_3DFACE for default dialog background)
Initial color is
int GetImgSizeX() const
int GetImgSizeY() const
int GetBltMode() const
double GetZoomX() const
double GetZoomY() const
int GetAlignX() const
int GetAlignY() const
int GetOriginX() const
int GetOriginY() const
These functions return what they promise. The values are correct even in
standard blit or alignment modes.
HBITMAP GetBitmap(bool detach = false)
Returns a handle the bitmap in use. If detach is true, the control will no longer
|Version 1.1 || |
CreateFromStatic now uses the initial bitmap (if any).