📄 treetestdlg.cpp
字号:
// treetestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "treetest.h"
#include "treetestDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTreetestDlg dialog
CTreetestDlg::CTreetestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTreetestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTreetestDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTreetestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTreetestDlg)
DDX_Control(pDX, IDC_MYLIST, m_mylist);
DDX_Control(pDX, IDC_MYTREE, m_mytree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTreetestDlg, CDialog)
//{{AFX_MSG_MAP(CTreetestDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(TVN_BEGINDRAG, IDC_MYTREE, OnBegindragMytree)
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_NOTIFY(TVN_BEGINDRAG, IDC_MYLIST, OnBegindragMylist)
ON_NOTIFY(NM_RCLICK, IDC_MYLIST, OnRclickMylist)
ON_NOTIFY(NM_RCLICK, IDC_MYTREE, OnRclickMytree)
//}}AFX_MSG_MAP
ON_COMMAND(ID_EDIT_CUT, Zappit)
ON_COMMAND(ID_EDIT_COPY, AddNewProperty)
ON_COMMAND(ID_EDIT_PASTE, AddNewFolder)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTreetestDlg message handlers
BOOL CTreetestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
//////////////////////////////////////////////////////////////////
CString LibName=BinDir+"matlib.dat";
FILE *fp;
CMaterialProp MProp;
CFolderProp FProp;
char s[1024];
int k;
Ancestors.RemoveAll();
Parent=NULL;
// set up materials library tree control
m_bIsDragging = FALSE;
m_dragTargetTree = NULL;
m_dragTargetList = NULL;
m_dragItem = NULL;
m_imageList.Create( IDB_TREE, 16, 1, RGB(255,0,0) );
m_mytree.SetImageList( &m_imageList, TVSIL_NORMAL );
m_mylist.SetImageList( &m_imageList, TVSIL_NORMAL );
LibParent = m_mytree.InsertItem(TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_STATE,
"Library Materials",1,1,TVIS_EXPANDED ,TVIS_EXPANDED ,-9999,NULL,NULL);
Parent=LibParent;
ModelParent = m_mylist.InsertItem(TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_STATE,
"Model Materials",1,1,TVIS_EXPANDED ,TVIS_EXPANDED ,-9999,NULL,NULL);
/*
// Put Model's properties into the InModel edit box;
CArray<CMaterialProp,CMaterialProp&> &blockproplist=pDoc->blockproplist;
for(i=0;i<blockproplist.GetSize();i++)
m_inmodel.AddString(blockproplist[i].BlockName);
m_inmodel.SetCurSel(0);
*/
// Placeholder for items in the model materials list
m_mylist.InsertItem( "Stuff1", 2, 2, ModelParent );
// read in materials library;
LibProps.RemoveAll();
if ((fp=fopen(LibName,"rt"))==NULL) return TRUE;
while (fgets(s,1024,fp)!=NULL)
{
switch(ParseLine(s,fp,MProp,FProp))
{
case 1:
// add a material to library
k=LibProps.GetSize();
LibProps.Add(MProp);
m_mytree.InsertItem(TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT,
MProp.BlockName,2,2,NULL,NULL,k,Parent,NULL);
// MProp.BHpoints=0;
break;
case 2:
// open a new folder
if (Parent!=NULL) Ancestors.Add(Parent);
k=Ancestors.GetSize();
Parent=m_mytree.InsertItem(TVIF_IMAGE | TVIF_PARAM | TVIF_SELECTEDIMAGE | TVIF_TEXT,
FProp.FolderName,0,1,NULL,NULL,-k,Parent,NULL);
break;
case 3:
// close a folder
k=Ancestors.GetUpperBound();
if (k>=0){
Parent=Ancestors[k];
Ancestors.RemoveAt(k);
}
FoldProps.Add(FProp);
break;
default:
break;
}
}
// MProp.BHpoints=0;
fclose(fp);
/*
// tutorial example
HTREEITEM hChapter;
hChapter = m_mytree.InsertItem( "Chapter 1", 0, 1 );
m_mytree.InsertItem( "What", 2, 2, hChapter );
*/
Focus=NULL;
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CTreetestDlg::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 CTreetestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
///////////////////////////////////////////////////
// Implementation of library-specific file I/O
///////////////////////////////////////////////////
char* CTreetestDlg::StripKey(char *c)
{
char *d;
int i,k;
k=strlen(c);
for(i=0;i<k;i++){
if (c[i] == '='){
d=c+i+1;
return d;
}
}
return c+k;
}
int CTreetestDlg::ParseLine(char *s, FILE *fp, CMaterialProp &MProp, CFolderProp &FProp)
{
char q[1024];
char *v;
int i,k;
if (sscanf(s,"%s",q)==EOF) return FALSE;
// Library Hierarchy
if( _strnicmp(q,"<beginfolder>",13)==0){
// initialization of a new folder entry here
q[0]=NULL;
}
if( _strnicmp(q,"<foldername>",11)==0){
v=StripKey(s);
k=strlen(v);
for(i=0;i<k;i++)
if(v[i]=='\"'){
v=v+i+1;
i=k;
}
k=strlen(v);
if(k>0) for(i=k-1;i>=0;i--){
if(v[i]=='\"'){
v[i]=0;
i=-1;
}
}
FProp.FolderName=v;
q[0]=NULL;
return 2;
}
// Block Properties;
if( _strnicmp(q,"<beginblock>",12)==0){
// initialization of a new library entry here
q[0]=NULL;
}
// Library Hierarchy
if( _strnicmp(q,"<endfolder>",11)==0){
q[0]=NULL;
return 3;
}
if( _strnicmp(q,"<blockname>",10)==0){
v=StripKey(s);
k=strlen(v);
for(i=0;i<k;i++)
if(v[i]=='\"'){
v=v+i+1;
i=k;
}
k=strlen(v);
if(k>0) for(i=k-1;i>=0;i--){
if(v[i]=='\"'){
v[i]=0;
i=-1;
}
}
MProp.BlockName=v;
q[0]=NULL;
}
/*
// typical parse procedure
if( _strnicmp(q,"<mu_x>",6)==0){
v=StripKey(s);
sscanf(v,"%lf",&MProp.mu_x);
q[0]=NULL;
}
*/
if( _strnicmp(q,"<endblock>",9)==0){
q[0]=NULL;
return TRUE;
}
return FALSE;
}
////////////////////////////////////////////////////////////////
// Drag-n-Drop Implementation
void CTreetestDlg::OnBegindragMytree(NMHDR* pNMHDR, LRESULT* pResult)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -