📄 cezip.cpp
字号:
CommandBar_AddAdornments(hwndCB, 0, 0);
InitOpenDlg();
break;
case WM_PAINT:
RECT rt;
hdc = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rt);
LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
DrawText(hdc, szHello, _tcslen(szHello), &rt,
DT_SINGLELINE | DT_VCENTER | DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
CommandBar_Destroy(hwndCB);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Mesage handler for the About box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;
// if the About box is larger than the physical screen
if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
return TRUE;
case WM_COMMAND:
if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
LRESULT CALLBACK control(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
RECT rt, rt1;
int DlgWidth, DlgHeight; // dialog width and height in pixel units
int NewPosX, NewPosY;
switch (message)
{
case WM_INITDIALOG:
// trying to center the About dialog
if (GetWindowRect(hDlg, &rt1)) {
CheckRadioButton(hDlg,IDC_scale,IDC_number,IDC_scale);
tem = 1;
GetClientRect(GetParent(hDlg), &rt);
DlgWidth = rt1.right - rt1.left;
DlgHeight = rt1.bottom - rt1.top ;
NewPosX = (rt.right - rt.left - DlgWidth)/2;
NewPosY = (rt.bottom - rt.top - DlgHeight)/2;
// if the About box is larger than the physical screen
if (NewPosX < 0) NewPosX = 0;
if (NewPosY < 0) NewPosY = 0;
SetWindowPos(hDlg, 0, NewPosX, NewPosY,
0, 0, SWP_NOZORDER | SWP_NOSIZE);
}
return TRUE;
case WM_COMMAND:
if(LOWORD(wParam) == IDC_scale)
tem = 1;//scale
if(LOWORD(wParam) == IDC_number)
tem = 2;//number
if(LOWORD(wParam) == IDOK)
{
i = ::GetDlgItemInt(hDlg,IDC_size,NULL,true);
if(i <= 0)
{
MessageBox(hDlg,L"Wrong enter",L"Warning",MB_OK);
break;
}
TCHAR xxx[100];
ListView_GetItemText(g_listWnd,0,1,xxx,sizeof(xxx));
char size[100];
WideCharToMultiByte(CP_ACP,NULL,xxx,-1,size,sizeof(size),NULL,NULL);
long lsize = atol(size);
if((tem == 2) && (i > 999))
::MessageBox(hDlg,L"Wrong enter,number should less than 999",L"Warning",MB_OK);
else if((tem == 1) && ((lsize / i) + 1) > 20)
if(IDYES == MessageBox(hDlg,L"Subfiles will more than 20,do you want to countinue?",L"Waring",MB_YESNO))
EndDialog(hDlg, LOWORD(wParam));
else
break;
else
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
if(LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
//initialize the list view window
BOOL InitListView(HWND hwndListView, RECT rcClient)
{
int iWidth[4] = { 150,100,150,250 }; //column width
TCHAR szString[4][15] = //column name
{
TEXT("File Name"),
TEXT("Size"),
TEXT("Modify Time"),
TEXT("Path")
};
int iColumn;
// Create the columns.
ListView_DeleteAllItems(hwndListView);
LV_COLUMN lvColumn;
lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
lvColumn.fmt = LVCFMT_LEFT;
for(iColumn = 0; iColumn < 4; iColumn++)
{
lvColumn.cx = iWidth[iColumn];
lvColumn.pszText = szString[iColumn];
if(-1 == ListView_InsertColumn(hwndListView, iColumn, &lvColumn))
{
return false;
}
}
ListView_SetTextBkColor(hwndListView,RGB(16,165,53));
ListView_SetBkColor(hwndListView,RGB(242,141,87));
return true;
}
//initialize the file open and save dialog
void InitOpenDlg()
{
memset(&g_ofn,0x00,sizeof(g_ofn));
g_ofn.Flags=OFN_CREATEPROMPT|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
// g_ofn.hInstance=hInst;
g_ofn.hwndOwner=g_listWnd;
// g_ofn.lCustData=0;
// g_ofn.lpfnHook=NULL;
// g_ofn.lpstrCustomFilter=NULL;
g_ofn.lpstrDefExt=TEXT("czf");
g_ofn.lpstrFile=lpstrFileName;
g_ofn.lpstrFileTitle=NULL;
g_ofn.lpstrFilter=TEXT("ce zip file(*.czf)\0 *.czf\0 All files(*.*)\0 *.*"); //过滤器
g_ofn.lpstrInitialDir=NULL;//"c:\\"; //默认路径
g_ofn.lpstrTitle=NULL;
// g_ofn.lpTemplateName=NULL;
g_ofn.lStructSize=sizeof(g_ofn);
g_ofn.nFileExtension=0;
g_ofn.nFileOffset=0;
g_ofn.nFilterIndex=1;
// g_ofn.nMaxCustFilter=2;
g_ofn.nMaxFile=sizeof(lpstrFileName);
g_ofn.nMaxFileTitle=0;
}
void OpenFile()
{
g_ofn.Flags=OFN_CREATEPROMPT|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
g_ofn.lpstrFilter=TEXT("All files(*.*)\0 *.*");
g_ofn.lpstrTitle = TEXT("Add File");
memset(lpstrFileName,0,sizeof(lpstrFileName));
//get the file's full path
if(GetOpenFileName(&g_ofn))
InsertIterm();
}
BOOL InsertIterm()
{
HANDLE hFind; // Search handle returned by FindFirstFile
WIN32_FIND_DATA FileData; // Data structure describes the file found
int itemCount;
TCHAR szBuf[50];
itemCount = ListView_GetItemCount(g_listWnd); //get the number of the item in the list window
//find whether the file has been selected or not
for(int index = 0;index < itemCount;index++)
{
memset(szBuf,0,sizeof(szBuf));
ListView_GetItemText(g_listWnd,index,3,szBuf,sizeof(szBuf));
if(!lstrcmp(szBuf,lpstrFileName))
{
MessageBox(g_listWnd,TEXT("This file has already been selected!"),TEXT("Warning"),MB_OK);
return false;
}
}
//get the attributes of the file and insert it into the list window
if((hFind = FindFirstFile(lpstrFileName,&FileData)) != INVALID_HANDLE_VALUE)
{
LV_ITEM lvItem;
int nItem;
DWORD fileSize;
SYSTEMTIME lastWriteTime;
FILETIME fileTime;
//get the size of the file
fileSize = ((FileData.nFileSizeHigh * MAXDWORD) + FileData.nFileSizeLow);
//convert the file time to the system time
FileTimeToLocalFileTime(&FileData.ftLastWriteTime,&fileTime);
FileTimeToSystemTime(&fileTime, &lastWriteTime);
memset(&lvItem, 0, sizeof(LVITEM));
lvItem.mask = LVIF_TEXT;
lvItem.state = LVIS_SELECTED;
lvItem.stateMask = 0;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = FileData.cFileName;
nItem = ListView_InsertItem(g_listWnd, &lvItem);
//insert the size of the file into the list window
wsprintf(szBuf, TEXT("%ld"),fileSize);
lstrcat(szBuf,TEXT(" bytes"));
ListView_SetItemText(g_listWnd, nItem, 1, szBuf);
//insert the time of the file into the list window
wsprintf(szBuf,TEXT("%0.2d/%d/%0.2d(%d:%0.2d)"),
lastWriteTime.wYear, lastWriteTime.wMonth, lastWriteTime.wDay,
lastWriteTime.wHour, lastWriteTime.wMinute, lastWriteTime.wSecond);
ListView_SetItemText(g_listWnd, nItem, 2, szBuf);
//insert the full path of the file into the list window
ListView_SetItemText(g_listWnd, nItem, 3, lpstrFileName);
// Close the search handle.
if(!::FindClose(hFind))
return false;
return true;
}
return false;
}
//select the file to be decompressed
void SelectFile_1(char name[][50],char * filepath)
{
g_ofn.Flags=OFN_CREATEPROMPT|OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY;
g_ofn.lpstrFilter=TEXT("ce zip file(*.czf)\0 *.czf\0");
g_ofn.lpstrTitle = TEXT("Select File");
memset(lpstrFileName,0,sizeof(lpstrFileName));
if(GetOpenFileName(&g_ofn))
{
long length[100];
int count;
int iNum;
TCHAR WideName[100];
char tmppath[100];
LV_ITEM lvItem;
int nItem;
TCHAR szBuf[100];
WideCharToMultiByte(CP_ACP,NULL,lpstrFileName,-1,tmppath,sizeof(tmppath),NULL,NULL);
memset(filepath,0,sizeof(filepath));
strcpy(filepath,tmppath);
memset(length,0,sizeof(long)*100);
iNum = CPList(tmppath,name,length);
ListView_DeleteAllItems(g_listWnd);
for( count = 0;count < iNum;count++ )
{
memset(WideName,0,sizeof(WideName));
MultiByteToWideChar(CP_ACP,NULL,name[count],-1,WideName,sizeof(WideName));
memset(&lvItem, 0, sizeof(LVITEM));
lvItem.mask = LVIF_TEXT;
lvItem.state = LVIS_SELECTED;
lvItem.stateMask = 0;
lvItem.iItem = 0;
lvItem.iSubItem = 0;
lvItem.pszText = WideName;
nItem = ListView_InsertItem(g_listWnd, &lvItem);
//insert the size of the file into the list window
wsprintf(szBuf, TEXT("%ld"),length[count]);
lstrcat(szBuf,TEXT(" bytes"));
ListView_SetItemText(g_listWnd, nItem, 1, szBuf);
}
}
}
void DeleteItem()
{
int iSelected;
iSelected = ListView_GetSelectionMark(g_listWnd);
if( iSelected < 0 )
MessageBox(NULL,TEXT("Please select the file to delete first!"),TEXT("Warning"),MB_OK);
else
ListView_DeleteItem(g_listWnd,iSelected);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -