📄 getfileopenname.cpp
字号:
lvi1.pszText = wfd.cFileName;
lvi1.iItem = num;
ListView_InsertItem(hWnd,&lvi1);
ZeroMemory(string,sizeof(string));
wsprintf(string,_T("%s"),stFileInfo.szTypeName);
ListView_SetItemText(hWnd,num,2,string);//文件类型
ZeroMemory(string,sizeof(string));
wsprintf(string,_T("%04d-%02d-%02d %02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute);
ListView_SetItemText(hWnd,num,3,string);//修改时间
Flag[num] = 1;
// RETAILMSG(1,(L"num=%d",num));
}
}
else if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
{
lvi[j].mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
lvi[j].state = 0;
lvi[j].stateMask=0;
lvi[j].iSubItem=0;
FileTimeToSystemTime(&wfd.ftLastWriteTime,&st);//把文件时间转化为系统时间
wsprintf(szFileName,_T("%s\\%s"),m_szCurDir,wfd.cFileName);//文件路径
SHGetFileInfo(szFileName,NULL,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_TYPENAME);
hIcon = stFileInfo.hIcon;
ImageList_ReplaceIcon(ilist,i,hIcon);
lvi[j].iImage = i;
wsprintf(FileName[j],_T("%s"),wfd.cFileName);
ZeroMemory(string,sizeof(string));
wsprintf(FileSize[j],_T("%ld KB"),wfd.nFileSizeLow);
ZeroMemory(string,sizeof(string));
wsprintf(FileType[j],_T("%s"),stFileInfo.szTypeName);
ZeroMemory(string,sizeof(string));
wsprintf(FileTime[j],_T("%04d-%02d-%02d %02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute);
i++;
j++;
}
} while(FindNextFile(hFile, &wfd)) ;
num = ListView_GetItemCount(hWnd);
// RETAILMSG(1,(L"num=%d",num));
// RETAILMSG(1,(L"i=%d",i));
// RETAILMSG(1,(L"j=%d",j));
k = j;
for(j=0;j<k;j++)
{
lvi[j].iItem = num+j;
lvi[j].pszText = FileName[j];
ListView_InsertItem(hWnd,&lvi[j]);
// RETAILMSG(1,(L"i=%s",lvi[j].pszText));
ListView_SetItemText(hWnd,num+j,1,FileSize[j]);//文件大小
ListView_SetItemText(hWnd,num+j,2,FileType[j]);//文件类型
ListView_SetItemText(hWnd,num+j,3,FileTime[j]);//修改时间
Flag[num+j] = 2;
}
FindClose(hFile);
return ;
}
BOOL AddItems(HWND hwnd)
{
int i = 0;
do
{
wsprintf(Item[i],_T("%s(%s)"),szFilterShow[i],szFilterType[i]);
if(SendMessage(hwnd,CB_ADDSTRING,0,(LPARAM)Item[i]) == -1)
{
return FALSE;
}
i++;
}while(wcscmp(szFilterType[i],_T("")));
// for(int i=0;i<ItemNum;i++){
// if(SendMessage(hwnd,CB_ADDSTRING,0,(LPARAM)Addr[i]) == -1)
// return FALSE;
// }
nIndex = SendMessage(hwnd,CB_SETCURSEL,(WPARAM)0,0);
return TRUE;
}
void CreateNewFile(HWND hDlg,TCHAR NewFileName[MAX_PATH])
{
HWND hWnd;
LVITEM lvi;
// TCHAR string[MAX_PATH];
TCHAR szPathName[MAX_PATH];
// SYSTEMTIME st;
// int num;
// SHFILEINFO stFileInfo;
// HIMAGELIST ilist;
// HICON hIcon;
HANDLE hFile;
WIN32_FIND_DATA wfd;
hWnd = GetDlgItem(hDlg,IDC_LIST1);
if(!wcscmp(NewFileName,_T("")))
{
// wsprintf(szPathName,_T("%s\\%s"),m_szCurDir,TEXT("新建文件夹"));
// lvi.pszText = _T("新建文件夹");
// MessageBox(NULL,_T("不创建文件夹"),_T("目录浏览器"),MB_OK);
}
else
{
wsprintf(szPathName,_T("%s\\%s"),m_szCurDir,NewFileName);
lvi.pszText = NewFileName;
wsprintf(m_szInitDir,TEXT("%s\\*.*"),m_szCurDir);
hFile = FindFirstFile(m_szInitDir,&wfd);
CreateDirectory (szPathName,NULL);
GetSubItemList(hDlg,TEXT("*.*"));
/*
if(hFile == INVALID_HANDLE_VALUE)
{
ilist = ImageList_Create(16,16,ILC_COLOR,0,0);//创建image列表
ListView_SetImageList(hWnd,ilist, LVSIL_SMALL);
ImageList_SetImageCount(ilist,100);//设置image列表初始值
CreateDirectory (szPathName,NULL);
SHGetFileInfo(szPathName,NULL,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON|SHGFI_SMALLICON|SHGFI_TYPENAME);
hIcon = stFileInfo.hIcon;
ImageList_ReplaceIcon(ilist,0,hIcon);
}
else{
CreateDirectory (szPathName,NULL);
}
lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
lvi.state = 0;
lvi.stateMask=0;
lvi.iSubItem=0;
lvi.iImage = 0;
num = ListView_GetItemCount(hWnd);
lvi.iItem = num;
ListView_InsertItem(hWnd,&lvi);
ZeroMemory(string,sizeof(string));
wsprintf(string,_T("文件夹"));
ListView_SetItemText(hWnd,num,2,string);//文件类型
ZeroMemory(string,sizeof(string));
wsprintf(string,_T("%04d-%02d-%02d %02d:%02d"),
st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute);
ListView_SetItemText(hWnd,num,3,string);//修改时间
Flag[num] = 1;*/
}
}
void SearchFile(HWND hDlg,TCHAR SName[MAX_PATH])
{
HANDLE hFile;
WIN32_FIND_DATA wfd;
wsprintf(m_szInitDir,TEXT("%s\\*.*"),m_szCurDir);
hFile = FindFirstFile(m_szInitDir,&wfd);
if(hFile == INVALID_HANDLE_VALUE)
return;
do
{
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) &&
!(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN))
{
if( wfd.cFileName[0] != '.' )
{
if(!_wcsicmp(SName,wfd.cFileName))
{
searchFlag = 2;
wsprintf(m_szDir,m_szCurDir);
wsprintf(m_szCurDir,_T("%s\\%s"),m_szCurDir,wfd.cFileName);
GetSubItemList(hDlg,_T("*.*"));
wsprintf(m_CurDir[numb++],m_szDir);
return ;
}
}
}
else if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM))
{
if(!wcscmp(SName,wfd.cFileName))
{
searchFlag = 1;
ZeroMemory(g_szFilePath,sizeof(g_szFilePath));
wsprintf(g_szFilePath,TEXT("%s\\%s"),m_szCurDir,SName);
// OpenFile(SName);
}
}
} while(FindNextFile(hFile, &wfd)) ;
FindClose(hFile);
return ;
}
void CreateToolbar (HWND hwnd)
{
DWORD dwStyle; // Style of the toolbar
HWND hwndTB = NULL; // Handle to the command bar control
INITCOMMONCONTROLSEX iccex; // The INITCOMMONCONTROLSEX structure
iccex.dwSize = sizeof (INITCOMMONCONTROLSEX);
iccex.dwICC = ICC_BAR_CLASSES;
InitCommonControlsEx (&iccex);
// Create the toolbar control.
dwStyle = WS_VISIBLE | WS_CHILD | TBSTYLE_BUTTON |
CCS_NOPARENTALIGN ;
static TBBUTTON tbButton[]={
{0,ID_GOUP,(unsigned char)TBSTATE_ENABLED,(unsigned char)(TBSTYLE_BUTTON),0L,0},
{1,ID_NEW,(unsigned char)TBSTATE_ENABLED,(unsigned char)(TBSTYLE_BUTTON),0L,0}
};
hwndTB = CreateToolbarEx (
hwnd, // Parent window handle
dwStyle, // Toolbar window styles
(UINT) IDR_TOOLBAR1,// Toolbar control identifier
3, // Number of button images
g_hInst,//NULL, // Module instance
IDR_TOOLBAR1, // Bitmap resource identifier
tbButton, // Array of TBBUTTON structure
// contains button data
sizeof (tbButton) / sizeof (TBBUTTON),
// Number of buttons in toolbar
16, // Width of the button in pixels
15, // Height of the button in pixels
24, // Button image width in pixels
22, // Button image height in pixels
sizeof (TBBUTTON));// Size of a TBBUTTON structure
MoveWindow(hwndTB,400,10,120,15,TRUE);
ShowWindow(hwndTB,SW_SHOWNORMAL);
}
LRESULT CALLBACK NewProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWnd;
TCHAR str[MAX_PATH];
switch (message)
{
case WM_INITDIALOG:
wsprintf(str,_T("新建文件夹"));
SetWindowText(GetDlgItem(hDlg,IDC_EDIT2),str);
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_EDIT2:
break;
case IDOK:
// MessageBox(NULL,str,TEXT("hello!"),MB_OK);
ZeroMemory(str,sizeof(str));
hWnd = GetDlgItem(hDlg,IDC_EDIT2);
GetWindowText(hWnd,str,MAX_PATH);
wsprintf(m_szNewFileName,str);
EndDialog(hDlg, LOWORD(wParam));
break;
case IDCANCEL:
wsprintf(m_szNewFileName,_T(""));
EndDialog(hDlg, LOWORD(wParam));
return true;
}
}
return 0;
}
/*void OpenFile(TCHAR name[MAX_PATH])
{
SHELLEXECUTEINFO sei;
TCHAR str1[MAX_PATH]={0};
wsprintf(str1,TEXT("%s\\%s"),m_szCurDir,name);
// MessageBox(NULL,str1,TEXT("hello!"),MB_OK);
ZeroMemory(&sei, sizeof(sei));
sei.cbSize = sizeof(sei);
sei.lpVerb = _T("open");
sei.lpFile = str1;
sei.lpDirectory = NULL;
sei.nShow = SW_SHOWNORMAL;
sei.hwnd = NULL;
ShellExecuteEx(&sei);
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -