转载自:http://blog.csdn.net/norains/article/details/3957029
CImage是控件中最简单的一个,IMAGE是配置文件中也属于简单的一位。这简单的两者组合起来,就构成了程序中图片的显示。
CImage的头文件定义如下:
// Image.h: interface for the CImage class.
//
//
#pragma once
#include "..//Table//imageTabBase.h"
class CImage
{
public:
//Before using you must call the function
//--------------------------------------------------------------------
//Description:
// Set image table object
//
//-------------------------------------------------------------------
void SetImgTab(CImageTabBase &imgTab);
public:
//--------------------------------------------------------------------
//Description:
// Set the button position
//
//-------------------------------------------------------------------
void SetImgPosition(const RECT &rcWndImg);
//--------------------------------------------------------------------
//Description:
// Set the visible
//
//Parameters:
// bVisible:[in]
// TRUE - visible
// FALSE - invisible
//
//--------------------------------------------------------------------
void SetVisible(BOOL bVisible);
//--------------------------------------------------------------------
//Description:
// Set the transparent mode
//
//Parameters:
// bTran:[in]
// TRUE - Don't draw the transparent color
// FALSE - Draw all the color
//
//-------------------------------------------------------------------
void SetTransparent(BOOL bTran);
//--------------------------------------------------------------------
//Description:
// Set the transparent color
//
//-------------------------------------------------------------------
void SetTransparentColor(COLORREF crColor);
//--------------------------------------------------------------------
//Description:
// Draw the button
//
//-------------------------------------------------------------------
BOOL Draw(HDC hdc);
//--------------------------------------------------------------------
//Description:
// Set the image index
//
//-------------------------------------------------------------------
void SetImgIndex(TSTRING strIndex);
//--------------------------------------------------------------------
//Description:
// Get the image index
//
//-------------------------------------------------------------------
TSTRING GetImgIndex();
public:
CImage();
virtual ~CImage();
private:
RECT m_rcWndImg;
COLORREF m_crTranColor;
BOOL m_bTran;
BOOL m_bVisible;
TSTRING m_ImgIndex;
CImageTabBase *m_pImgTab;
CImage的大部分函数,都和配置文件相关,由MUF读取然后自动调用,用户基本上不必进行干预。在实际的程序中,大概可能用到的也就只有两个函数,分别是SetVisible和SetImgIndex。顾名思义,前者是设置该控件是否可用,后者则是显示图片的序号(该序号是在配置文件中定义的)。
配置文件也非常简单,只有简简单单的四项:
TYPE:控件类型,这里只能为IMAGE
RECT_POS:在窗口的位置
IMAGE_FILE:图片的序列
TRANSPARENT_MODE:取值为TRUE或FALSE。当为TRUE时,不绘制透明色。
简单的一个配置文件的例子:
[CIMG_BOOK]
TYPE=IMAGE
RECT_POS=0,0,480,272
IMAGE_FILE=IMG_BOOK
TRANSPARENT_MODE=TRUE
[IMG_BOOK]
TYPE=IMAGE_FILE
RECT_FILE=48,135,95,179
FILE_NAME="%STARTUP_PATH%/UIImage/book.bmp"
TRANSPARENT_COLOR=255,0,255
对于上述的配置文件,MUF其实会自动调用如下函数:
//伪代码
CImage::SetImgPosition(RECT(0,0,480,272));
CImage::SetTransparent(TRUE);
CImage::SetTransparentColor(RGB(255,0,255));
CImage::SetImgIndex(IMG_BOOK)
除非用户在后续中对此会有更改,一般这些函数都不必再次调用。