📄 qrysoftdlg.cpp
字号:
// QrySoftDlg.cpp : implementation file
//
#include "stdafx.h"
#include "QrySoft.h"
#include "QrySoftDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CString connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\QrySoft\\qry.mdb";
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CQrySoftDlg dialog
CQrySoftDlg::CQrySoftDlg(CWnd* pParent /*=NULL*/)
: CDialog(CQrySoftDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CQrySoftDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
myBr.CreateSolidBrush(RGB(125,125,125));
}
void CQrySoftDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CQrySoftDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CQrySoftDlg, CDialog)
//{{AFX_MSG_MAP(CQrySoftDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CTLCOLOR()
ON_LBN_DBLCLK(IDC_LIST1, OnDblclkList1)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_BN_CLICKED(IDC_QRY, OnQry)
ON_WM_DRAWITEM()
ON_BN_CLICKED(IDC_CHA1, OnCha1)
ON_BN_CLICKED(IDC_CHA2, OnCha2)
ON_BN_CLICKED(IDC_CHA3, OnCha3)
ON_BN_CLICKED(IDC_CHA4, OnCha4)
ON_BN_CLICKED(IDC_CHA5, OnCha5)
ON_BN_CLICKED(IDC_CHA6, OnCha6)
ON_BN_CLICKED(IDC_CHA7, OnCha7)
ON_BN_CLICKED(IDC_CHA8, OnCha8)
ON_BN_CLICKED(IDC_CHA9, OnCha9)
ON_BN_CLICKED(IDC_CHA11, OnCha11)
ON_BN_CLICKED(IDC_CHA12, OnCha12)
ON_BN_CLICKED(IDC_CHA13, OnCha13)
ON_BN_CLICKED(IDC_CHA14, OnCha14)
ON_BN_CLICKED(IDC_CHA15, OnCha15)
ON_BN_CLICKED(IDC_CHA16, OnCha16)
ON_BN_CLICKED(IDC_CHA17, OnCha17)
ON_BN_CLICKED(IDC_CHA18, OnCha18)
ON_BN_CLICKED(IDC_CHA19, OnCha19)
ON_BN_CLICKED(IDC_CHA20, OnCha20)
ON_BN_CLICKED(IDC_CHA21, OnCha21)
ON_BN_CLICKED(IDC_CHA22, OnCha22)
ON_BN_CLICKED(IDC_CHA23, OnCha23)
ON_BN_CLICKED(IDC_CHA24, OnCha24)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CQrySoftDlg message handlers
BOOL CQrySoftDlg::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
// TODO: Add extra initialization here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString p_str = "";
p_str = "select name from qry";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
// hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
CString ini;
ini = " 欢迎使用C语言函数查询软件 作者: 广外大04软件1班 张东城";
((CEdit *)GetDlgItem(IDC_EDIT2))->SetWindowText(ini);
return TRUE; // return TRUE unless you set the focus to a control
}
void CQrySoftDlg::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 CQrySoftDlg::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 CQrySoftDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CQrySoftDlg::OnOK()
{
// TODO: Add extra validation here
}
HBRUSH CQrySoftDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
// if(pWnd->GetDlgCtrlID()==IDC_EDIT1)
// TODO: Return a different brush if the default is not desired
// return myBr;
HBRUSH br = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID() == IDC_EDIT1 || pWnd->GetDlgCtrlID() == IDC_EDIT2 ||
pWnd->GetDlgCtrlID() == IDC_EDIT3 || pWnd->GetDlgCtrlID() == IDC_EDIT4 ||
pWnd->GetDlgCtrlID() == IDC_EDIT5 || pWnd->GetDlgCtrlID() ==IDC_LIST1)
{
// static HBRUSH hbrEdit = ::CreateSolidBrush(RGB(67, 110, 238));
static HBRUSH hbrEdit = ::CreateSolidBrush(RGB(30, 144, 255));
CFont ft;
pDC->SetBkColor(RGB(30, 144, 255));
pDC->SetTextColor(RGB(255, 255, 255));
return hbrEdit;
}
return br;
}
void CQrySoftDlg::OnDblclkList1()
{
// TODO: Add your control notification handler code here
CString p_str = "";
CString p = "";
((CListBox*)GetDlgItem(IDC_LIST1))->GetText(((CListBox*)GetDlgItem(IDC_LIST1))->GetCurSel(), p);
p_str = "select * from qry where name like '";
p_str += p;
p_str += "'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
((CEdit*)GetDlgItem(IDC_EDIT3))->SetWindowText((_bstr_t)pRst->GetCollect("name"));
((CEdit*)GetDlgItem(IDC_EDIT4))->SetWindowText((_bstr_t)pRst->GetCollect("function"));
((CEdit*)GetDlgItem(IDC_EDIT5))->SetWindowText((_bstr_t)pRst->GetCollect("usage"));
((CEdit*)GetDlgItem(IDC_EDIT2))->SetWindowText((_bstr_t)pRst->GetCollect("example"));
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString q_str = "";
CString p_str = "";
((CEdit*)GetDlgItem(IDC_EDIT1))->GetWindowText(q_str);//把IDC_EDIT1输入字符串放入q_str;
p_str = "select name from qry where name like '";
p_str += q_str;
p_str += "%'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnQry()
{
// TODO: Add your control notification handler code here
CString p_str = "";
CString p = "";
((CEdit*)GetDlgItem(IDC_EDIT1))->GetWindowText(p);
p_str = "select * from qry where name like '";
p_str += p;
p_str += "'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
if(!pRst->rsEOF)
{
((CEdit*)GetDlgItem(IDC_EDIT3))->SetWindowText((_bstr_t)pRst->GetCollect("name"));
((CEdit*)GetDlgItem(IDC_EDIT4))->SetWindowText((_bstr_t)pRst->GetCollect("function"));
((CEdit*)GetDlgItem(IDC_EDIT5))->SetWindowText((_bstr_t)pRst->GetCollect("usage"));
((CEdit*)GetDlgItem(IDC_EDIT2))->SetWindowText((_bstr_t)pRst->GetCollect("example"));
}
else
{
((CEdit *)GetDlgItem(IDC_EDIT3))->SetWindowText("");
((CEdit *)GetDlgItem(IDC_EDIT4))->SetWindowText("");
((CEdit *)GetDlgItem(IDC_EDIT5))->SetWindowText("");
((CEdit *)GetDlgItem(IDC_EDIT2))->SetWindowText(" 提示: 所查询的函数找不到!");
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your message handler code here and/or call default
CDC ButtonDC;
CBitmap bitmapTrans;
BITMAP bmp;
CDC mem;
CRect rc;
ButtonDC.Attach(lpDrawItemStruct->hDC);
mem.CreateCompatibleDC(&ButtonDC);
rc = lpDrawItemStruct->rcItem;
if(lpDrawItemStruct->CtlID == IDC_CHA1)
bitmapTrans.LoadBitmap(IDB_BITMAP1);
if(lpDrawItemStruct->CtlID == IDC_CHA2)
bitmapTrans.LoadBitmap(IDB_BITMAP2);
if(lpDrawItemStruct->CtlID == IDC_CHA3)
bitmapTrans.LoadBitmap(IDB_BITMAP3);
if(lpDrawItemStruct->CtlID == IDC_CHA4)
bitmapTrans.LoadBitmap(IDB_BITMAP4);
if(lpDrawItemStruct->CtlID == IDC_CHA5)
bitmapTrans.LoadBitmap(IDB_BITMAP5);
if(lpDrawItemStruct->CtlID == IDC_CHA6)
bitmapTrans.LoadBitmap(IDB_BITMAP6);
if(lpDrawItemStruct->CtlID == IDC_CHA7)
bitmapTrans.LoadBitmap(IDB_BITMAP7);
if(lpDrawItemStruct->CtlID == IDC_CHA8)
bitmapTrans.LoadBitmap(IDB_BITMAP8);
if(lpDrawItemStruct->CtlID == IDC_CHA9)
bitmapTrans.LoadBitmap(IDB_BITMAP9);
// if(lpDrawItemStruct->CtlID == IDC_CHA10)
// bitmapTrans.LoadBitmap(IDB_BITMAP10);
if(lpDrawItemStruct->CtlID == IDC_CHA11)
bitmapTrans.LoadBitmap(IDB_BITMAP11);
if(lpDrawItemStruct->CtlID == IDC_CHA12)
bitmapTrans.LoadBitmap(IDB_BITMAP12);
if(lpDrawItemStruct->CtlID == IDC_CHA13)
bitmapTrans.LoadBitmap(IDB_BITMAP13);
if(lpDrawItemStruct->CtlID == IDC_CHA14)
bitmapTrans.LoadBitmap(IDB_BITMAP14);
if(lpDrawItemStruct->CtlID == IDC_CHA15)
bitmapTrans.LoadBitmap(IDB_BITMAP15);
if(lpDrawItemStruct->CtlID == IDC_CHA16)
bitmapTrans.LoadBitmap(IDB_BITMAP16);
if(lpDrawItemStruct->CtlID == IDC_CHA17)
bitmapTrans.LoadBitmap(IDB_BITMAP17);
if(lpDrawItemStruct->CtlID == IDC_CHA18)
bitmapTrans.LoadBitmap(IDB_BITMAP18);
if(lpDrawItemStruct->CtlID == IDC_CHA19)
bitmapTrans.LoadBitmap(IDB_BITMAP19);
if(lpDrawItemStruct->CtlID == IDC_CHA20)
bitmapTrans.LoadBitmap(IDB_BITMAP20);
if(lpDrawItemStruct->CtlID == IDC_CHA21)
bitmapTrans.LoadBitmap(IDB_BITMAP21);
if(lpDrawItemStruct->CtlID == IDC_CHA22)
bitmapTrans.LoadBitmap(IDB_BITMAP22);
if(lpDrawItemStruct->CtlID == IDC_CHA23)
bitmapTrans.LoadBitmap(IDB_BITMAP23);
bitmapTrans.GetBitmap(&bmp);
CBitmap * old = mem.SelectObject(&bitmapTrans);
ButtonDC.StretchBlt(rc.left, rc.top, rc.right, rc.bottom, &mem, 0, 0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);
mem.SelectObject(old);
bitmapTrans.DeleteObject();
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
void CQrySoftDlg::OnCha1()
{
// TODO: Add your control notification handler code here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString p_str = "";
p_str = "select name from qry where name like 'a%'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnCha2()
{
// TODO: Add your control notification handler code here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString p_str = "";
p_str = "select name from qry where name like 'b%'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnCha3()
{
// TODO: Add your control notification handler code here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString p_str = "";
p_str = "select name from qry where name like 'c%'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
}
void CQrySoftDlg::OnCha4()
{
// TODO: Add your control notification handler code here
if(((CListBox*)GetDlgItem(IDC_LIST1))->GetCount() != 0)
((CListBox*)GetDlgItem(IDC_LIST1))->ResetContent();
CString p_str = "";
p_str = "select name from qry where name like 'd%'";
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString = (_bstr_t)connStr;
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute((_bstr_t)p_str, NULL, adCmdText);
while(!pRst->rsEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("name"));
pRst->MoveNext();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -