📄 leftdlg.cpp
字号:
// LeftDlg.cpp : implementation file
//
#include "stdafx.h"
#include "VCStyle.h"
#include "LeftDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "resource.h"
#include "data.h"
/////////////////////////////////////////////////////////////////////////////
// CLeftDlg dialog
CLeftDlg::CLeftDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLeftDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLeftDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
m_pwndExplorer = NULL;
m_ChildCtrlRect = CRect(0,0,0,0);
//
}
CLeftDlg::~CLeftDlg()
{
if(m_pwndExplorer)
delete m_pwndExplorer;
}
void CLeftDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLeftDlg)
DDX_Control(pDX, IDC_TREE_SYSTEM, m_systree);
DDX_Control(pDX, IDC_TAB, m_tab);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLeftDlg, CDialog)
//{{AFX_MSG_MAP(CLeftDlg)
ON_WM_SIZE()
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB, OnSelchangeTab)
ON_NOTIFY(NM_RCLICK, IDC_TREE_SYSTEM, OnRclickTreeSystem)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLeftDlg message handlers
void CLeftDlg::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
if(!m_tab.GetSafeHwnd()) return;
//draw tab ctrl first
m_tab.MoveWindow(0,0,cx,cy);
//get client rect of tab ctrl
CRect rc;
m_tab.GetItemRect(0,rc);
m_ChildCtrlRect = CRect(2,2,cx-2,cy-5-m_tab.GetRowCount()*rc.Height());
//decide show which window
m_systree.MoveWindow(&m_ChildCtrlRect);
m_pwndExplorer->MoveWindow(&m_ChildCtrlRect);
// ReShow();
}
void CLeftDlg::OnOK()
{
}
void CLeftDlg::OnCancel()
{
}
BOOL CLeftDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//创建tab
m_tabil.Create(IDB_BITMAP_TAB,16,0,RGB(255,255,255));
m_tab.SetImageList(&m_tabil);
m_tab.InsertItem(0,"文件",0);
m_tab.InsertItem(1,"系统",1);
//加入系统页
m_sysil.Create(IDB_BITMAP_SYS,16,0,RGB(255,255,255));
m_systree.SetImageList(&m_sysil,TVSIL_NORMAL);
//建立初始6个文件夹
tree<tree_node>::iterator it;
tree<tree_node>::iterator itad,itda,itdi,itdo,itdio,itqd;
tree_node tn;//构造一个tree_node
tn.is_model = FALSE;
HTREEITEM ht;
tn.ht = ht = m_systree.InsertItem("系统",0,3);
it = m_can.insert(m_can.begin(),tn);
tn.ht = m_systree.InsertItem("AD模块",1,4,ht);
itad = m_can.append_child(it,tn);
tn.ht = m_systree.InsertItem("DA模块",1,4,ht);
itda = m_can.append_child(it,tn);
tn.ht = m_systree.InsertItem("数字量输入",1,4,ht);
itdi = m_can.append_child(it,tn);
tn.ht = m_systree.InsertItem("数字量输出",1,4,ht);
itdo = m_can.append_child(it,tn);
tn.ht = m_systree.InsertItem("数字量输入/出",1,4,ht);
itdio = m_can.append_child(it,tn);
tn.ht = m_systree.InsertItem("驱动模块",1,4,ht);
itqd = m_can.append_child(it,tn);
//读入数据
for(int i=0;i<MAX_MODELS;i++){
BYTE addr = i;
UINT type = ModelTable[i].type;
CString name = ModelTable[i].name;
tree_node tn;
tn.is_model = TRUE;
tn.addr = addr;
switch(type){
case T_AD_7703:
case T_AD_7703_2:
case T_AD_7710:
tn.ht = m_systree.InsertItem(name,2,5,(*itad).ht);
m_can.append_child(itad,tn);
break;
case T_QD:
tn.ht = m_systree.InsertItem(name,2,5,(*itqd).ht);
m_can.append_child(itqd,tn);
break;
default:
break;
}
}
m_systree.Expand(ht,TVE_EXPAND);
//加入文件页
VERIFY(CreateExplorer());//must be true
//选择一下,使其中一页隐藏起来 cannot use SetCurSel.it does NOT invoke TCN_SELCHANGE
m_tab.SetCurFocus(-1);
m_tab.SetCurFocus(0);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CLeftDlg::CreateExplorer()
{
m_pwndExplorer = new CExplorePlug;
CRect rect = m_ChildCtrlRect;
if (!m_pwndExplorer->Create (WS_CHILD|WS_VISIBLE|TVS_HASLINES|TVS_HASBUTTONS|TVS_SHOWSELALWAYS, rect, &m_tab, 1))
{
TRACE (_T("Failed to create CExplorePlug\n"));
return FALSE;
}
m_pwndExplorer->SendMessage (SHLT_MODIFYPATTERN, 0, (LPARAM) _T ("*.*"));
m_pwndExplorer->SendMessage (SHLT_MODIFYFLAGS, 0, SHLT_FILES|SHLT_REFRESHONEXPAND);
m_pwndExplorer->ModifyStyleEx (0, WS_EX_CLIENTEDGE);
return TRUE;
}
void CLeftDlg::OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if(m_pwndExplorer && m_pwndExplorer->GetSafeHwnd()
&& m_systree.GetSafeHwnd()){
if(m_tab.GetCurSel()==0){
m_systree.ShowWindow(SW_HIDE);
m_pwndExplorer->ShowWindow(SW_SHOW);
}
else{
m_pwndExplorer->ShowWindow(SW_HIDE);
m_systree.ShowWindow(SW_SHOW);
}
}
*pResult = 0;
}
#include <Windowsx.h>
void CLeftDlg::OnRclickTreeSystem(NMHDR* pNMHDR, LRESULT* pResult)
{
DWORD dwPos = GetMessagePos();
/* Convert the co-ords into a CPoint structure */
CPoint pt( GET_X_LPARAM( dwPos ), GET_Y_LPARAM( dwPos ) ), spt;
spt = pt;
/* Convert to screen co-ords for hittesting */
m_systree.ScreenToClient( &spt );
UINT test;
HTREEITEM hti = m_systree.HitTest( spt, &test );
/* Did the click occur on an item */
if ( ( hti != NULL ) && ( test & TVHT_ONITEM ) )
{
//select correspond tree item
m_systree.SelectItem(hti);
//because we call WhomSelected function in OnSelChanged(),
//here not necessary to call it.
//判断是否是模块
tree<tree_node>::iterator it;
for(it = m_can.begin(); it != m_can.end(); ++it){
if((*it).ht == hti){
if((*it).is_model){
ShowPopupMenu(spt,IDR_MENU_SYSTREE);//client pt
}
break;
}
}
}
*pResult = 0;
}
void CLeftDlg::ShowPopupMenu(CPoint point, UINT MenuID)
{
//show menu
CMenu menu;
VERIFY(menu.LoadMenu(MenuID));
m_systree.ClientToScreen(&point);
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = &m_systree;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -