📄 080426dbdialogdlg.cpp
字号:
// 080426dbdialogDlg.cpp : implementation file
//
#include "stdafx.h"
#include "080426dbdialog.h"
#include "080426dbdialogDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMy080426dbdialogDlg dialog
CMy080426dbdialogDlg::CMy080426dbdialogDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy080426dbdialogDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy080426dbdialogDlg)
m_stuNO = _T("");
m_chinese = _T("");
m_math = _T("");
m_english = _T("");
m_timer = _T("");
m_name = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
//m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
nUpdate=0;
m_BOOLTag=false;
}
void CMy080426dbdialogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy080426dbdialogDlg)
DDX_Control(pDX, IDC_COMBO1, m_comboNO);
DDX_Control(pDX, IDC_EDIT_NAME, m_ColEdit);
DDX_Control(pDX, IDC_LIST1, m_ListCtrl);
DDX_CBString(pDX, IDC_COMBO1, m_stuNO);
DDV_MaxChars(pDX, m_stuNO, 20);
DDX_Text(pDX, IDC_EDIT2, m_chinese);
DDX_Text(pDX, IDC_EDIT3, m_math);
DDX_Text(pDX, IDC_EDIT4, m_english);
DDX_Text(pDX, IDC_EDIT5, m_timer);
DDX_Text(pDX, IDC_EDIT_NAME, m_name);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy080426dbdialogDlg, CDialog)
//{{AFX_MSG_MAP(CMy080426dbdialogDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_ADD, OnAdd)
ON_BN_CLICKED(IDC_DELETE, OnDelete)
ON_BN_CLICKED(IDC_BTOK, OnBtok)
ON_WM_TIMER()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_ADDMAP, OnAddmap)
ON_BN_CLICKED(IDC_BUTVIEW, OnButview)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy080426dbdialogDlg message handlers
BOOL CMy080426dbdialogDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CoInitialize(NULL);
// 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_Colorsta=new CColorStatic;
CRect rect(0,0,50,30);
int nID=110;
//m_Colorsta->Create("kddf",WS_CHILD|WS_VISIBLE,rect,this,nID);
m_ColEdit.m_Bitmap.LoadBitmap(IDB_BITMAP3);
//m_bitmap.LoadBitmap(IDB_BITMAP1);
UpdateData(false);
m_Colorsta->SetTextColor(RGB(232,100,27));
//m_Colorsta->SubclassDlgItem(nID,this);//这一句和下一句有着很不一样子的区别;
//m_ColorStatic.SubclassDlgItem(IDC_STA_STU,this);
m_ColorStatic.SetTextColor(RGB(232,100,27));
// TODO: Add extra initialization here
CString combo;
for(int i=1;i<51;i++)
{
combo.Format("2015451%02d",i);
m_comboNO.InsertString(i-1,combo);
}
m_comboNO.SetCurSel(0);
CString sql;
try
{
m_pConnection.CreateInstance(__uuidof(Connection));
m_pCommand.CreateInstance(__uuidof(Command));
sql.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=student.mdb");
_bstr_t sql_=sql;
m_pConnection->Open(sql_,"","",-1);
}
catch(_com_error& e)
{
AfxMessageBox(e.ErrorMessage());
this->EndDialog(0);
}
CString header[7]={"学号","姓名","语文","数学","英语","平均分","时间"};
for(i=0;i<7;i++)
{
m_ListCtrl.InsertColumn(i,header[i],LVCFMT_CENTER,70);
}
m_ListCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_LIST|LVS_EX_HEADERDRAGDROP);
_bstr_t str1("select * from students");
i=0;
_variant_t temp;
/*10.使用command
利用Command对象来执行SQL命令
_CommandPtr m_pCommand;
m_pCommand.CreateInstance("ADODB.Command");
_variant_t vNULL;
vNULL.vt = VT_ERROR;
vNULL.scode = DISP_E_PARAMNOTFOUND;///定义为无参数
m_pCommand->ActiveConnection = m_pConnection;///非常关键的一句,将建立的连接赋值给它
m_pCommand->CommandText = "SELECT * FROM users";///命令字串
m_pRecordset = m_pCommand->Execute(&vNULL,&vNULL,adCmdText);///执行命令,取得记录集*/
//CString strchange;
_variant_t vNULL;
vNULL.vt=VT_ERROR;
vNULL.scode=DISP_E_PARAMNOTFOUND;
m_pCommand->ActiveConnection=m_pConnection;
m_pCommand->CommandText="select * from students";
try{
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset=m_pCommand->Execute(&vNULL,&vNULL,adCmdText);
//m_pRecordset = m_pConnection->Execute(str1,NULL,adCmdText);
m_pRecordset->MoveFirst();
CString strtemp;
int aaaa;
while(!m_pRecordset->adoEOF)//在一些常用的功能上,MFC一定会有很简单的方法的~
{
temp = m_pRecordset->GetCollect("number");
if(temp.vt != VT_NULL)
m_ListCtrl.InsertItem(i,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("name");
if(temp.vt != VT_NULL)
m_ListCtrl.SetItemText(i,1,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("chinexe");
if(temp.vt != VT_NULL)
temp.ChangeType(VT_BSTR);//_variant_t支持的内部基本数据类型之间进行各种转换运算;
strtemp=temp.bstrVal;
m_ListCtrl.SetItemText(i,2,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("math");
if(temp.vt != VT_NULL)
m_ListCtrl.SetItemText(i,3,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("english");
if(temp.vt != VT_NULL)
m_ListCtrl.SetItemText(i,4,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("average");
if(temp.vt!=VT_NULL)
m_ListCtrl.SetItemText(i,5,(char*)(_bstr_t)temp);
temp =m_pRecordset->GetCollect("timer");
if(temp.vt!=VT_NULL)
m_ListCtrl.SetItemText(i,6,(char*)(_bstr_t)temp);
//strchange.Format("%f",temp2);
m_pRecordset->MoveNext();
}
MessageBox(strtemp);
VariantClear(&temp);
m_pRecordset->Close();
}
catch(_com_error& e)
{
AfxMessageBox(e.ErrorMessage());
}
m_ListCtrl.SetRedraw(TRUE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMy080426dbdialogDlg::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 CMy080426dbdialogDlg::OnPaint()
{ CPaintDC dc(this);
if (IsIconic())
{
// 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);
}
if (m_BOOLTag)
{
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);//创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(rect);
CBitmap *pbmpOld=dcMem.SelectObject(&m_Bitmap);
dc.BitBlt(600,50,400,355,&dcMem,0,0,SRCCOPY);
//dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,MERGECOPY);
this->OpenClipboard();
EmptyClipboard();
HANDLE sss=SetClipboardData(CF_BITMAP,m_Bitmap.GetSafeHandle());
if (NULL==sss)
{
MessageBox("asdddddf");
}
CloseClipboard();
m_bitmap.Detach();//分离图层
if( OpenClipboard())
{
//获得剪贴板数据
HBITMAP handle = (HBITMAP)GetClipboardData(CF_BITMAP);
if (NULL==handle)
{
MessageBox("asdf");
}
CBitmap * bm = CBitmap::FromHandle(handle);
CClientDC cdc(this);
CDC dcss;
dcss.CreateCompatibleDC(&cdc);
dcss.SelectObject(bm);
cdc.BitBlt(0,0,800,500,&dcss,0,0,SRCCOPY);
CloseClipboard();
}
//dc.BitBlt(0, 0,800, 500, &dcMem, 0, 0, SRCCOPY);
}
/*CDC dcMem;
dcMem.CreateCompatibleDC(&dc); //创建与对话框dc兼容的内存dc
CRect rect;
GetClientRect(&rect);
BITMAP bitMap;
m_bitmap.GetBitmap(&bitMap);
CBitmap *pbmpOld=dcMem.SelectObject(&m_bitmap); //将背景位图选入内存dc中
//dc.BitBlt(370, 100, 130, 160, &dcMem, 0, 0, SRCCOPY);
dc.StretchBlt(0,0,rect.Width(),rect.Height(),&dcMem,0,0,bitMap.bmWidth,bitMap.bmHeight,SRCCOPY);*/
CDialog::OnPaint();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMy080426dbdialogDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy080426dbdialogDlg::OnDestroy()
{
CDialog::OnDestroy();
m_pConnection->Close();
m_pConnection=NULL;
CoUninitialize();
// TODO: Add your message handler code here
}
void CMy080426dbdialogDlg::OnAdd()
{
// TODO: Add your control notification handler code here
UpdateData(true);
// _CommandPtr m_pCommand;
//m_pCommand.CreateInstance(__uuidof(Command));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -