// test11Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "test11.h"
#include "test11Dlg.h"
#include "FileOptionDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort)
{
CTest11Dlg *dlg = (CTest11Dlg*)lParamSort;
CListCtrl *listCtrl = &dlg->m_listCtrl;
LVFINDINFO findInfo;
findInfo.flags = LVFI_PARAM;
findInfo.lParam = lParam1;
int nItem1 = listCtrl->FindItem(&findInfo);
findInfo.lParam = lParam2;
int nItem2 = listCtrl->FindItem(&findInfo);
// if (nItem2==-1 || nItem1==-1)
// {
// return 0;
// }
CString str1;
CString str2;
str1 = listCtrl->GetItemText(nItem1, 0);
str2 = listCtrl->GetItemText(nItem2, 0);
int nCom = str1.CompareNoCase(str2);
return nCom;
}
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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest11Dlg dialog
CTest11Dlg::CTest11Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTest11Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CTest11Dlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_bAddImage = TRUE;
}
void CTest11Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CTest11Dlg)
DDX_Control(pDX, IDC_LIST1, m_listCtrl);
DDX_Control(pDX, IDC_TREE1, m_treeCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CTest11Dlg, CDialog)
//{{AFX_MSG_MAP(CTest11Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_NOTIFY(NM_RCLICK, IDC_TREE1, OnRclickTree1)
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1)
ON_WM_SIZE()
ON_WM_MOVE()
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
ON_NOTIFY(TVN_ITEMEXPANDING, IDC_TREE1, OnItemexpandingTree1)
ON_COMMAND(ID_SORT_BYNAME, OnSortByname)
ON_WM_CONTEXTMENU()
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
ON_COMMAND(ID_MENU_OPTION, OnMenuOption)
ON_COMMAND(ID_DIR_OPTION, OnDirOption)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_COMMAND(ID_OPEN_FILE, OnOpenFile)
ON_COMMAND(ID_OPEN_BYNOTEPAD, OnOpenBynotepad)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_COMMAND(ID_EDIT_CUT, OnEditCut)
ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
ON_COMMAND(ID_EDIT_PASTER, OnEditPaster)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTER, OnUpdateEditPaster)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTest11Dlg message handlers
BOOL CTest11Dlg::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
SetDefID(IDC_LIST1);
m_ImageList.Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 1);
m_ImageList.SetBkColor(RGB(255, 255, 255));
m_pImageList = new CImageList();
m_pImageList->Create(32, 32, ILC_COLOR32 | ILC_MASK, 0, 1);
m_treeCtrl.SetImageList(&m_ImageList, TVSIL_NORMAL);
m_listCtrl.SetImageList(m_pImageList, TVSIL_NORMAL);
InitTreeCtrl();
InitLisCtrl();
CRect rc;
m_treeCtrl.GetWindowRect(&rc);
ScreenToClient(&rc);
//rc.InflateRect(5,5,5,5);
m_rectTracker = CRectTracker(rc, CRectTracker::dottedLine | CRectTracker::resizeOutside);
return TRUE; // return TRUE unless you set the focus to a control
}
void CTest11Dlg::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 CTest11Dlg::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();
CDC *pDC = GetDC();
m_rectTracker.Draw(pDC);
pDC->DeleteDC();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CTest11Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CTest11Dlg::InitLisCtrl()
{
m_listCtrl.SetExtendedStyle(LVS_EX_INFOTIP);
//m_listCtrl.InsertColumn(0, _T("PATH"), LVCFMT_CENTER);
//m_listCtrl.SetColumnWidth (0, 500);
return TRUE;
}
BOOL CTest11Dlg::InitTreeCtrl()
{
HICON icon = AfxGetApp()->LoadIcon(IDI_ICON_COMPUTER);
int nIcon = m_ImageList.Add(icon);
m_hRoot = m_treeCtrl.InsertItem(_T("我的电脑"), nIcon, nIcon, TVI_ROOT);
GetLogicalDrives(m_hRoot);
m_treeExpand[m_hRoot] = TRUE;
return TRUE;
}
void CTest11Dlg::GetLogicalDrives(HTREEITEM hParent)
{
DWORD drive = ::GetLogicalDrives();
int nIcon = 0;
CString strDrive(_T("C:"));
for(int i=0; i<32; i++)
{
if ((drive>>i & 1) == 1)
{
TCHAR ch = 'A' + i;
strDrive.SetAt(0, ch);
}
else
{
continue;
}
CString strDrivePath = strDrive;
if(strDrivePath.Right(1) != "\\")
strDrivePath += "\\";
SHFILEINFO info;
SHGetFileInfo(strDrivePath,
0,
&info,sizeof(SHFILEINFO),
SHGFI_ICON);
HICON hIcon = info.hIcon;
int nIcon = m_ImageList.Add(hIcon);
DestroyIcon(hIcon);
HTREEITEM hRoot0 = m_treeCtrl.InsertItem(strDrive, nIcon, nIcon, hParent);
TVITEM *pItem = new TVITEM;
pItem->hItem = hRoot0;
pItem->mask |= TVIF_CHILDREN;
m_treeCtrl.GetItem(pItem);
pItem->cChildren = 1;
pItem->mask |= TVIF_CHILDREN;
m_treeCtrl.SetItem(pItem);
delete pItem;
m_treeExpand[hRoot0] = FALSE;
}
}
void CTest11Dlg::OnRclickTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
POINT pt = GetCurrentMessage()->pt;
m_treeCtrl.ScreenToClient(&pt);
UINT nFlags = 0;
HTREEITEM hTree = m_treeCtrl.HitTest(pt, &nFlags);
if ( (hTree != NULL) && ( (nFlags & TVHT_ONITEMLABEL) ==TVHT_ONITEMLABEL ) )
{
m_treeCtrl.SelectItem(hTree);
CRect rc;
m_treeCtrl.GetWindowRect(&rc);
ScreenToClien
- 1
- 2
- 3
前往页