?? usbhostdlg.cpp
字號:
// USBHostDlg.cpp : implementation file
//
#include "stdafx.h"
#include "USBHost.h"
#include "USBHostDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CUSBHostDlg dialog
CUSBHostDlg::CUSBHostDlg(CWnd* pParent /*=NULL*/)
: CDialog(CUSBHostDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CUSBHostDlg)
m_Dirname = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CUSBHostDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CUSBHostDlg)
DDX_Control(pDX, IDC_DIR_TREE, m_tree);
DDX_Text(pDX, IDC_DIRECT_NAME, m_Dirname);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CUSBHostDlg, CDialog)
//{{AFX_MSG_MAP(CUSBHostDlg)
ON_BN_CLICKED(IDC_LIST_DIRECTORY, OnListDirectory)
ON_EN_UPDATE(IDC_DIRECT_NAME, OnUpdateDirectName)
ON_NOTIFY(TVN_ITEMEXPANDED, IDC_DIR_TREE, OnItemexpandedDirTree)
ON_NOTIFY(TVN_ITEMEXPANDING, IDC_DIR_TREE, OnItemexpandingDirTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CUSBHostDlg message handlers
BOOL CUSBHostDlg::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
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CUSBHostDlg::OnListDirectory()
{
// TODO: Add your control notification handler code here
DWORD dwStyle = GetWindowLong(m_tree.m_hWnd,GWL_STYLE);
dwStyle |= TVS_HASBUTTONS | TVS_HASLINES | TVS_LINESATROOT;
SetWindowLong(m_tree.m_hWnd,GWL_STYLE,dwStyle);
if(m_Dirname != "")
{
m_hRoot = m_tree.InsertItem((m_Dirname));
}else
{
m_hRoot = m_tree.InsertItem(_T("\\Hard Disk"));
}
AddSubDir(m_hRoot);
m_tree.Expand(m_hRoot,TVE_EXPAND);
}
void CUSBHostDlg::OnUpdateDirectName()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function to send the EM_SETEVENTMASK message to the control
// with the ENM_UPDATE flag ORed into the lParam mask.
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CUSBHostDlg::OnItemexpandedDirTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
/*
TVITEM item = pNMTreeView->itemNew;
HTREEITEM hChild = m_tree.GetChildItem(item.hItem);
while(hChild)
{
AddSubDir(hChild);
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT);
}
*/
*pResult = 0;
}
void CUSBHostDlg::OnItemexpandingDirTree(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
TVITEM item = pNMTreeView->itemNew;
HTREEITEM hChild = m_tree.GetChildItem(item.hItem);
while(hChild)
{
AddSubDir(hChild);
hChild = m_tree.GetNextItem(hChild,TVGN_NEXT);
}
*pResult = 0;
}
// Define functions
void CUSBHostDlg::AddSubDir(HTREEITEM hParent)
{
CString strPath = GetFullPath(hParent);
if(strPath.Right(1) != "\\")
strPath += "\\";
strPath += "*.*";
WIN32_FIND_DATA tempFindFileName;
HANDLE hFindFile = FindFirstFile(strPath,&tempFindFileName);
BOOL bContinue = TRUE;
while(hFindFile != INVALID_HANDLE_VALUE && bContinue)
{
if(tempFindFileName.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
m_tree.InsertItem(tempFindFileName.cFileName,hParent);
bContinue = FindNextFile(hFindFile,&tempFindFileName);
}
}
CString CUSBHostDlg::GetFullPath(HTREEITEM hCurrent)
{
CString strTemp;
CString strReturn = m_Dirname;
if(m_Dirname != "")
{
strReturn = m_Dirname;
}else
{
strReturn = "\\Hard Disk\\";
}
while(hCurrent != m_hRoot)
{
strTemp = m_tree.GetItemText(hCurrent);
if(strTemp.Right(1) != "\\")
strTemp += "\\";
strReturn = strTemp + strReturn;
hCurrent = m_tree.GetParentItem(hCurrent);
}
return strReturn;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -