📄 image.cpp
字号:
/***********************************************************************************
@author Chandar
@version 1.0
Development Environment : Visual C++ 6.0
Name of the File : Image.cpp
Creation/Modification History :
01-Aug-2001 Created
Overview of file
This file implements the CImage class to open the image file and store the data
into LPPICTURE struct variable and to draw or display the image on the dialog
box
***********************************************************************************/
#include "stdafx.h"
#include "ADODBHandler.h"
#include "Image.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define HIMETRIC_INCH 2540
/**********************
Constructor definition
***********************/
CImage::CImage()
{
gpPicture = NULL;
}
/**********************
Destructor definition
***********************/
CImage::~CImage()
{
if(gpPicture != NULL)
gpPicture->Release();
}
/*********************************************************************
This function is used to draw the image using the device context object
passed to it in the area passed to it through CRect parameter
*********************************************************************/
BOOL CImage::DrawImage(CDC*pDC, CRect rectImage)
{
//if device context is not valid or gpPicture is null, return from function
if (pDC == NULL || gpPicture == NULL)
return FALSE;
long hmWidth = 0;
long hmHeight = 0;
//get the height and width of picture
gpPicture->get_Width (&hmWidth);
gpPicture->get_Height(&hmHeight);
HRESULT hr = NULL;
//Draw the picture
hr = gpPicture->Render(pDC->m_hDC,
rectImage.left,
rectImage.top,
rectImage.Width(),
rectImage.Height(),
0,
hmHeight,
hmWidth,
-hmHeight,
&rectImage);
if (SUCCEEDED(hr))
return TRUE; //return true if successful
return FALSE;
}
/**********************************************************************
This function takes the image file name as parameter and loads it in the
LPPICTURE struct variable which is used for drawing the image
***********************************************************************/
BOOL CImage::Open(_bstr_t strFile)
{
if (gpPicture)
(gpPicture)->Release(); //if gpPicture is not null , Release it
//Load the picture data into the gpPicture
HRESULT hr=::OleLoadPicturePath(strFile, 0, 0, 0, IID_IPicture, (LPVOID*)&gpPicture);
if (!(SUCCEEDED(hr)))
{
//Show message if failed to load the image
AfxMessageBox("Could not load image "+strFile);
return FALSE;
}
return TRUE; //Made it ...!
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -