BOOL CStuApp::InitInstance()
{
AfxEnableControlContainer();
AfxOleInit();
m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
m_pConnection->ConnectionTimeout=3;///设置超时时间为3秒
m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb;","","",adModeUnknown);//连接数据库
SetDialogBkColor(RGB(0,81,162),RGB(0,255,0));设置对话框的背景色和当前色。
..........
BOOL CStuDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
DWORD dwStyle=::GetWindowLong(m_MyList.m_hWnd,GWL_STYLE);
//设置为报表形式
SetWindowLong(m_MyList.m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT);
DWORD ExStyle =m_MyList.GetExtendedStyle();
//设置为整栏选择和网格线
m_MyList.SetExtendedStyle(ExStyle|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
m_MyList.InsertColumn(0,"学号",LVCFMT_CENTER,80,0);//插入LIST
m_MyList.InsertColumn(1,"姓名",LVCFMT_CENTER,60,0);
m_MyList.InsertColumn(2,"性别",LVCFMT_CENTER,40,0);
m_MyList.InsertColumn(3,"年龄",LVCFMT_CENTER,40,0);
m_MyList.InsertColumn(4,"系",LVCFMT_CENTER,260,0);
// TODO: Add extra initialization here
List("SELECT * FROM student");
return TRUE; // return TRUE unless you set the focus to a control
}