// Image.cpp : implementation file
//
#include "stdafx.h"
#include "picture.h"
#include "Image.h"
#include
#include
#include
#include "Image.h"
#include "pictureDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Image dialog
int aa,bb,cc,dd;
int ii=4;
int ll;
bool mybool=FALSE;
bool btnbool=TRUE;
RECT rect={7,39,698,450};
int jj=0;
CString namestr;//得到图片的名字
Image::Image(CWnd* pParent /*=NULL*/)
: CDialog(Image::IDD, pParent)
{
//{{AFX_DATA_INIT(Image)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void Image::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(Image)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(Image, CDialog)
//{{AFX_MSG_MAP(Image)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Image message handlers
BOOL Image::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void Image::OnPaint()
{
CPaintDC dc(this); // device context for painting
//*******画背景********//
CDC memory;
mycbitmap=new CBitmap;
mycbitmap->LoadBitmap(IDB_BITMAP2);
memory.CreateCompatibleDC(&dc);
memory.SelectObject(mycbitmap);
RECT myrect;
GetWindowRect(&myrect);
dc.BitBlt(0,0,myrect.right-myrect.left,myrect.bottom-myrect.top,&memory,0,0,SRCCOPY);
//*********画图片********//
CDC memory1;
mycbitmap1=new CBitmap;
memory1.CreateCompatibleDC(&dc);
myhbitmap1=drow(namestr);
mycbitmap1=CBitmap::FromHandle(myhbitmap1);
BITMAP mybmp1;
mycbitmap1->GetBitmap(&mybmp1);
memory1.SelectObject(mycbitmap1);
RECT myrect1;
GetWindowRect(&myrect1);
aa=myrect1.right-myrect1.left;
bb=myrect1.bottom-myrect1.top;
cc=400;
dd=240;
if(mybool)//mybool为真执行全屏操作
{
dc.StretchBlt(0,0,aa,bb,&memory1,0,0,mybmp1.bmWidth,mybmp1.bmHeight,SRCCOPY);//StretchBlt()完成图片的缩放功能
mybool=FALSE;
}
else
{
dc.StretchBlt((cc-90)-(80*ii/2),(dd-20)-(48*ii/2),80+(80*ii),48+(48*ii),&memory1,0,0,mybmp1.bmWidth,mybmp1.bmHeight,SRCCOPY);
}
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
//********等到文件名*************//
void Image::Getimagename(CString str)
{
namestr=str;
}
//*********把图片画到内存*********//
HBITMAP Image::drow(CString strFileName)
{
IImage* m_pImage = NULL;
IImagingFactory* m_pImagingFactory = NULL;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
HRESULT hr = CoCreateInstance(CLSID_ImagingFactory, NULL,CLSCTX_INPROC_SERVER,IID_IImagingFactory,(void **)&m_pImagingFactory);
HBITMAP hBitmap = 0;
ImageInfo imageInfo;
if (SUCCEEDED(hr))
{
hr = m_pImagingFactory->CreateImageFromFile(strFileName, &m_pImage);//从内存中读取图片
if (FAILED(hr))
{
return 0;
}
m_pImage->GetImageInfo(&imageInfo);
CWindowDC dc(0);
CDC dcBitmap;
dcBitmap.CreateCompatibleDC(&dc);
hBitmap = CreateCompatibleBitmap(dc.GetSafeHdc(), imageInfo.Width, imageInfo.Height);
if (hBitmap)
{
HGDIOBJ hOldBitmap = dcBitmap.SelectObject(hBitmap);
m_pImage->Draw(dcBitmap.GetSafeHdc(), CRect(0, 0, imageInfo.Width, imageInfo.Height), NULL);
dcBitmap.SelectObject(hOldBitmap);
}
m_pImage->Release();
}
m_pImagingFactory->Release();
CoUninitialize();
return hBitmap;
}
//**********确定有效区域*************//
BOOL Image::InRect(int left, int top, int right, int bottom, int px, int py)
{
if((left < 0) || (left > 800))
return FALSE;
if((right < 0) || (right > 800))
return FALSE;
if((top < 0) || (top > 480))
return FALSE;
if((bottom < 0) || (bottom > 480))
return FALSE;
if((px < 0) || (px > 800))
return FALSE;
if((py < 0) || (py > 480))
return FALSE;
if((px>=left)&&(px=top)&&(py return TRUE;
return FALSE;
}
//*******关闭窗口********//
void Image::OnButton1()
{
// TODO: Add your control notification handler code here
DestroyWindow();
}
//*********全屏显示**********//
void Image::OnButton2()
{
// TODO: Add your control notification handler code here
if (btnbool==TRUE)//判断中间区域激活,按钮区就不能用,用BOOL做选择
{
mybool=TRUE;
InvalidateRect(NULL,TRUE);
UpdateWindow();
btnbool=FALSE;
}
}
//*********缩小**********//
void Image::OnButton3()
{
// TODO: Add your control notification handler code her
if(btnbool==TRUE)
{
if(ii>=1)
ii--;
else
ii==1;
InvalidateRect(&rect,TRUE);
UpdateWindow();
}
}
//*********放大**********//
void Image::OnButton4()
{
// TODO: Add your control notification handler code here
if(btnbool==TRUE)
{
ii++;
InvalidateRect(&rect,TRUE);//刷新区域会自动调用OnPaint()进行重绘
UpdateWindow();//执行立即刷新
}
}
void Image::OnButton5()
{
// TODO: Add your control notification handler code here
if(btnbool==TRUE)
{
if(ll>=1)
{
namestr=Imagelist[ll-1];
InvalidateRect(&rect,TRUE);
UpdateWindow();
ll--;
}
}
}
void Image::OnButton6()
{
// TODO: Add your control notification handler code here
if(btnbool==TRUE)
{
if(ll+1 {
namestr=Imagelist[ll+1];
InvalidateRect(&rect,TRUE);
UpdateWindow();
ll++;
}
}
}
//*********复位**********//
void Image::OnButton7()
{
// TODO: Add your control notification handler code here
if(btnbool==TRUE)
{
ii=4;
InvalidateRect(&rect,TRUE);
UpdateWindow();
HWND MyhWnd;
MyhWnd = ::FindWindow(NULL,L"图片列表");
if(MyhWnd)
::SetForegroundWindow(MyhWnd);
CPictureDlg *mypict;
// mypict = (CPictureDlg*)(AfxGetApp()->m_pMainWnd);的到主窗口
// mypict->ShowWindow(TRUE);
}
}
void Image::OnButton8()
{
// TODO: Add your control notification handler code here
if(btnbool==FALSE)
{
ii=4;
InvalidateRect(&rect,TRUE);
UpdateWindow();
btnbool=TRUE;
}
}
void Image::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (InRect(727,3,771,40,point.x,point.y))
{
OnButton1();
}
if (InRect(724,67,774,99,point.x,point.y))
{
OnButton2();
}
if (InRect(724,128,777,157,point.x,point.y))
{
OnButton3();
}
if (InRect(726,191,775,221,point.x,point.y))
{
OnButton4();
}
if (InRect(725,254,775,280,point.x,point.y))
{
OnButton5();
}
if (InRect(728,316,777,342,point.x,point.y))
{
OnButton6();
}
if (InRect(728,381,778,409,point.x,point.y))
{
OnButton7();
}
if (InRect(10,10,700,450,point.x,point.y))
{
OnButton8();
}
CDialog::OnLButtonUp(nFlags, point);
}
//****得到双击文件的索引*******//
void Image::GetIndex(int t)
{
ll=t;
}
//********把文件路径放到Imagelist容器**********//
void Image::Receptname(CString b)
{
if(jj==0)
{
Imagelist.insert(Imagelist.begin(),b);//遍历文件时把图片文件明保存在Imageliste容器中
}
if(jj>=1)
{
Imagelist.insert(Imagelist.end(),b);
}
jj++;
}