123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- // Dlg_EditView.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "Dlg_EditView.h"
- #include ".\dlg_editview.h"
- #include <io.h>
- #include "shlwapi.h"
- #define FILE_NAME "sort.txt"
- // CDlg_EditView 对话框
- IMPLEMENT_DYNAMIC(CDlg_EditView, CDialog)
- CDlg_EditView::CDlg_EditView(CWnd* pParent /*=NULL*/)
- : CDialog(CDlg_EditView::IDD, pParent)
- {
-
- }
- CDlg_EditView::~CDlg_EditView()
- {
- }
- void CDlg_EditView::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_LIST1, m_ListView);
- }
- BEGIN_MESSAGE_MAP(CDlg_EditView, CDialog)
- ON_BN_CLICKED(IDC_BTN_DEL, OnBnClickedBtnDel)
- ON_BN_CLICKED(IDC_BTN_UP, OnBnClickedBtnUp)
- ON_BN_CLICKED(IDC_BTN_DOWN, OnBnClickedBtnDown)
- ON_BN_CLICKED(IDC_BTN_ALLSHOW, OnBnClickedBtnAllShow)
- ON_BN_CLICKED(IDC_BTN_ALLHIDE, OnBnClickedBtnAllHide)
- ON_BN_CLICKED(IDOK, OnBnClickedOk)
- ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnNMDblclkList1)
- END_MESSAGE_MAP()
- // CDlg_EditView 消息处理程序
- BOOL CDlg_EditView::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: 在此添加额外的初始化
- m_ListView.InsertColumn(0, "画面名称");
- m_ListView.SetColumnWidth(0, 1000);
- m_ListView.SetExtendedStyle(m_ListView.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
- ////////////////////
- char szPicDir[MAX_PATH] = {0};
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- m_sPath.Format( "%s",szPicDir );
- ReadALlView();
- //CButtonST m_btnDel,m_btnUp,m_btnDown,m_btnShow,m_btnHide,m_btnSave,m_btnExit;
- m_btnShow.SubclassDlgItem(IDC_BTN_ALLSHOW, this);
- m_btnShow.SetBitmaps(IDB_EDIT, RGB(255, 0, 255));
- m_btnShow.SetFlat(FALSE);
- m_btnShow.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnHide.SubclassDlgItem(IDC_BTN_ALLHIDE, this);
- m_btnHide.SetBitmaps(IDB_COPY , RGB(192, 192, 192));
- m_btnHide.SetFlat(FALSE);
- m_btnHide.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnSave.SubclassDlgItem(IDOK, this);
- m_btnSave.SetBitmaps(IDB_SAVE, RGB(255,0 , 255));
- m_btnSave.SetFlat(FALSE);
- m_btnSave.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnDel.SubclassDlgItem(IDC_BTN_DEL, this);
- m_btnDel.SetBitmaps(IDB_DEL, RGB(255,0 , 255));
- m_btnDel.SetFlat(FALSE);
- m_btnDel.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnExit.SubclassDlgItem(IDCANCEL, this);
- m_btnExit.SetBitmaps(IDB_EXIT, RGB(192, 192, 192));
- m_btnExit.SetFlat(FALSE);
- m_btnExit.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnUp.SubclassDlgItem(IDC_BTN_UP, this);
- m_btnUp.SetIcon(IDI_ICON_UP);
- m_btnUp.SetFlat(FALSE);
- m_btnUp.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- m_btnDown.SubclassDlgItem(IDC_BTN_DOWN, this);
- m_btnDown.SetIcon(IDI_ICON_DOWN);
- m_btnDown.SetFlat(FALSE);
- m_btnDown.SetAlign(CButtonST::ST_ALIGN_HORIZ);
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void CDlg_EditView::OnBnClickedBtnDel()
- {
- m_ListView.SetFocus();
- int iListCount = m_ListView.GetItemCount();
- POSITION pos = m_ListView.GetFirstSelectedItemPosition();
- int nListSel = m_ListView.GetNextSelectedItem(pos);
- if(nListSel>=iListCount || nListSel==-1 )
- {
- return;
- }
- m_ListView.DeleteItem( nListSel );
- }
- void CDlg_EditView::OnBnClickedBtnUp()
- {
- m_ListView.SetFocus();
- int iListCount = m_ListView.GetItemCount();
- POSITION pos = m_ListView.GetFirstSelectedItemPosition();
- int nListSel = m_ListView.GetNextSelectedItem(pos);
- if(nListSel>=iListCount || nListSel==-1 || nListSel==0 )
- {
- return;
- }
- CString str1,str2,s1,s2;
- str1 = m_ListView.GetItemText( nListSel,0 );
- str2 = m_ListView.GetItemText( nListSel-1,0 );
- m_ListView.SetItemText( nListSel,0,str2 );
- m_ListView.SetItemText( nListSel-1,0,str1 );
- m_ListView.SetItemState( nListSel,0,LVIS_SELECTED|LVIS_FOCUSED );
- m_ListView.SetItemState( nListSel-1,LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED );
- }
- void CDlg_EditView::OnBnClickedBtnDown()
- {
- m_ListView.SetFocus();
- int iListCount = m_ListView.GetItemCount();
- POSITION pos = m_ListView.GetFirstSelectedItemPosition();
- int nListSel = m_ListView.GetNextSelectedItem(pos);
- if(nListSel>=iListCount-1 || nListSel==-1 )
- {
- return;
- }
- CString str1,str2,s;
- str1 = m_ListView.GetItemText( nListSel,0 );
- str2 = m_ListView.GetItemText( nListSel+1,0 );
- m_ListView.SetItemText( nListSel,0,str2 );
- m_ListView.SetItemText( nListSel+1,0,str1 );
- m_ListView.SetItemState(nListSel,0,LVIS_SELECTED|LVIS_FOCUSED);
- m_ListView.SetItemState( nListSel+1,LVIS_SELECTED, LVIS_SELECTED|LVIS_FOCUSED );
- }
- void CDlg_EditView::OnBnClickedBtnAllShow()
- {
- m_ListView.SetFocus();
- ShowAll();
- }
- void CDlg_EditView::OnBnClickedBtnAllHide()
- {
- m_ListView.SetFocus();
-
- HideAll();
- }
- void CDlg_EditView::OnBnClickedOk()
- {
- // TODO: 在此添加控件通知处理程序代码
- ShowAll();
- char szPicDir[MAX_PATH] = {0};
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- strcat(szPicDir, FILE_NAME);
- if( PathFileExists( szPicDir ) )
- DeleteFile( szPicDir );
- if( m_ListView.GetItemCount()==0 )
- return;
- CString strTemp;
- CStdioFile MyFile;
- MyFile.Open(szPicDir,CFile::modeCreate|CFile::modeWrite);
- for( int i=0;i<m_ListView.GetItemCount();i++ )
- {
- strTemp = m_ListView.GetItemText( i,0 );
- strTemp += "\n";
- MyFile.SeekToEnd();
- MyFile.WriteString(strTemp);
- }
-
- MyFile.Close();
- }
- void CDlg_EditView::OnBnClickedCancel()
- {
- // TODO: 在此添加控件通知处理程序代码
- OnCancel();
- }
- void CDlg_EditView::ReadALlView()
- {
- char szPicDir[MAX_PATH] = {0};
- strcpy(szPicDir, g_strDirectory);
- strcat(szPicDir, "\\");
- strcat(szPicDir, _PICTUREDIR);
- strcat(szPicDir, FILE_NAME);
- if( PathFileExists( szPicDir ) )
- {
- CString sTemp,strTemp1,strTemp2,sTemp2;
- CStdioFile File;
-
- if(!File.Open(szPicDir,CFile::modeRead))
- File.Open(szPicDir,CFile::modeCreate|CFile::modeRead);
- while(File.ReadString(sTemp))//定义一个CString变量sTemp作为缓冲区
- {
- m_ListView.InsertItem( m_ListView.GetItemCount(),sTemp );
- }
- File.Close();
- }
-
- CString strFindPicFile = "*.view";
- char szPicDir2[MAX_PATH] = {0};
- strcpy(szPicDir2, g_strDirectory);
- strcat(szPicDir2, "\\");
- strcat(szPicDir2, _PICTUREDIR);
- CStringArray SATemp;
- FileSearch( SATemp,0, szPicDir2, "*.*", 0);
- CString str1,str2;
- for( int i=m_ListView.GetItemCount()-1;i>=0;i-- )
- {
- str1 = m_ListView.GetItemText( i,0 );
- bool bExist = false;
- for( int m=0;m<SATemp.GetCount();m++ )
- {
- str2 = SATemp.GetAt( m );
- if( str1==str2 )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- m_ListView.DeleteItem( i );
- }
- }
- BOOL CDlg_EditView::DirSearch(CString strPath, CString strFileName)
- {
- BOOL bResult = FALSE;
- long hDir;
- struct _finddata_t fDir;
- int nDone;
- strPath += "*.*";
- hDir = _findfirst( (char *)(LPCTSTR)strPath, &fDir );
- if( -1L != hDir )
- {
- while( !( nDone = _findnext(hDir, &fDir) ) )
- {
- if( !strcmp(fDir.name, "..") ) continue;
- if( (_A_SUBDIR == fDir.attrib) )
- {
- CString str = fDir.name;
- if( !str.Compare(strFileName) )
- {
- bResult = TRUE;
- }
- }
- }
- }
- return bResult;
- }
- void CDlg_EditView::FileSearch( CStringArray &SATemp,int iInsertIndex, CString strPath, CString strFileName, int nLayer)
- {
- long hfile;
- struct _finddata_t fFile;
- CString strCurr = strPath + strFileName; // + "\\" +
-
- CString sIndex,sContent;
- int nDone=0;
- int nTime = 0;
- hfile = _findfirst( (char *)(LPCTSTR)strCurr, &fFile );
- if( -1L != hfile )
- {
- while( !( nDone = _findnext(hfile, &fFile) ) )
- {
- if( !strcmp(fFile.name,"..") ) continue;
- if( (_A_SUBDIR == fFile.attrib) )
- {
- strCurr = strPath + "\\" + fFile.name + "\\";
- int nPos = strCurr.Find("\\\\");
- if( nPos!=-1 )
- {
- strCurr.Delete( nPos );
- }
- CString str = fFile.name;
- //HTREEITEM hReturn = hItem;
- sContent = str;
-
- InsertToList( iInsertIndex,sContent,strPath );
- ////////////////////////////////////////////////
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=strPath )
- sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- SATemp.Add( sContent );
- ///////////////////////////////////////////////////
- iInsertIndex++;
- FileSearch( SATemp,iInsertIndex, strCurr, "*.*", nLayer + 1);
- //hItem = hReturn;
-
- if( g_bStartRun )
- {
- CString sPath = strCurr;
- int nPos = sPath.Find("*");
- if( nPos!=-1 )
- {
- sPath = sPath.Left( sPath.GetLength()-3 );
- }
-
- sPath = sPath+".view";
-
- nPos = sPath.Find("\\.");
- if( nPos!=-1 )
- {
- sPath.Delete( nPos );
- }
- }
- }
- else
- {
- CString str = fFile.name;
- if( str.Right(4).Compare("view") ) continue;
- CString strTemp = str.Left(str.GetLength()-5);
- if( !DirSearch(strPath + "\\", strTemp ) )
- {
- //m_wndTree.InsertItem(strTemp, 1, 1, hTemp);
- sContent = str;
- InsertToList( iInsertIndex,sContent,strPath );
- iInsertIndex++;
- ////////////////////////////////////////////////
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=strPath )
- sParent = strPath.Right( strPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- SATemp.Add( sContent );
- ///////////////////////////////////////////////////
- }
- }
- }
- _findclose(hfile);
- }
- }
- void CDlg_EditView::InsertToList( int iInsertIndex,CString sContent,CString sPath )
- {
- CString str;
- if( sContent.Find(".view")!=-1 )
- sContent = sContent.Left( sContent.GetLength()-5 );
- CString sParent;
- if( m_sPath!=sPath )
- sParent = sPath.Right( sPath.GetLength()-m_sPath.GetLength() );
- if( sParent!="" )
- {
- sContent = sParent+sContent;
- }
- bool bExist=false;
- for( int i=0;i<m_ListView.GetItemCount();i++ )
- {
- str = m_ListView.GetItemText( i,0 );
-
- if( str==sContent )
- {
- bExist = true;
- break;
- }
- }
- if( !bExist )
- {
- int nInsert=m_ListView.GetItemCount();
- CString s1;
- s1 = GetPreStr( sContent );
- for( int i=nInsert-1;i>=0;i-- )
- {
- str = m_ListView.GetItemText( i,0 );
-
- if( str.Find( s1 )==0 )
- {
- nInsert = i+1;
- break;
- }
- }
- m_ListView.InsertItem( nInsert,sContent );
- }
- }
- int CDlg_EditView::GetLevel( CString sContent )
- {
- int nRet=0;
- for( int i=0;i<sContent.GetLength();i++ )
- {
- if( sContent[i]=='\\' )
- nRet++;
- if( sContent[i]=='[' )
- break;
- }
- return nRet;
- }
- CString CDlg_EditView::GetPreStr( CString sContent )
- {
- CString sRet;
- for( int i=sContent.GetLength()-1;i>=0;i-- )
- {
- if( sContent[i]=='\\' )
- {
- sRet = sContent.Left( i );
- break;
- }
- }
- return sRet;
- }
- void CDlg_EditView::ShowAll()
- {
- int nSize = m_ListView.GetItemCount();
- CString str;
- for( int i=0;i<nSize;i++ )
- {
- str = m_ListView.GetItemText( i,0 );
- ShowOne( "",str,i );
- nSize = m_ListView.GetItemCount();
- }
- }
- void CDlg_EditView::HideAll()
- {
- int nSize = m_ListView.GetItemCount();
- CString str;
- for( int i=nSize-1;i>=0;i-- )
- {
- str = m_ListView.GetItemText( i,0 );
- HideOne( "",str,i );
- }
- }
- void CDlg_EditView::ShowOne( CString sParent,CString sContent,int &iListIndex )
- {//A[\a[\1\2]\b[\1\2]] A[\a\b] A[\a\b[\1\2]]
- int nInsertLastIndex=iListIndex;
- bool bFirst = true;
- CString sData,s1,s2;
- int nStart=-1,nEnd=-1;
- nStart = sContent.Find("[");
- if( nStart==-1 )
- return;
- CString str;
- str = sContent.Left( nStart );
- sData = sContent.Mid( nStart+1,sContent.GetLength()-nStart-2 );
- //\a[\1\2]\b[\1\2] \a\b \a\b[\1\2]
- int nPos1=-1,nPos2=-1;
- nPos1 = sData.Find( "\\",0 );
- bool bOK=false;
- int nLastStatus=0;//0:\ 1:[ 2:]
- for( int i=1;i<sData.GetLength();i++ )
- {
- if( sData[i]=='\\' )
- {
- if( nLastStatus==0 )
- {
- nPos2 = i;
- bOK = true;
- }
- }
- else if( sData[i]=='[' )
- {
- nLastStatus = 1;
- }
- else if( sData[i]==']' )
- {
- if( nLastStatus==1 )
- {
- nLastStatus = 0;
- nPos2 = i;
- }
- }
- if( i==sData.GetLength()-1 )
- {
- nPos2 = sData.GetLength()-0;
- bOK = true;
- }
- if( bOK )
- {
- bOK = false;
- s1 = str + sData.Mid( nPos1,nPos2-nPos1 );
- nInsertLastIndex++;
- m_ListView.InsertItem( nInsertLastIndex,s1 );
- ShowOne( "",s1,nInsertLastIndex );
-
- i = nPos2;
- nPos1 = nPos2;
- }
- }
- if( nInsertLastIndex!=iListIndex )
- {
- m_ListView.SetItemText( iListIndex,0,str );
- iListIndex = nInsertLastIndex;
- }
- }
- void CDlg_EditView::HideOne( CString sParent,CString &sContent,int iListIndex )
- {
- int nDelLastIndex=-1;
- bool bFirst = true;
- CString sDesc=sContent,str1,str2,s1 = sContent,s2;
- int nCount1=0,nCount2=0;
- nCount1 = GetLevel( s1 );
- for( int i=iListIndex+1;i<m_ListView.GetItemCount();i++ )
- {
- s2 = m_ListView.GetItemText( i,0 );
- nCount2 = GetLevel( s2 );
- if( s2.Find(s1)==0 && nCount1+1==nCount2 )
- {
- HideOne( "",s2,i );
- nDelLastIndex = i;
- if( bFirst )
- {
- bFirst = false;
- sDesc += "[";
- }
- sDesc += s2.Right( s2.GetLength()-s1.GetLength() );
- }
- else
- break;
- }
- if( nDelLastIndex!=-1 )
- {
- sDesc += "]";
- sContent = sDesc;
- m_ListView.SetItemText( iListIndex,0,sDesc );
- }
-
- if( nDelLastIndex!=-1 )
- {
- for( int i=nDelLastIndex;i>iListIndex;i-- )
- {
- m_ListView.DeleteItem( i );
- }
- }
- }
- void CDlg_EditView::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
- {
- int iListCount = m_ListView.GetItemCount();
- POSITION pos = m_ListView.GetFirstSelectedItemPosition();
- int nListSel = m_ListView.GetNextSelectedItem(pos);
- if(nListSel>=iListCount || nListSel==-1)
- {
- return;
- }
- CString sDesc;
- sDesc = m_ListView.GetItemText( nListSel,0 );
- if( sDesc.Find("[")==-1 )
- {
- HideOne( "",sDesc,nListSel );
- }
- else
- {
- ShowOne( "",sDesc,nListSel );
- }
- *pResult = 0;
- }
|