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

📄 rwaccessdlg.cpp

📁 R/W with DB [代码性质] VC完整应用程序代码 [代码作者] 徐景周
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//////////////////////////////////////////////////////////////////////////////
//类名:CRWAccessDlg
//功能:直接通过DAO读、写Access文件示例实现
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.9.26
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "RWAccess.h"
#include "RWAccessDlg.h"

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

CDaoDatabase db;				//数据库
CDaoRecordset RecSet(&db);		//记录集
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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

	//绘制荣誉显示框中的闪电效果
	static void DrawCreditsBackground(CDC *pDC, RECT rect, BOOL bAnimate, DWORD lParam);

	void SizeWindow(int ReduceHeight, bool bExtend);    //伸展或收缩对话框    
	
	//"关于"对话框中的荣誉显示
	int m_nReducedHeight;								//收缩状态下的窗口高度 
	
	bool m_bVertical;									//是否显示荣誉标志

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CXPButton	m_More;									//XP风格按钮
	CHyperLink	m_Mail;									//超链接形式显示EMAIL
	CXPButton	m_OK;									//XP风格按钮
	CPictureEx	m_Flag;									//GIF动态图像显示
	//}}AFX_DATA

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

// Implementation
protected:
	CCreditsCtrl m_wndCredits;							//荣誉显示

	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	afx_msg void OnMore();
	//}}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)
	DDX_Control(pDX, ID_MORE, m_More);
	DDX_Control(pDX, IDC_STATIC_MAIL, m_Mail);
	DDX_Control(pDX, IDOK, m_OK);
	DDX_Control(pDX, IDC_FLAG, m_Flag);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	ON_BN_CLICKED(ID_MORE, OnMore)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

//////////////////////////////////////////////////////////////////////////////
//名称:OnInitDialog
//功能:初始化"关于"对话框
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.9.26
/////////////////////////////////////////////////////////////////////////////
BOOL CAboutDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	//对话框居中显示
	CRect dlgRect; 
	GetWindowRect(dlgRect);  
	CRect desktopRect; 
	GetDesktopWindow()->GetWindowRect(desktopRect); 

	MoveWindow( 
		(desktopRect.Width() - dlgRect.Width()) / 2, 
		(desktopRect.Height() - dlgRect.Height()) / 2, 
		0, 
		0 ); 

	//"关于"对话框中对话框可收缩效果
	CRect Rect1,Rect2; 												//对话框收缩时大小		
	
	GetDlgItem(IDC_DYCREDITS)->GetWindowRect(Rect1); 
	GetDlgItem(IDC_COPYRIGHT)->GetWindowRect(Rect2); 
	m_nReducedHeight = Rect1.Height()+(Rect1.top -Rect2.bottom)/2; //收缩后窗体高度
	dlgRect.bottom -= (Rect1.Height()+(Rect1.top -Rect2.bottom)/2); 
	MoveWindow(&dlgRect);											//如果要显示对话框起始动态效果的话,不能使用该句

	m_bVertical=false;			

	//加入EMAIL的超连接
    m_Mail.SetURL(_T("mailto:jingzhou_xu@163.net"));
	m_Mail.SetUnderline(FALSE);	

	//显示动态GIF图像logo
	if(m_Flag.Load(MAKEINTRESOURCE(IDR_FLAG),_T("GIF")))
	{
		m_Flag.SetBkColor(RGB(160,180,220));
		m_Flag.Draw();	
	}

	//显示荣誉效果框
	srand((unsigned)time(NULL));

	// 内容
	CString s;
	s = "<font color='255,255,255' face='宋体' size='12' align='center'><br><p>";
	s += "<font color='200,250,100' size='18' face='宋体' style='ui'>直接通过DAO读、写Access文件示例</font><br><br><p>";
	s += "<font color='200,250,100' size='14' face='宋体'>作者:徐景周</font><br><br><p>";
	s += "<font color='200,250,100' size='14' face='宋体'>未来工作室出品</font><br><p>";

	//格式化并加入字符串
	m_wndCredits.FormatDataString(s);
	
	// 绘制闪电效果
	m_wndCredits.m_pBackgroundPaint = CAboutDlg::DrawCreditsBackground;
	m_wndCredits.m_dwBackgroundPaintLParam = TRUE;

	// 默认背景置黑色
	m_wndCredits.m_crInternalTransparentColor = RGB(255,255,255);

	//滚动速度
	m_wndCredits.m_nTimerSpeed = 40;

	//用户拖拉滚动
	m_wndCredits.m_bCanScroll = TRUE;
	
	// 创建荣誉框
	m_wndCredits.Create(WS_EX_CLIENTEDGE,WS_VISIBLE|WS_CHILD,IDC_DYCREDITS,this,0,0,0);

	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

// ---------------------------------------------------------
//	名称: OnMore
//	功能: 是否荣誉显示
//	变量: 无
//	返回: 无
//	编写: 徐景周,2002.4.8
// ---------------------------------------------------------
void CAboutDlg::OnMore() 
{
	m_bVertical = !m_bVertical; 
	
	if(m_bVertical == FALSE)	//不显示
	{ 
		SetDlgItemText(ID_MORE,_T("更多>>"));

		SizeWindow(m_nReducedHeight,true);
	} 
	else						//显示
	{ 
		SetDlgItemText(ID_MORE,_T("<<隐藏"));

		SizeWindow(m_nReducedHeight,false);
	} 
	
	UpdateWindow(); 
}

// ---------------------------------------------------------
//	名称: SizeWindow
//	功能: 伸展或收缩对话框    
//	变量: ReduceHeight-收缩高度,bExtend-是否伸展
//	返回: 无
//	编写: 徐景周,2002.4.8
// ---------------------------------------------------------	
void CAboutDlg::SizeWindow(int ReduceHeight, bool bExtend)
{
	CRect rc;
	GetWindowRect(&rc);
	if(bExtend)
	{
		for (int i= 0; i < ReduceHeight; i++)
		{
			rc.bottom--;
			MoveWindow(&rc);
		}
	}
	else
	{
		for (int i= 0; i < ReduceHeight; i++)
		{
			rc.bottom++;
			MoveWindow(&rc);
		}
	}
}

// ---------------------------------------------------------
//	名称: DrawCreditsBackground
//	功能: 绘制荣誉框中闪电效果   
//	变量: pDC -- 环境指针,rect -- 范围,bAnimate -- 动画效果,lParam -- 消息参数
//	返回: 无
//	编写: 徐景周,2002.4.8
// ---------------------------------------------------------	
void CAboutDlg::DrawCreditsBackground(CDC *pDC, RECT rect, BOOL bAnimate, DWORD lParam)
{
	static int on1,on2,oon1,oon2;
	pDC->FillSolidRect(&rect,0x00000000);
	
	if(bAnimate || (!lParam)) // return now if we are not supposed to do the animation
		return;

	int n1,n2;
	n1 = rand()*200/RAND_MAX-100;
	n2 = rand()*200/RAND_MAX-100;

	// 2/10 chance of (prehaps) making some wild stuff on one of the curves
	if(rand() < RAND_MAX/10)
		n1 = rand()*400/RAND_MAX-200;
	else if(rand() < RAND_MAX/10)
		n2 = rand()*400/RAND_MAX-200;

	POINT points1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+n1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n1,
		0,rect.bottom
	};
	POINT points2[4] = {
		0,0,
		(rect.right-rect.left)/2-n2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-n2,
		rect.right,rect.bottom
	};
	POINT opoints1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+on1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on1,
		0,rect.bottom
	};
	POINT opoints2[4] = {
		0,0,
		(rect.right-rect.left)/2-on2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-on2,
		rect.right,rect.bottom
	};
	POINT oopoints1[4] = {
		rect.right,0,
		(rect.right-rect.left)/2+oon1,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon1,
		0,rect.bottom
	};
	POINT oopoints2[4] = {
		0,0,
		(rect.right-rect.left)/2-oon2,(rect.bottom-rect.top)/2,
		(rect.right-rect.left)/2,(rect.bottom-rect.top)/2-oon2,
		rect.right,rect.bottom
	};

	CPen wpen(PS_SOLID,1,RGB(150,220,255));

⌨️ 快捷键说明

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