📄 tryfinddlg.cpp
字号:
// TryfindDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Tryfind.h"
#include "TryfindDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTryfindDlg dialog
CTryfindDlg::CTryfindDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTryfindDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTryfindDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CTryfindDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTryfindDlg)
DDX_Control(pDX, IDC_COMBO, m_ctrlCombo);
DDX_Control(pDX, IDC_LIST, m_ctrlList);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTryfindDlg, CDialog)
//{{AFX_MSG_MAP(CTryfindDlg)
ON_CBN_SELCHANGE(IDC_COMBO, OnSelchangeCombo)
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
ON_BN_CLICKED(IDC_BUTTON, OnButtonUp)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTryfindDlg message handlers
BOOL CTryfindDlg::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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
RECT rect;
m_ctrlList.GetClientRect( &rect );
int width = (rect.right - rect.left)/4;
m_ctrlList.InsertColumn( 0, L"Name", width );
m_ctrlList.SetColumnWidth( 0, width);
m_ctrlList.InsertColumn( 1, L"Type", width);
m_ctrlList.SetColumnWidth( 1, width);
m_ctrlList.InsertColumn( 2, L"Modified", width*2);
m_ctrlList.SetColumnWidth( 2, width*2);
SHFILEINFO shFinfo;
HIMAGELIST hImgList = NULL;
if ( m_ctrlList.GetImageList( LVSIL_SMALL ) )
m_ImgLst.Detach();
hImgList = ( HIMAGELIST )SHGetFileInfo( L"\\",
0,
&shFinfo,
sizeof( shFinfo ),
SHGFI_ICON | SHGFI_SMALLICON );
if ( !hImgList )
return FALSE;
if ( !m_ImgLst.Attach( hImgList ) )
return FALSE;
m_ctrlList.SetImageList( &m_ImgLst, LVSIL_SMALL );
DisplayDirContents( '\\');
return TRUE; // return TRUE unless you set the focus to a control
}
void CTryfindDlg::DisplayDirContents( CString csDirPath )
{
m_ctrlList.DeleteAllItems();
AddDirtoCombo( csDirPath );
if( csDirPath.Right(1) != '\\' )
csDirPath += '\\';
csDirPath += L"*.*";
BOOL bFound;
bFound = m_finder.FindFile( csDirPath );
int i = 0;
while ( bFound )
{
bFound = m_finder.FindNextFile();
CString csName = m_finder.GetFileName();
// m_ctrlList.InsertItem( i, csName );
AddItemToList( i );
i++;
}
m_finder.Close();
}
void CTryfindDlg::OnSelchangeCombo()
{
CString csPath;
m_ctrlCombo.GetLBText( m_ctrlCombo.GetCurSel(), csPath );
DisplayDirContents( csPath );
}
void CTryfindDlg::AddDirtoCombo(CString csDir)
{
int nFound = m_ctrlCombo.FindStringExact( -1, csDir );
if( nFound == CB_ERR )
nFound = m_ctrlCombo.AddString( csDir );
m_ctrlCombo.SetCurSel( nFound );
}
void CTryfindDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// int nMark = m_ctrlList.GetSelectedCount();
// GetSelectionMark() is not supported on WCE 2.0 so we use GetNextItem()
int nMark = m_ctrlList.GetNextItem( -1, LVNI_SELECTED );
CString csPath;
m_ctrlCombo.GetLBText(m_ctrlCombo.GetCurSel(), csPath );
if ( csPath.Right(1) != '\\' )
csPath += '\\';
csPath += m_ctrlList.GetItemText( nMark, 0 ) ;
CCeFileFind finder;
BOOL bFound = finder.FindFile( csPath );
bFound = finder.FindNextFile();
if( finder.IsDirectory() )
{
AddDirtoCombo( csPath );
DisplayDirContents( csPath );
}
finder.Close();
*pResult = 0;
}
BOOL CTryfindDlg::AddItemToList( int nItem )
{
int iSubItem, iActualItem;
LV_ITEM lvitem;
for ( iSubItem = 0; iSubItem < 3; iSubItem++)
{
lvitem.mask = (iSubItem == 0)? LVIF_TEXT | LVIF_IMAGE : LVIF_TEXT;
lvitem.iItem = (iSubItem == 0)? nItem : iActualItem;
lvitem.iSubItem = iSubItem;
if(iSubItem == 0)
{
CString csName = m_finder.GetFileName();
lvitem.pszText = csName.GetBuffer( csName.GetLength() );
csName.ReleaseBuffer();
SHFILEINFO shFinfo;
if ( !SHGetFileInfo( m_finder.GetFilePath() ,0,&shFinfo,sizeof( shFinfo ),
SHGFI_ICON |SHGFI_SMALLICON ) )
return FALSE ;
lvitem.iImage = shFinfo.iIcon;
iActualItem = m_ctrlList.InsertItem(&lvitem); // insert new item
}
else if(iSubItem == 1 )
{
LPTSTR lpsz = new unsigned short[10];
DWORD dwSize = m_finder.GetLength() / 1024;
if( dwSize > 0 )
wsprintf( lpsz, L"%d K", dwSize );
else
wsprintf( lpsz, L"%c", ' ' );
lvitem.pszText = lpsz;
m_ctrlList.SetItem(&lvitem); // modify existing item (the sub-item text)
delete [] lpsz;
}
else if(iSubItem == 2 )
{
FILETIME ft;
m_finder.GetLastAccessTime( &ft );
LPTSTR lpsz = FormatTime( &ft );
lvitem.pszText = lpsz;
m_ctrlList.SetItem(&lvitem); // modify existing item (the sub-item text)
delete [] lpsz;
}
}
return TRUE;
}
LPTSTR CTryfindDlg::FormatTime(FILETIME *pft)
{
char szDate[ 40 ], szTime[ 40 ];
SYSTEMTIME st;
FileTimeToSystemTime( pft, &st );
memset( szDate, 0, sizeof( szDate ) );
memset( szTime, 0, sizeof( szTime ) );
GetDateFormat( GetUserDefaultLCID(), 0, &st, NULL, (unsigned short *)szDate, sizeof( szDate ) );
GetTimeFormat( GetUserDefaultLCID(), 0, &st, NULL, (unsigned short *)szTime, sizeof( szTime ) );
LPTSTR lpsz = new WCHAR[MAX_PATH];
memset( lpsz, 0, MAX_PATH );
wsprintf( lpsz, L"%s %s", szTime , szDate );
return lpsz;
}
void CTryfindDlg::OnButtonUp()
{
CString csPath;
m_ctrlCombo.GetLBText(m_ctrlCombo.GetCurSel(), csPath );
int nPos = csPath.ReverseFind( '\\' );
if( nPos == 0 )
csPath = '\\';
else
csPath = csPath.Left( nPos );
AddDirtoCombo( csPath );
DisplayDirContents( csPath );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -