www.pudn.com > 一个可自动演示的图片控件.rar > CStaticBmpDlg.cpp


// CStaticBmpDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "CStaticBmp.h" 
#include "CStaticBmpDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCStaticBmpDlg dialog 
 
CCStaticBmpDlg::CCStaticBmpDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CCStaticBmpDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CCStaticBmpDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CCStaticBmpDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CCStaticBmpDlg) 
	DDX_Control(pDX, IDC_DELAY_TIME, m_DelayTime); 
	DDX_Control(pDX, IDC_STRETCH, m_bStretch); 
	DDX_Control(pDX, IDC_REPORT, m_Report); 
	DDX_Control(pDX, IDC_HAVE_FORM, m_bHaveForm); 
	DDX_Control(pDX, IDC_BmpNo, m_BmpNo); 
	DDX_Control(pDX, IDC_CYC, m_bCyc); 
	DDX_Control(pDX, IDC_AUTO_DISPLAY, m_bAutoDisplay); 
	DDX_Control(pDX, IDC_STATIC1, m_Bmp); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CCStaticBmpDlg, CDialog) 
	//{{AFX_MSG_MAP(CCStaticBmpDlg) 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_SETCOLOR, OnSetcolor) 
	ON_BN_CLICKED(IDC_HAVE_FORM, OnHaveForm) 
	ON_BN_CLICKED(IDC_AUTO_DISPLAY, OnAutoDisplay) 
	ON_BN_CLICKED(IDC_CYC, OnCyc) 
	ON_BN_CLICKED(IDC_SET_BMP_NO, OnSetBmpNo) 
	ON_BN_CLICKED(IDC_STRETCH, OnStretch) 
	ON_BN_CLICKED(IDC_SET_DELAY_TIME, OnSetDelayTime) 
	//}}AFX_MSG_MAP 
	ON_MESSAGE(WM_STATICBMP_PRECHANGE, OnStaticBmpPreChange) 
 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCStaticBmpDlg message handlers 
 
BOOL CCStaticBmpDlg::OnInitDialog() 
{ 
	CDialog::OnInitDialog(); 
 
	// Set the icon for this dialog.  The framework does this automatically 
	//  when the application's main window is not a dialog 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	 
	// TODO: Add extra initialization here 
	this->m_bHaveForm.SetCheck(this->m_Bmp.IsDrawForm()); 
	this->m_bAutoDisplay.SetCheck( this->m_Bmp.GetAutoDisplay() ); 
	this->m_bCyc.SetCheck( this->m_Bmp.IsCyc() ); 
	this->m_bStretch.SetCheck( this->m_Bmp.GetStretchMode() ); 
 
	CUIntArray bmpId; 
	bmpId.Add(IDB_BITMAP1); 
	bmpId.Add(IDB_BITMAP2); 
	bmpId.Add(IDB_BITMAP3); 
	bmpId.Add(IDB_BITMAP4); 
	this->m_Bmp.SetBitmap(bmpId); 
 
	CString str; 
	str.Format("%d", this->m_Bmp.GetDelayTime()); 
	this->m_DelayTime.SetWindowText(str); 
 
	str.Format("%d/%d", this->m_Bmp.GetNowBmp(), this->m_Bmp.GetBmpAmount()); 
	this->m_Report.SetWindowText(str); 
 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
// If you add a minimize button to your dialog, you will need the code below 
//  to draw the icon.  For MFC applications using the document/view model, 
//  this is automatically done for you by the framework. 
 
void CCStaticBmpDlg::OnPaint()  
{ 
	if (IsIconic()) 
	{ 
		CPaintDC dc(this); // device context for painting 
 
		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); 
 
		// Center icon in client rectangle 
		int cxIcon = GetSystemMetrics(SM_CXICON); 
		int cyIcon = GetSystemMetrics(SM_CYICON); 
		CRect rect; 
		GetClientRect(&rect); 
		int x = (rect.Width() - cxIcon + 1) / 2; 
		int y = (rect.Height() - cyIcon + 1) / 2; 
 
		// Draw the icon 
		dc.DrawIcon(x, y, m_hIcon); 
	} 
	else 
	{ 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CCStaticBmpDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CCStaticBmpDlg::OnSetcolor()  
{ 
	CColorDialog color(this->m_Bmp.GetFormColor()); 
	color.DoModal(); 
	this->m_Bmp.SetFormColor(color.GetColor()); 
} 
 
void CCStaticBmpDlg::OnStaticBmpPreChange(WPARAM wParam, LPARAM lParam) 
{ 
	CString str; 
	str.Format("%d/%d", wParam, lParam); 
	this->m_Report.SetWindowText(str); 
} 
 
void CCStaticBmpDlg::OnHaveForm()  
{ 
	this->m_Bmp.SetDrawForm(this->m_bHaveForm.GetCheck()); 
} 
 
void CCStaticBmpDlg::OnAutoDisplay()  
{ 
	this->m_Bmp.SetAutoDisplay(this->m_bAutoDisplay.GetCheck()); 
} 
 
void CCStaticBmpDlg::OnCyc()  
{ 
	this->m_Bmp.SetCyc( this->m_bCyc.GetCheck() );	 
} 
 
void CCStaticBmpDlg::OnSetBmpNo()  
{ 
	CString str; 
	this->m_BmpNo.GetWindowText(str); 
	this->m_Bmp.SetNowBmp(::atoi(str), TRUE); 
} 
 
void CCStaticBmpDlg::OnStretch()  
{ 
	this->m_Bmp.SetStretchMode(this->m_bStretch.GetCheck());	 
} 
 
void CCStaticBmpDlg::OnSetDelayTime()  
{ 
	CString str; 
	this->m_DelayTime.GetWindowText(str);	 
	this->m_Bmp.SetDelayTime(::atoi(str)); 
}