selecttables.cpp
来自「深入浅出Visual C++入门进阶与应用实例 随书光盘 作者 何志丹」· C++ 代码 · 共 153 行
CPP
153 行
// SelectTables.cpp : implementation file
//
#include "stdafx.h"
#include "SelectTables.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSelectTables dialog
CSelectTables::CSelectTables(CWnd* pParent /*=NULL*/)
: CDialog(CSelectTables::IDD, pParent)
{
//{{AFX_DATA_INIT(CSelectTables)
m_strSelectTable = _T("");
//}}AFX_DATA_INIT
m_style = ST_NULL;
m_ListBoxID = IDC_OLD_TABLE_SING ;
}
void CSelectTables::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSelectTables)
DDX_Control(pDX, IDC_TABLES, m_editTables);
DDX_Text(pDX, IDC_TABLES, m_strSelectTable);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSelectTables, CDialog)
//{{AFX_MSG_MAP(CSelectTables)
ON_LBN_SELCHANGE(IDC_OLD_TABLE_MUIL, OnSelchangeOldTableMuil)
ON_LBN_DBLCLK(IDC_OLD_TABLE_MUIL, OnDblclkOldTableMuil)
ON_LBN_SELCHANGE(IDC_OLD_TABLE_SING, OnSelchangeOldTableSing)
ON_LBN_DBLCLK(IDC_OLD_TABLE_SING, OnDblclkOldTableSing)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSelectTables message handlers
BOOL CSelectTables::OnInitDialog()
{
CDialog::OnInitDialog();
if(!m_strTitle.IsEmpty())
SetWindowText(m_strTitle);
if(!m_strInfo.IsEmpty())
GetDlgItem(IDC_GROUP)->SetWindowText(m_strInfo);
if(ST_READONLY & m_style)
m_editTables.SetReadOnly(true);
if(ST_MUIT & m_style)
{
m_ListBoxID = IDC_OLD_TABLE_MUIL ;
}
m_listOldTable.SubclassDlgItem(m_ListBoxID,this);
m_listOldTable.ShowWindow(SW_SHOW);
for(int i = 0 ; i < m_arTables.GetSize() ; i++)
m_listOldTable.AddString(m_arTables[i]);
if(0 != m_arTables.GetSize())
{
m_editTables.SetWindowText(m_arTables[0]);
m_editTables.SetSel(0,-1);
}
return TRUE;
}
void CSelectTables::OnOK()
{
CDialog::OnOK();
}
void CSelectTables::UpdateEditByListBox()
{
if(ST_MUIT & m_style)//多选
{
CString strSelectTable;
const int nCount = m_listOldTable.GetCount();
for(int i = 0 ; i < nCount ; i++ )
{
CString str;
int nSel = m_listOldTable.GetSel(i);
if(nSel <= 0)
continue;
if(!strSelectTable.IsEmpty())
strSelectTable += ' ';
m_listOldTable.GetText(i,str);
strSelectTable += str;
}
m_editTables.SetWindowText(strSelectTable);
}
else//单选
{
int nSel = m_listOldTable.GetCurSel();
if(-1 != nSel)
{
CString str;
m_listOldTable.GetText(nSel,str);
m_strSelectTable = str;
m_editTables.SetWindowText(str);
m_editTables.SetSel(0,-1);
m_editTables.SetFocus();
}
}
m_editTables.SetSel(0,-1);
m_editTables.SetFocus();
}
CString CSelectTables::GetTables()
{
if(IDOK == DoModal())
return m_strSelectTable;
else
return "";
}
void CSelectTables::OnSelchangeOldTableMuil()
{
UpdateEditByListBox();
}
void CSelectTables::OnDblclkOldTableMuil()
{
UpdateEditByListBox();
OnOK();
}
void CSelectTables::OnSelchangeOldTableSing()
{
UpdateEditByListBox();
}
void CSelectTables::OnDblclkOldTableSing()
{
UpdateEditByListBox();
OnOK();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?