📄 cxml2itemsdlg.cpp
字号:
// CXML2ITEMSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CXML2ITEMS.h"
#include "CXML2ITEMSDlg.h"
#include "XMLFile.h"
//#include "TestSetObject.h"
#include "TestSetObjects1.h"
#include "TestCaseObjects.h"
#include "TestRunObjects.h"
#include "TestStepObjects.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
typedef CTypedPtrArray<CObArray,CTestSetObject*> CMyObjectArray;
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCXML2ITEMSDlg dialog
CCXML2ITEMSDlg::CCXML2ITEMSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCXML2ITEMSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCXML2ITEMSDlg)
m_strNodeValue = _T("");
m_strNodeProValue = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
count=0;
}
void CCXML2ITEMSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCXML2ITEMSDlg)
DDX_Control(pDX, IDC_TREE1, m_TreeCtrl);
DDX_Text(pDX, IDC_EDIT1, m_strNodeValue);
DDV_MaxChars(pDX, m_strNodeValue, 1024);
DDX_Text(pDX, IDC_EDIT2, m_strNodeProValue);
DDV_MaxChars(pDX, m_strNodeProValue, 512);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCXML2ITEMSDlg, CDialog)
//{{AFX_MSG_MAP(CCXML2ITEMSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCXML2ITEMSDlg message handlers
BOOL CCXML2ITEMSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CCXML2ITEMSDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CCXML2ITEMSDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCXML2ITEMSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCXML2ITEMSDlg::OnOK()
{
}
void CCXML2ITEMSDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CString strPath;
CFileDialog fileDlg(TRUE);
if(fileDlg.DoModal()==IDOK)
{
strPath = fileDlg.GetFileName();
UpdateData(FALSE);
} else {
strPath = "";
}
//m_ImageList.Create(32,16,ILC_COLOR8|ILC_MASK,4,1);
m_ImageList.Create(IDB_BITMAP4,16,16, RGB(0, 0x80, 0x80));
m_TreeCtrl.SetImageList(&m_ImageList,TVSIL_NORMAL);
/*SHFILEINFO fi;
SHGetFileInfo("C:\\WINNT",0,&fi,sizeof(SHFILEINFO),
SHGFI_ICON|SHGFI_SMALLICON); //获取文件夹图标
m_ImageList.Add(fi.hIcon);
SHGetFileInfo("C:\\WINNT",0,&fi,sizeof(SHFILEINFO),
SHGFI_ICON|SHGFI_SMALLICON|SHGFI_OPENICON); //获取打开文件夹图标
m_ImageList.Add(fi.hIcon);*/
/*m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));*/
//CString strPath = "test12.xml";
if(strPath!="")
{
CXMLFile theFile(strPath);
CXMLFile* p_theXMLFile = &theFile;
CTestSetObjects objTestSets(p_theXMLFile);
CTestSetObject* p_theTestSet;
CString strRoot;
HTREEITEM htemp;
htemp=m_TreeCtrl.GetRootItem();
while(htemp!=NULL)
{
if(m_TreeCtrl.GetItemText(htemp)==strPath)
{
break;
}
htemp = m_TreeCtrl.GetNextSiblingItem(htemp);
}
if(htemp==NULL)
{
HTREEITEM hRoot, hRoot1, hSubNode;
HTREEITEM htempNode, htempNode1;
hRoot = m_TreeCtrl.InsertItem(strPath,0,1); //根节点为XML文件名
int count = objTestSets.m_testsetobArray.GetSize();
for(int i=0;i<count;i++) //不同的testset依次插入
{
p_theTestSet = objTestSets.m_testsetobArray[i];
CString strTestPath = p_theTestSet->m_strTestSetFolder;
CStringArray strNodeTag;
CString str;
int pos;
pos = strTestPath.Find('\\');
if(pos>0) //取testset路径层次
{
while(pos>0)
{
str = strTestPath.Mid(0,pos);
strNodeTag.Add(str);
strTestPath = strTestPath.Mid((pos+1));
pos=strTestPath.Find('\\');
}
strNodeTag.Add(strTestPath);
} else {
strNodeTag.Add(strTestPath);
}
strNodeTag.Add(p_theTestSet->m_strName); //将testset folder子路径以及testset name组合为数组,供后面构造节点使用
//for(int n=0;n<strNodeTag.GetSize();n++)
//{
// AfxMessageBox(strNodeTag[n]);
//}
htempNode = m_TreeCtrl.GetChildItem(hRoot); //同一个testset集合,根节点相同
if(htempNode!=NULL)
{
htempNode1 = htempNode;
for(int j=0;j<(strNodeTag.GetSize()-1);j++) //依次取路径中的子路径
{
CString str=strNodeTag[j];
while(str!=m_TreeCtrl.GetItemText(htempNode1) )
{
//htempNode = htempNode1;
htempNode1 = m_TreeCtrl.GetNextSiblingItem(htempNode); //取下一个兄弟节点
if(htempNode1==NULL)
{
break;
}
}
if(htempNode1==NULL) //表示该层所有节点均不匹配
{
hRoot1 = m_TreeCtrl.GetParentItem(htempNode);
for(int k=j;k<strNodeTag.GetSize();k++) //插入未匹配之后的节点文本
{
hSubNode = m_TreeCtrl.InsertItem(strNodeTag[k],2,3,hRoot1);
hRoot1 = hSubNode;
}
j=strNodeTag.GetSize();
} else {
htempNode1 = m_TreeCtrl.GetChildItem(htempNode1); //将匹配节点的子节点置为当前节点
if(!m_TreeCtrl.ItemHasChildren(htempNode1)) //如无子节点,则表明所遍历节点已经为叶子节点
{
if(m_TreeCtrl.GetItemText(htempNode1)==str) //如节点文本相同,此处无法区别处理该节点为folder或testset
{
hRoot1 = htempNode1;
} else {
hRoot1 = m_TreeCtrl.GetParentItem(htempNode1);
}
for(int k=(j+1);k<strNodeTag.GetSize();k++) //插入未匹配之后的节点文本
{
hSubNode = m_TreeCtrl.InsertItem(strNodeTag[k],2,3,hRoot1);
hRoot1 = hSubNode;
}
j=strNodeTag.GetSize();
}
if(j==(strNodeTag.GetSize()-2))
{
hRoot1 = m_TreeCtrl.GetParentItem(htempNode1);
for(int k=(j+1);k<strNodeTag.GetSize();k++) //插入未匹配之后的节点文本
{
hSubNode = m_TreeCtrl.InsertItem(strNodeTag[k],2,3,hRoot1);
hRoot1 = hSubNode;
}
}
htempNode = htempNode1;
}
}
} else {
hRoot1=hRoot;
for(int j=0;j<strNodeTag.GetSize();j++)
{
hSubNode = m_TreeCtrl.InsertItem(strNodeTag[j],2,3,hRoot1);
hRoot1 = hSubNode;
}
}
}
}
}
m_ImageList.Detach();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -