【VC开源代码栏目提醒】:网学会员,鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“adxDlg.cpp”一文,供大家参考学习!
// adxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "adx.h"
#include "adxDlg.h"
#include "AFXPRIV.H"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_; // Global Instance to force load/unload of OLE
// This handy macro allows lazy programmers to type less
#define RsITEM(rs,n) rs->Fields->Item[_variant_t((long)n)]->Value
CString CrackStrVariant(const _variant_t& var); // forward decl
/////////////////////////////////////////////////////////////////////////////
// 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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdxDlg dialog
CAdxDlg::CAdxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAdxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAdxDlg)
m_strName = _T("");
m_strID = _T("");
m_gradYr = 0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bAddNew = 0;
m_maxID = 1001;
}
void CAdxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdxDlg)
DDX_Control(pDX, IDC_BUTsupports, m_butSupports);
DDX_Control(pDX, IDC_BUTrollback, m_ctlRollback);
DDX_Control(pDX, IDC_BUTcommit, m_ctlCommit);
DDX_Control(pDX, IDC_BUTupdate, m_ctlUpdate);
DDX_Control(pDX, IDC_BUTprev, m_ctlPrev);
DDX_Control(pDX, IDC_BUTopen, m_ctlOpen);
DDX_Control(pDX, IDC_BUTnext, m_ctlNext);
DDX_Control(pDX, IDC_BUTlast, m_ctlLast);
DDX_Control(pDX, IDC_BUTfirst, m_ctlFirst);
DDX_Control(pDX, IDC_BUTdel, m_ctlDel);
DDX_Control(pDX, IDC_BUTaddNew, m_ctlAddNew);
DDX_Text(pDX, IDC_EDITname, m_strName);
DDX_Text(pDX, IDC_EDITid, m_strID);
DDX_Text(pDX, IDC_EDITgy, m_gradYr);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAdxDlg, CDialog)
//{{AFX_MSG_MAP(CAdxDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTopen, OnBUTopen)
ON_BN_CLICKED(IDC_BUTnext, OnBUTnext)
ON_BN_CLICKED(IDC_BUTprev, OnBUTprev)
ON_BN_CLICKED(IDC_BUTfirst, OnBUTfirst)
ON_BN_CLICKED(IDC_BUTlast, OnBUTlast)
ON_EN_CHANGE(IDC_EDITname, OnChangeEDITname)
ON_EN_CHANGE(IDC_EDITid, OnChangeEDITid)
ON_BN_CLICKED(IDC_BUTupdate, OnBUTupdate)
ON_BN_CLICKED(IDC_BUTaddNew, OnBUTaddNew)
ON_BN_CLICKED(IDC_BUTdel, OnBUTdel)
ON_BN_CLICKED(IDC_BUTcommit, OnBUTcommit)
ON_BN_CLICKED(IDC_BUTrollback, OnBUTrollback)
ON_BN_CLICKED(IDC_BUTsupports, OnBUTsupports)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAdxDlg message handlers
BOOL CAdxDlg::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
m_ctlAddNew.EnableWindow(0); // turn off all the buttons except open
m_ctlDel.EnableWindow(0); // since we can't move untill rs is open
m_ctlFirst.EnableWindow(0);
m_ctlLast.EnableWindow(0);
m_ctlNext.EnableWindow(0);
m_ctlPrev.EnableWindow(0);
m_ctlUpdate.EnableWindow(0);
m_ctlCommit.EnableWindow(0);
m_ctlRollback.EnableWindow(0);
m_butSupports.EnableWindow(0);
return TRUE; // return TRUE unless you set the focus to a control
}
void CAdxDlg::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 CAdxDlg::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 CAdxDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CAdxDlg::OnBUTopen()
{
try{
_ConnectionPtr Conn1;
HRESULT hr=Conn1.CreateInstance( __uuidof( Connection ) );
if (FAILED(hr)){
CString strErr; strErr.Format("hr = %x", hr);
AfxMessageBox(strErr); exit(-1);
}
_bstr_t bstrAccessConnect ( L"DRIVER={Microsoft Access Driver (*.mdb)};"
L"DBQ=adostudent.MDB;DefaultDir=;" );
_bstr_t bsEmpty = L"";
Conn1->ConnectionString = bstrAccessConnect;
try{
Conn1->Open( bsEmpty, bsEmpty, bsEmpty, -1 );
}
catch(_com_error &e){
if(e.Error() != 0x80004005)
throw e;
// If we can't open the mdb file, were probably running the program from
// explorer, not from the debugger, in which case the file is one dir up
_bstr_t bs2( L"DRIVER={Microsoft Access Driver (*.mdb)};"
L"DBQ=adost
上一篇:
adx.cpp
下一篇:
让我掉下眼泪的