📄 listpage.cpp
字号:
// ListPage.cpp : implementation file
//
#include "stdafx.h"
#include "phonebook.h"
#include "ListPage.h"
#include "mdbfield.h"
#include "PhoneSheetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ListPage property page
IMPLEMENT_DYNCREATE(ListPage, CPropertyPage)
ListPage::ListPage() : CPropertyPage(ListPage::IDD)
{
//{{AFX_DATA_INIT(ListPage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
ListPage::~ListPage()
{
}
void ListPage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ListPage)
DDX_Control(pDX, IDC_LIST, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ListPage, CPropertyPage)
//{{AFX_MSG_MAP(ListPage)
ON_WM_CTLCOLOR()
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ListPage message handlers
BOOL ListPage::OnInitDialog()
{
CPropertyPage::OnInitDialog();
m_list.SetExtendedStyle(LVS_EX_GRIDLINES);
m_brush.CreateSolidBrush(RGB(0,170,170));
try
{
CString sDSN="ODBC;DRIVER=Microsoft Access Driver (*.mdb);DSN='';DBQ=telbook.mdb";
m_database = new CDatabase;
if(!m_database->Open(NULL,FALSE,FALSE,sDSN,FALSE))
{
CDialog::EndDialog(0);
return FALSE;
}
CString strSQL="select * from personlist";
m_pSet = new CRecordset(m_database);
m_pSet->Open(CRecordset::dynaset,strSQL);
m_list.SetBkColor(RGB(0xFF,0xFF,0xFF));
m_list.SetTextBkColor(RGB(0xFF,0xFF,0xFF));
for(int i=0;i<12;i++)
{
m_list.InsertColumn(i,dbFields[i].label,LVCFMT_LEFT,-1,-1);
m_list.SetColumnWidth(i,dbFields[i].len);
}
}
catch(CDBException* pEx)
{
pEx->ReportError();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
HBRUSH ListPage::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = (HBRUSH)m_brush;
if(nCtlColor==CTLCOLOR_STATIC)
{ pDC->SetBkMode(TRANSPARENT);
return hbr;
}
if(nCtlColor==CTLCOLOR_EDIT)
{
return NULL;
}
return hbr;
}
BOOL ListPage::OnSetActive()
{
m_list.DeleteAllItems();
AddDataIntoCtrl();
return CPropertyPage::OnSetActive();
}
void ListPage::AddDataIntoCtrl()
{
CWaitCursor wc;
CString temp;
char *buf;
int j=0;
if(!m_pSet->Requery()) AfxMessageBox("can not requery");
if(m_pSet->IsBOF() && m_pSet->IsEOF()) return;
m_pSet->MoveFirst();
while( !m_pSet->IsEOF() )
{
for(int i=0;i<MAX_LEN;i++)
{
m_pSet->GetFieldValue(dbFields[i].name,temp);
buf=temp.GetBuffer(temp.GetLength());
strcpy(dbFields[i].m_name,buf);
}
m_list.InsertItem(j,(LPCTSTR)dbFields[0].m_name,0);
for(i=1;i<MAX_LEN;i++)
{
m_list.SetItemText(j,i,dbFields[i].m_name);
}
j++;
m_pSet->MoveNext();
}
}
BOOL ListPage::DestroyWindow()
{
if(m_pSet!=NULL)
{
m_pSet->Close();
m_database->Close();
delete m_pSet;
delete m_database;
}
return CPropertyPage::DestroyWindow();
}
void ListPage::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CWnd *pWnd=this->GetParent();
//SetActivePage(1);
//PhoneSheetDlg *a=this->GetParentOwner();
//a->EnableWindow(TRUE);
//dlg.SetActivePage(dlg.GetPage(1));
//theApp.Get
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -