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

📄 newdialog.h

📁 Visual C++数据库编程源代码 《Visual C++程序员成长攻略》一书的附带源代码
💻 H
字号:
// NewDialog.h : Declaration of the CNewDialog

#ifndef __NEWDIALOG_H_
#define __NEWDIALOG_H_

#include "resource.h"       // main symbols
#include <atlhost.h>
//"加入自定义代码"
#include "Information.h"

/////////////////////////////////////////////////////////////////////////////
// CNewDialog
class CNewDialog : 
	public CAxDialogImpl<CNewDialog>
{
public:
	//"加入自定义代码"
	CInformation* m_pSet;
	//判断记录是否添加
	bool m_pAddRecord;
	//加入自定义函数
	void AddRecord();                      //添加记录
	void MoveRecord(int location);         //移动记录
	void UpdateData(bool m_pUpdateSet);    //更新记录

	CNewDialog()
	{
		//"加入自定义代码"
		//初始化m_pSet并分配
		m_pSet = new CInformation();
		m_pAddRecord  = false;
		DoModal();
	}

	~CNewDialog()
	{
	}

	enum { IDD = IDD_NEWDIALOG };

BEGIN_MSG_MAP(CNewDialog)
	MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
	COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
	COMMAND_HANDLER(IDC_CHANGE, BN_CLICKED, OnClickedChange)
	COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnCancel)
	//"加入自定义代码",实现菜单及其响应函数的绑定
	COMMAND_ID_HANDLER(ID_OPEN, OnOpen)
	COMMAND_ID_HANDLER(ID_ADD_RECORD, OnAddRecord)
	COMMAND_ID_HANDLER(ID_DELETE_RECORD, OnDeleteRecord)
	COMMAND_ID_HANDLER(ID_MOVE_RECORD, OnMoveRecord)
	COMMAND_ID_HANDLER(ID_ABOUT, OnAbout)
END_MSG_MAP()
// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{
		//"加入自定义代码"
		//装载自定义菜单
		HMENU hmenu = LoadMenu (_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME));
        SetMenu(hmenu);
		//设定应用程序标题
        SetWindowText(_T("My First ATL Window"));
		//设定编辑控件文本长度
		SendMessage(GetDlgItem(IDC_ID), EM_LIMITTEXT, (WPARAM)5, 0);
		SendMessage(GetDlgItem(IDC_NAME), EM_LIMITTEXT, (WPARAM)45, 0);
		SendMessage(GetDlgItem(IDC_SCORE), EM_LIMITTEXT, (WPARAM)10, 0);
		//打开数据库相关对象
		HRESULT hresult = m_pSet->Open();
		if (FAILED(hresult))
		{
			MessageBox("Open Rowset failed!", "Message", 0);
			return 0;
		}
		//移到首记录
		m_pSet->MoveFirst();
		UpdateData(false);	//更新窗口
		return 1;  // Let the system set the focus
	}
	LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		EndDialog(wID);
		return 0;
	}
	LRESULT OnClickedChange(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		// TODO : Add Code for control notification handler.
		//"加入自定义代码",更新显示
		UpdateData(false);		return 0;
	}

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//"加入自定义代码",实现各个函数的功能
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	LRESULT OnOpen(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& 	bHandled)
	{
		//"加入自定义代码"
		MessageBox("文件已经打开!", "提示信息", 0);
		return 0;
	}
	LRESULT OnAddRecord(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		//"加入自定义代码"
		AddRecord();
		return 0;
	}
	LRESULT OnDeleteRecord(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		//"加入自定义代码"
		HRESULT hresult;
		//删除记录
		hresult = m_pSet->Delete();
		if (FAILED(hresult))
		{
			MessageBox("Delete Record failed!", "Message", 0);
			return 0;
		}
		m_pSet->MoveFirst();
		UpdateData(false);
		return 0;
	}
	LRESULT OnMoveRecord(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		//"加入自定义代码"
		//定义字符指针
		char *str = new char[5];
		int location;
		//获得IDC_LOCATION控件中的字符文本
		GetDlgItemText(IDC_LOCATION, str, 5);
		//弹出消息框显示编辑控件IDC_LOCATION中的文本内容
	//	MessageBox(str);
		//实现从字符型到整型的转换
		location = atoi(str);
		//移动记录
		MoveRecord(location);
		UpdateData(false);
		return 0;
	}
	LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
	{
		//"加入自定义代码"
		MessageBox("ATLOLEDB Version 1.0");
		return 0;
	}
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

};

#endif //__NEWDIALOG_H_

⌨️ 快捷键说明

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