⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 showviewdlg.cpp

📁 本次程序主要由两个工程组成
💻 CPP
字号:
/*

此文件名为 "ShowViewDlg.cpp"。

Copyright:04本3班 丁伟成,陈妙娜,肖芹珍,赖删珊。

此文件功能:引入BitDll.dll动态链接库,包括ShoeBitmap函数和图片资源。
            处理对话框界面按钮的事件,包括“自动播放/暂停”、“选择显示图片”选择框、
            “上一张”、“下一张”和“退出”。

作者: 陈妙娜,赖删珊,肖芹珍。

完成日期:2007年3月12日

当前的版本号:ShowView.01,该程序暂时为最新版本。

*/
// ShowViewDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ShowView.h"
#include "ShowViewDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowViewDlg dialog

CShowViewDlg::CShowViewDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CShowViewDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShowViewDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	//添加代码,初始化变量
	hdll=LoadLibrary("BitDll.dll");//导入动态链接库

	index=0;
	timerFlag=false;
}

void CShowViewDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowViewDlg)
	DDX_Control(pDX, IDC_PhotoIndex, m_photoIndex);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CShowViewDlg, CDialog)
	//{{AFX_MSG_MAP(CShowViewDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(ID_AutoShow, OnAutoShow)
	ON_BN_CLICKED(ID_Forward, OnForward)
	ON_CBN_SELCHANGE(IDC_PhotoIndex, OnSelchangePhotoIndex)
	ON_BN_CLICKED(ID_Backward, OnBackward)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowViewDlg message handlers

BOOL CShowViewDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// 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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CShowViewDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// 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 CShowViewDlg::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
	{
		//添加代码,初始化对话框
		m_photoIndex.SetCurSel(0);

		PaintBit();

		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CShowViewDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

//“自动播放/暂停”按钮
void CShowViewDlg::OnAutoShow() 
{
	// TODO: Add your control notification handler code here
	if(timerFlag==false)
	{
		timerFlag=true;
		SetTimer(0,1000,NULL);
	}
	else
		KillTimer(0);	
}

//“选择图片”选择框
void CShowViewDlg::OnSelchangePhotoIndex() 
{
	// TODO: Add your control notification handler code here
	index=m_photoIndex.GetCurSel();	
	PaintBit();
}

//“上一张”按钮
void CShowViewDlg::OnForward() 
{
	// TODO: Add your control notification handler code here
	index--;
	PaintBit();
}

//“下一张”按钮
void CShowViewDlg::OnBackward() 
{
	// TODO: Add your control notification handler code here
	index++;
	PaintBit();
}

//“退出”按钮
void CShowViewDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

//调用Dll中的ShowBitmap函数显示图片
void CShowViewDlg::PaintBit()
{
	CDC *pDC=GetDC();
	hdc=pDC->GetSafeHdc();

	if(index<=0)
		index+=12;
	hbit=LoadBitmap(hdll,MAKEINTRESOURCE(index%12+1));
	typedef void (*BITPROC)(HDC hdc,int xStart,int yStart,HBITMAP hBitmap);
	BITPROC bit = (BITPROC)GetProcAddress(hdll,"ShowBitmap");
	bit(hdc,130,45,hbit);
}

//系统定时器时函数
void CShowViewDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	
	CDialog::OnTimer(nIDEvent);

	OnBackward();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -