📄 dialogsetother.cpp
字号:
// DialogSetOther.cpp : implementation file
//
#include "stdafx.h"
#include "qq.h"
#include "DialogSetOther.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDialogSetOther dialog
CDialogSetOther::CDialogSetOther(CWnd* pParent /*=NULL*/)
: CDialog(CDialogSetOther::IDD, pParent)
{
//{{AFX_DATA_INIT(CDialogSetOther)
m_Edit2 = _T("");
m_EDIT1 = _T("");
//}}AFX_DATA_INIT
}
void CDialogSetOther::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDialogSetOther)
DDX_Control(pDX, IDC_SET_OTHER_EDIT, m_setOtherEdit);
DDX_Control(pDX, IDC_SET_OTHER_INFO, m_setOtherInfo);
DDX_Control(pDX, IDC_SET_OTHER, m_setOther);
DDX_Text(pDX, IDC_SET_OTHER_EDIT, m_Edit2);
DDX_Text(pDX, IDC_SET_OTHER_INFO, m_EDIT1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDialogSetOther, CDialog)
//{{AFX_MSG_MAP(CDialogSetOther)
ON_NOTIFY(NM_CLICK, IDC_SET_OTHER, OnClickSetOther)
ON_BN_CLICKED(IDC_MODIFY, OnModify)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDialogSetOther message handlers
BOOL CDialogSetOther::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
DWORD dwStyle = m_setOther.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;
m_setOther.SetExtendedStyle(dwStyle);
m_setOther.ModifyStyle(0, LVS_REPORT);
// Setup the column headings
SetListCtrlColsNames(0);
GetDlgItem(IDC_MODIFY)->EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDialogSetOther::SetListCtrlColsNames(int nTabMode)
{//根据不同的表头设置不同的标题
// Insert some columns
int k=0;
CRect rect;
m_setOther.GetClientRect(&rect);
int nColInterval = rect.Width();//设置单位宽度
CHeaderCtrl* pHdr=m_setOther.GetHeaderCtrl();
int n=pHdr->GetItemCount();
m_setOther.InsertColumn(0,_T("名称"),LVCFMT_LEFT,nColInterval/6+40);
m_setOther.InsertColumn(1,_T("值"),LVCFMT_LEFT,nColInterval/6+40);
m_setOther.InsertColumn(2,_T("说明"),LVCFMT_LEFT,nColInterval/6+60);
if(!m_OtherInfoSet.Open())
{
AfxMessageBox("打开数据库失败!");
return;
}
m_OtherInfoSet.MoveFirst();//move to the first
do
{
//int i = 0;
CString s;
s.Format("%d",k);
m_setOther.InsertItem(k,s,0);
m_setOther.SetItemText(k,0,m_OtherInfoSet.m_name);
m_setOther.SetItemText(k,1,m_OtherInfoSet.m_content);
m_setOther.SetItemText(k,2,m_OtherInfoSet.m_description);
k++;
m_OtherInfoSet.MoveNext();
} while(!m_OtherInfoSet.IsEOF());
m_OtherInfoSet.Close();
}
void CDialogSetOther::OnClickSetOther(NMHDR* pNMHDR, LRESULT* pResult)
{
//选择了listctrl中的一个项目
// TODO: Add your control notification handler code here
m_setOtherInfo.SetWindowText("");//清空
GetDlgItem(IDC_MODIFY)->EnableWindow(TRUE);
// CRect rect;
// m_setOtherInfo.GetClientRect(&rect);
POSITION pos=m_setOther.GetFirstSelectedItemPosition();
while (pos)
{
int nSel=m_setOther.GetNextSelectedItem(pos);
CString str=_T("");
int nMode= 0;//m_cTabListMode.GetCurSel();
int i=0;
//get the CHeaderCtrl pointer
CHeaderCtrl* pHeader=(CHeaderCtrl*)m_setOther.GetHeaderCtrl();
HDITEM Hditem;
TCHAR lpBuffer[256];
Hditem.mask=HDI_TEXT;
Hditem.pszText=lpBuffer;
Hditem.cchTextMax=256;
m_setOtherInfo.SetWindowText(m_setOther.GetItemText(nSel,0));
m_setOtherEdit.SetWindowText(m_setOther.GetItemText(nSel,1));
}
*pResult = 0;
}
void CDialogSetOther::OnOK()
{
// TODO: Add extra validation here
// CDialog::OnOK();
}
void CDialogSetOther::OnModify()
{
// TODO: Add your control notification handler code here
int k=0;
UpdateData(TRUE);
if(m_EDIT1 == "")
return;
if(!m_OtherInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE))
{
AfxMessageBox("打开数据库失败!");
return;
}
m_OtherInfoSet.MoveFirst();
do
{
if(m_OtherInfoSet.m_name==m_EDIT1)
break;
m_OtherInfoSet.MoveNext();
}while(!m_OtherInfoSet.IsEOF());
m_OtherInfoSet.Edit();
m_OtherInfoSet.m_content= m_Edit2;
m_OtherInfoSet.m_name= m_EDIT1;
m_OtherInfoSet.Update();
m_OtherInfoSet.Close();
m_setOther.DeleteAllItems();
if(!m_OtherInfoSet.Open())
{
AfxMessageBox("打开数据库失败!");
return;
}
m_OtherInfoSet.MoveFirst();//move to the first
do
{
CString s;
s.Format("%d",k);
m_setOther.InsertItem(k,s,0);
m_setOther.SetItemText(k,0,m_OtherInfoSet.m_name);
m_setOther.SetItemText(k,1,m_OtherInfoSet.m_content);
m_setOther.SetItemText(k,2,m_OtherInfoSet.m_description);
k++;
m_OtherInfoSet.MoveNext();
} while(!m_OtherInfoSet.IsEOF());
m_OtherInfoSet.Close();
GetDlgItem(IDC_MODIFY)->EnableWindow(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -