📄 listviewdlg.cpp
字号:
// ListViewDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ListView.h"
#include "ListViewDlg.h"
#include "CeFileFind.h"
#include "JWListCtrl.h"
#include "MenuDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CListViewDlg dialog
CListViewDlg::CListViewDlg(CWnd* pParent /*=NULL*/)
: CDialog(CListViewDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CListViewDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CListViewDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CListViewDlg)
// DDX_Control(pDX, IDC_LIST1, m_cListCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CListViewDlg, CDialog)
//{{AFX_MSG_MAP(CListViewDlg)
ON_WM_PAINT()
ON_WM_CANCELMODE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_ACTIVATE()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_WM_PALETTECHANGED()
ON_WM_QUERYNEWPALETTE()
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnInitVScroll)
ON_NOTIFY(NM_CLICK, 1, OnClickList1)
ON_MESSAGE(IDOK,OnOK)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CListViewDlg message handlers
BOOL CListViewDlg::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
SetWindowPos(NULL,0,0,320,240,NULL);
// CenterWindow(GetDesktopWindow()); // center to the hpc screen
// TODO: Add extra initialization here
newlist = new CMyListCtrl;
newlist->Create( WS_VISIBLE |LVS_REPORT|LVS_OWNERDRAWFIXED/* LVS_ICON | LVS_NOSCROLL*/ ,
CRect(0,0,303,240), this , 1);
newlist->SetTextBkColor(CLR_NONE);
newlist->SetBkImage(IDB_BMP_ITEM);
newlist->InitVScroll();
newlist->HideScrollBars(LCSB_CLIENTDATA);
newlist->OnInitialUpdate();
int i=newlist->GetItemCount();
OpenFile();
return TRUE; // return TRUE unless you set the focus to a control
}
void CListViewDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
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();
}
// Do not call CDialog::OnPaint() for painting messages
}
void CListViewDlg::OnCancelMode()
{
CDialog::OnCancelMode();
// TODO: Add your message handler code here
}
void CListViewDlg::OnButton1()
{
// m_cListCtrl.InsertImgTextItems( IDB_IMAGES_NORMAL , 32 ,32,4,L"NewICON");
}
void CListViewDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
// CDialog::OnActivate(nState, pWndOther, bMinimized);
}
void CListViewDlg::OnButton2()
{
newlist = new CMyListCtrl;
newlist->Create( WS_VISIBLE |LVS_REPORT|LVS_OWNERDRAWFIXED/* LVS_ICON | LVS_NOSCROLL*/ ,
CRect(0,0,293,175), this , 1);
newlist->SetTextBkColor(CLR_NONE);
newlist->SetBkImage(IDB_BMP_ITEM);
newlist->InitVScroll();
newlist->HideScrollBars(LCSB_CLIENTDATA);
newlist->OnInitialUpdate();
}
void CListViewDlg::OnButton3()
{
//////////////////////////////////////////////////////////////////////////
/* newlist = new CMyListCtrl;
newlist->Create( WS_VISIBLE |LVS_REPORT|LVS_OWNERDRAWFIXED ,
CRect(0,0,303,190), this , 1);
newlist->SetTextBkColor(CLR_NONE);
newlist->SetBkImage(IDB_IMAGES_BK);
newlist->InitVScroll();
newlist->HideScrollBars(LCSB_CLIENTDATA);*/
//////////////////////////////////////////////////////////////////////////
if(newlist!=NULL)
newlist->InsertImgTextItems(0, 32,L"New Items");
}
void CListViewDlg::OnOK(LPARAM lparam,WPARAM wparam)
{
EndDialog(IDOK);
}
void CListViewDlg::OnPaletteChanged(CWnd* pFocusWnd)
{
CDialog::OnPaletteChanged(pFocusWnd);
}
BOOL CListViewDlg::OnQueryNewPalette()
{
CDialog::OnQueryNewPalette();
return TRUE;
}
void CListViewDlg::OnButton4()
{
newlist->SendMessage(WM_VSCROLL, MAKELONG(SB_PAGEDOWN,0),NULL);
}
void CListViewDlg::OnInitVScroll()
{
}
void CListViewDlg::OpenFile(LPTSTR path)
{
BOOL bf;
CCeFileFind find;
CString pathstr=path;
pathstr+=_T("\\*.*");
bf=find.FindFile(pathstr);
if (bf==false)
{
return;
}
int i=1;
CString insertstr;
newlist->DeleteAllItems();
while (bf)
{
i=newlist->GetItemCount();
insertstr=find.GetFilePath();
bf=find.FindNextFile();
if (!find.IsDots()&&insertstr.Find('.')==-1)//!
{
if(newlist!=NULL)
newlist->InsertImgTextItems(i, 32,insertstr.GetBuffer(30));
}
else
{
}
}
bf=find.FindFile(pathstr);
while (bf)
{
i=newlist->GetItemCount();
insertstr=find.GetFilePath();
bf=find.FindNextFile();
if (!find.IsDots()&&insertstr.Find('.')!=-1)//!
{
if(newlist!=NULL)
newlist->InsertImgTextItems(i, 32,insertstr.GetBuffer(30));
}
else
{
}
}
newlist->EnsureVisible(0,0);
}
void CListViewDlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem != -1)
{
CString strtemp;
strtemp.Format(_T("单击的是第%d行第%d列"),
pNMListView->iItem, pNMListView->iSubItem);
}
TCHAR szBuf[1024];
LVITEM lvi;
lvi.iItem = pNMListView->iItem;
lvi.iSubItem = 0;
lvi.mask = LVIF_TEXT;
lvi.pszText = szBuf;
lvi.cchTextMax = 1024;
newlist->GetItem(&lvi);
//////////////////////////////////////////////////////////////////////////
CString m_csRoot;
CString m_csPath;
m_csRoot = szBuf;
m_csPath = szBuf;
int nPos = m_csRoot.ReverseFind('.');
if(nPos == -1)
{
m_csRoot = '\\';
}
else
{
m_csRoot = m_csRoot.Right(m_csRoot.GetLength()-nPos-1);
}
if (m_csRoot==_T("mp4"))//音频播放
{
AfxMessageBox(m_csRoot);
}
else
if (m_csRoot == '\\')//文件夹
{
if (m_csPath==newlist->m_CurPath)//返回上一目录
{
int Pos = m_csPath.ReverseFind('\\');
if (Pos==0)
{
return ;
}
m_csPath = m_csPath.Left(Pos);
Pos = m_csPath.ReverseFind('\\');
m_csPath = m_csPath.Left(Pos);
OpenFile((LPTSTR)(LPCTSTR)m_csPath);
}
else
{
int Pos = m_csPath.ReverseFind('\\');
if(Pos == -1)
{
m_csPath = '\\';
}
else
{
OpenFile(szBuf);
}
}
}
else
if (m_csRoot== _T("txt"))//电子书
{
CMenuDlg *dlg=new CMenuDlg;
dlg->Create(IDD_DLG_MENU);
dlg->ShowWindow(SW_SHOW);
}
else
if (m_csRoot== _T("jpg")||m_csRoot== _T("bmp")||m_csRoot== _T("gif"))//电子书
{
}
else
if (m_csRoot== _T("exe"))//电子书??相关应用程序的识别
{
PROCESS_INFORMATION pi;
STARTUPINFO si;
memset(&pi,0,sizeof(pi));
memset(&si,0,sizeof(si));
if(FALSE==CreateProcess(szBuf,NULL,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi))
{
AfxMessageBox(L"load DMBTH Test APP Failed---/Storage Card/TestDmbth.exe");
}
}
//////////////////////////////////////////////////////////////////////////
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -