www.pudn.com > final_6.rar > BitmapDlg.cpp
// BitmapDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CG.h"
#include "BitmapDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBitmapDlg dialog
CBitmapDlg::CBitmapDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBitmapDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBitmapDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBitmapDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBitmapDlg)
DDX_Control(pDX, IDC_TEXTURE_PIC, m_pic);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBitmapDlg, CDialog)
//{{AFX_MSG_MAP(CBitmapDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_OPENFILE, OnOpenfile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBitmapDlg message handlers
void CBitmapDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// CurPic->LoadFromResource(IDB_BITMAP0);
switch (Index)
{
case 0:
CurPic->LoadFromResource(IDB_BITMAP0);
break;
/* case 1:
CurPic->LoadFromResource(IDB_BITMAP1);
break;
case 2:
CurPic->LoadFromResource(IDB_BITMAP2);
break;
case 3:
CurPic->LoadFromResource(IDB_BITMAP3);
break;
case 4:
CurPic->LoadFromResource(IDB_BITMAP4);
break;*/
case 1:
if(CurPic) CurPic->Load(filename);
break;
default:
break;
}
CRect rect;
m_pic.GetWindowRect(rect);
ScreenToClient(rect);
CurPic->Draw(GetDC(),rect.left,rect.top,rect.Width(),rect.Height());
// Do not call CDialog::OnPaint() for painting messages
}
BOOL CBitmapDlg::OnInitDialog()
{
CDialog::OnInitDialog();
Index=0;
filename="";
pic.LoadFromResource(IDB_BITMAP0);
/* pic[1].LoadFromResource(IDB_BITMAP1);
pic[2].LoadFromResource(IDB_BITMAP2);
pic[3].LoadFromResource(IDB_BITMAP3);
pic[4].LoadFromResource(IDB_BITMAP4);*/
// CurPic=&pic[0];
CurPic=&pic;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBitmapDlg::OnOpenfile()
{
CFileDialog fileDialog(TRUE, "*.bmp", "",
OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT,
"Bitmap Files(*.bmp)|*.bmp||",NULL);
if(fileDialog.DoModal()==IDOK)
{
CString fn=fileDialog.GetPathName();
CString surffix=fn.Right(4);
if(surffix.CompareNoCase(".bmp")!=0)
{
AfxMessageBox("±ØÐëλͼÎļþ");
}
filename=fn;
Index=1;
Invalidate();
}
}