CImagelist m_treeImageList;
CTreeCtrl m_tree
m_treeImageList.Create(16,16,FALSE,1,0); //创建Cimagelist控件
HICON hIcon = ::LoadIcon(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ICON1));
//HMENU hMenu = ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_PANEL));
m_treeImageList.Add(hIcon);
m_tree.SetImageList(&m_treeImageList, LVSIL_NORMAL);//将CImagelist控件 和CTreeCtrl控件相关联
m_root = m_tree.InsertItem("院系信息"); //插入根结点
AddtoTree(m_root, 0);//自定义的AddtoTree,目的是将创建的树结点添加到树形控件中
m_tree.Expand(m_root, TVE_EXPAND);
//选中根结点
m_tree.SelectItem(m_root);
// 修改按钮
void CSpecialityMan::OnModiButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
CAdodc m_Adodc;
CDataGrid m_Datagrid;
if (m_Adodc.GetRecordset().GetEof())
{
MessageBox("请选择要修改的记录!");
return;
}
CSpeciality cur;//自定义的专业信息数据库类
cur.GetInfo(m_Datagrid.GetItem(0));
CSpecialEditDlg dlg;//自定义的专业信息对话框类
dlg.SpeId = cur.SpeId;
dlg.Name = cur.Name;
dlg.DepId = cur.DepId;
dlg.m_dep = m_Datagrid.GetItem(2);
dlg.m_name = cur.Name;
dlg.m_describe = cur.Describes;
if (dlg.DoModal() == IDOK)
{//从树控件中读取院系编号信息
int iDepId;
HTREEITEM node;
node = m_tree.GetSelectedItem();
iDepId = m_tree.GetItemData(node);
//根据院系编号设置SQL语句
CString cDepId;
cDepId.Format("%d", iDepId);
// 设置Select语句
CString cSource = "SELECT s.SpeId, s.Name AS 专业名称, d.DepName AS 院系,"
" s.Describes AS 专业描述FROM Speciality s, DepInfo d"
" WHERE s.DepId = d.DepId";
// 如果选择的不是根结点
if(m_tree.GetItemData(node) != 0) // 不是根节点
{ //第二级结点
if(m_tree.GetItemData(m_tree.GetParentItem(node)) != 0)
{
cSource += " AND d.DepId = " + cDepId;
}
// 第一级结点
else
{
cSource += " AND (d.UID = " + cDepId + " OR d.DepId = " + cDepId + ")";
}
}
//刷新ADO Data控件的记录源
m_Adodc.SetRecordSource(cSource);
m_Adodc.Refresh();
//设置列宽度
_variant_t vIndex;
vIndex = long(0);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
vIndex = long(1);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(2);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(2);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(100);
}
}
class CStoreMan : public CDialog
{
// Construction
public:
CStoreMan(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CStoreMan)
enum { IDD = IDD_STOREMAN };
CTabCtrl m_tab;
CChild1 ch1;//一个对话框
CChild2 ch2;//另一个对话框
CChild4 ch4;//一个对话框
CChild5 ch5;
//}}AFX_DATA
};
BOOL CStoreMan::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_tab.InsertItem(0,_T("登记入库"),0);
m_tab.InsertItem(1,_T("入库查询"),1);
m_tab.InsertItem(2,_T("当前库存信息"),2);
m_tab.InsertItem(3,_T("用户管理"),3);
ch1.Create(IDD_CH1,GetDlgItem(IDC_TAB1));
ch2.Create(IDD_CH2,GetDlgItem(IDC_TAB1));
//ch3.Create(IDD_CH3,GetDlgItem(IDC_TAB1));
ch4.Create(IDD_CH4,GetDlgItem(IDC_TAB1));
ch5.Create(IDD_CH5,GetDlgItem(IDC_TAB1));
CRect rect;
m_tab.GetClientRect(&rect);
rect.top+=40;
rect.bottom-=10;
rect.left+=10;
rect.right-=10;
ch1.MoveWindow(&rect);
ch1.ShowWindow(SW_SHOW);
ch2.MoveWindow(&rect);
ch2.ShowWindow(SW_HIDE);
//ch3.MoveWindow(&rect);
//ch3.ShowWindow(SW_HIDE);
ch4.MoveWindow(&rect);
ch4.ShowWindow(SW_HIDE);
ch5.MoveWindow(&rect);
ch5.ShowWindow(SW_HIDE);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
IDC_TAB1的TCN_SELCHANGE消息处理函数:通过点击Tab选项的来显示和隐藏相应的对话框
void CStoreMan::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//µ±µã»÷ÁËTabµÄ°´Å¥
int num=m_tab.GetCurSel();
switch(num)
{
case 0:ch1.ShowWindow(SW_SHOW);
ch2.ShowWindow(SW_HIDE);
ch4.ShowWindow(SW_HIDE);
ch5.ShowWindow(SW_HIDE);
break;
case 1:ch1.ShowWindow(SW_HIDE);
ch2.ShowWindow(SW_SHOW);
ch4.ShowWindow(SW_HIDE);
ch5.ShowWindow(SW_HIDE);
break;
case 2:ch1.ShowWindow(SW_HIDE);
ch2.ShowWindow(SW_HIDE);
ch4.ShowWindow(SW_SHOW);
ch5.ShowWindow(SW_HIDE);
break;
case 3:ch1.ShowWindow(SW_HIDE);
ch2.ShowWindow(SW_HIDE);
ch4.ShowWindow(SW_HIDE);
ch5.ShowWindow(SW_SHOW);
break;
}
*pResult = 0;
}