![]() |
Desktop Development »
Miscellaneous »
General
Intermediate
License: The Code Project Open License (CPOL)
WndImage ControlBy peterchenAn easy-to-use control to display bitmaps (stretch, scale, tile) |
VC6, MFC, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

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.
CWndImage::CreateFromStatic, to replace it with the WndImage controlSetImg: HBITMAP, Resource ID, or SetImgFile(filename)SetBltMode for predefined scaling modesSetAlign for predefined alignment (left/center/right, top/center/bottom)SetZoom and SetOrigin for custom placementSetSourceRect for displaying only a clipped rectangle of the bitmap #include wndimage.h
where you need itIDC_ST_IMG
control ID.CWndImage m_img member variable to your dialog
class OnInitDialog:m_img.CreateFromStatic( GetDlgItem(IDC_ST_IMG) ); m_img.SetImg(IDB_MYBITMAP); // specify a valid bitmap resource here m_img.SetBltMode(CWndImage::bltFitXY);
(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)
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
displayed in 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) // Load from resource
shared: if true, the WndImage control will not
bool SetImg(UINT resID, HINSTANCE instance = 0) // Load from resource
bool SetImgFile(LPCTSTR fileName) // Load from File
DeleteObject() the HBITMAP
provided upon destruction. The prototypes 2..5 do not share the bitmap.
instance: if not NULL, specifies the module handle from which to load the
bitmap
void SetBltMode(int mode)
bltNormal |
the image is drawn in it's original size | a/r | ||
bltStretch |
the image is stretched to fit the entire window | |||
bltFitX |
the image is scaled proportional, to horizontally fit the window | a/r | ||
bltFitY |
the image is scaled proportional, to vertically fit the window | a/r | ||
bltFitXY |
the image is scaled proportional to the largest possible size that does not clip the image | a/r | ||
bltFitSm |
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 image's a/r) |
a/r | ||
bltTile |
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)
void SetAlignX(int alignX)
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)
void SetZoom(double zoom)
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)
void SetOriginX(int origX)
void SetOriginY(int origY)
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)
void SetSourceRect()
by using 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(HBRUSH)
void SetBackgroundBrush(int sysColorIndex)
void SetBackgroundBrush(CBrush & brush)
Sets the brush used to fill background not occupied by the image. For
valid sysColorindex values, see GetSysColor Win32 API documentation (e.g. COLOR_WINDOW for
default window background color, or COLOR_3DFACE for default dialog background)
Initial color is COLOR_3DFACE
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 use it.
| Version 1.1 | CreateFromStatic now uses the initial bitmap (if any). |
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 May 2002 Editor: Chris Maunder |
Copyright 2000 by peterchen Everything else Copyright © CodeProject, 1999-2009 Web21 | Advertise on the Code Project |