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

📄 logindlg.cpp

📁 一个用ODBC访问Access的实例
💻 CPP
字号:
// LoginDlg.cpp : implementation file
//

#include "stdafx.h"
#include "vocabulory.h"
#include "LoginDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg dialog


CLoginDlg::CLoginDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLoginDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLoginDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CLoginDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLoginDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)
	//{{AFX_MSG_MAP(CLoginDlg)
	ON_BN_CLICKED(IDC_SELECT, OnSelect)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

HCURSOR CLoginDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/////////////////////////////////////////////////////////////////////////////
// CLoginDlg message handlers

void CLoginDlg::OnSelect() 
{
	// TODO: Add your control notification handler code here
	CFileDialog f(TRUE,"mdb",NULL,NULL,"MDB 文件(*.mdb)|*.mdb||",NULL);
	if(f.DoModal()==IDOK)
	{
		sPath = f.GetPathName();
		CString str = f.GetFileName();
		int len = str.GetLength();
		spath = str.Left(sPath.GetLength()-len);
		SetDlgItemText(IDC_EDIT1,sPath);
	}
}

void CLoginDlg::OnOK() 
{
	// TODO: Add extra validation here
	char* szDesc;
	int mlen;
	szDesc=new char[256];

	sprintf(szDesc,
			"DSN=%s? DESCRIPTION=TOC support source? DBQ=%s? DEFAULTDIR=%s ??",
			"Vocabulory",sPath,spath);
 
	mlen = strlen(szDesc);
    for (int i=0; i<mlen; i++)
	{
		if (szDesc[i] == '?')
		szDesc[i] = '\0';
	}

	if (FALSE == SQLConfigDataSource(NULL,ODBC_ADD_DSN,
		"Microsoft Access Driver (*.mdb)\0",(LPCSTR)szDesc))
	{
		AfxMessageBox("SQLConfigDataSource Failed");
	}			

    try
	{
		CString strConnect;
		strConnect.Format("DSN=Vocabulory;");
		if(!m_DB.OpenEx(strConnect,CDatabase::useCursorLib|CDatabase::noOdbcDialog))
		{
			AfxMessageBox("Unable to Connect to the Specified Data Source");
			return ;
		}
	}catch(CDBException *pE)
	{
        pE->ReportError();
        pE->Delete();
        return ;
    }
	CDialog::OnOK();
}

void CLoginDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	CDialog::OnCancel();
}

⌨️ 快捷键说明

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