📄 cezip.cpp
字号:
// CeZip.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "CeZip.h"
#include <commctrl.h>
#include "Commdlg.h"
#include "compress.h"
#include "divide.h"
#include "string"
using namespace std;
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // The current instance
HWND hwndCB; // The command bar handle
HWND g_listWnd; // The list view handle
OPENFILENAME g_ofn; // The open file dialog
TCHAR lpstrFileName[200]; //The full path of the file
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass (HINSTANCE, LPTSTR);
BOOL InitInstance (HINSTANCE, int);
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK About (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK control (HWND, UINT, WPARAM, LPARAM);
BOOL InitListView(HWND, RECT); //initialize the list view
void InitOpenDlg(); //initialize the file open and save dialog
void OpenFile(); //get the open file name and put it into the list view
BOOL InsertIterm();
void SelectFile_1(char name[][50],char * filepath);
void DeleteItem();
long i;
int tem;
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HACCEL hAccelTable;
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_CEZIP);
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// It is important to call this function so that the application
// will get 'well formed' small icons associated with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CEZIP));
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The window class name
hInst = hInstance; // Store instance handle in our global variable
// Initialize global strings
LoadString(hInstance, IDC_CEZIP, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance, szWindowClass);
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
RECT rcClient;
GetClientRect(hWnd, &rcClient);
//create the list window
g_listWnd = CreateWindow(WC_LISTVIEW, NULL,
WS_CHILD | WS_VISIBLE | LVS_REPORT ,
rcClient.left, rcClient.top + 25, rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
hWnd, NULL, hInst,NULL);
//set the list view in full row select mode
ListView_SetExtendedListViewStyle(g_listWnd,
ListView_GetExtendedListViewStyle(g_listWnd) | LVS_EX_FULLROWSELECT);
if(!InitListView(g_listWnd, rcClient))
{
return(-1);
}
// ::SetWindowText(g_listWnd,TEXT("CeZip"));
ShowWindow(g_listWnd, nCmdShow);
UpdateWindow(g_listWnd);
if (hwndCB)
CommandBar_Show(hwndCB, TRUE);
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
int wmId, wmEvent;
PAINTSTRUCT ps;
TCHAR szHello[MAX_LOADSTRING];
char name[100][50];
static char filePath[100];
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_HELP_ABOUT:
DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
break;
case IDM_OPEN_FILE: //select the files
OpenFile();
break;
case IDM_DELETE_FILE: //
DeleteItem();
break;
case IDM_COMPRESS: //compress the files selected
int itemCount;
itemCount = ListView_GetItemCount(g_listWnd);
if( itemCount == 0 )
{
MessageBox(hWnd,TEXT("You should at least select one file!"),TEXT("Warning"),MB_OK);
break;
}
g_ofn.lpstrTitle = TEXT("Save File");
g_ofn.lpstrFilter=TEXT("ce zip file(*.czf)\0 *.czf\0");
g_ofn.Flags=OFN_CREATEPROMPT|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT;
memset(lpstrFileName,0,sizeof(lpstrFileName));
if(GetSaveFileName(&g_ofn))
{
TCHAR szBuf[100];
char path[100][100];
char savePath[100];
WideCharToMultiByte(CP_ACP,NULL,lpstrFileName,-1,savePath,sizeof(savePath),NULL,NULL);
//get the number of the item in the list window
int index;
for(index = 0;index < itemCount;index++)
{
memset(szBuf,0,sizeof(szBuf));
ListView_GetItemText(g_listWnd,index,0,szBuf,sizeof(szBuf));
WideCharToMultiByte(CP_ACP,NULL,szBuf,-1,name[index],sizeof(name[index]),NULL,NULL);
memset(szBuf,0,sizeof(szBuf));
ListView_GetItemText(g_listWnd,index,3,szBuf,sizeof(szBuf));
WideCharToMultiByte(CP_ACP,NULL,szBuf,-1,path[index],sizeof(name[index]),NULL,NULL);
}
int res;
if(MessageBox(hWnd,TEXT("Do you want to create the automatic decompress file?"),TEXT("Message"),MB_YESNO) == IDYES)
res = comain2(name,path,itemCount,savePath);
else
res = comain(name,path,itemCount,savePath);
if( res == 0 )
{
MessageBox(hWnd,TEXT("Compress the files successfully!"),TEXT("Message"),MB_OK);
ListView_DeleteAllItems(g_listWnd);
}
}
break;
case IDM_SELECT_FILE_1:
SelectFile_1(name,filePath);
break;
case IDM_DECOMPRESS:
int iCount;
iCount = ListView_GetItemCount(g_listWnd);
if( iCount == 0 )
{
MessageBox(hWnd,TEXT("You should at least select one file!"),TEXT("Warning"),MB_OK);
break;
}
if(!umain(filePath))
{
MessageBox(hWnd,TEXT("Decompress the file successfully!"),TEXT("Message"),MB_OK);
ListView_DeleteAllItems(g_listWnd);
}
break;
/////////////////////////////////////////
case IDM_SELECT_FILE_2:
g_ofn.lpstrFilter=TEXT("All files(*.*)\0 *.*");
g_ofn.lpstrTitle = TEXT("Select File");
memset(lpstrFileName,0,sizeof(lpstrFileName));
//get the file's full path
if(GetOpenFileName(&g_ofn))
{
ListView_DeleteAllItems(g_listWnd);
InsertIterm();
}
break;
case IDM_DIVIDE:
TCHAR buf[100];
char fullpath[100];
ListView_GetItemText(g_listWnd,0,3,buf,sizeof(buf));
WideCharToMultiByte(CP_ACP,NULL,buf,-1,fullpath,sizeof(fullpath),NULL,NULL);
FILE *check;
if(check = fopen(fullpath,"rb"))//文件存在
{
fclose(check);
DialogBox(hInst, (LPCTSTR)IDD_choose, hWnd, (DLGPROC)control);//进入对话框
//根据返回的要求切割文件
if(tem == 1)
scale(fullpath,i,hWnd);
if(tem == 2)
num(fullpath,i,hWnd);
ListView_DeleteAllItems(g_listWnd);
}
else
{
::MessageBox(hWnd,L"Please choose a file!",L"divide error",MB_OK);
}
break;
case IDM_SELECT_FILE_3:
g_ofn.lpstrFilter=TEXT("Divided files(*.lqh)\0 *.lqh");
g_ofn.lpstrTitle = TEXT("Select File");
memset(lpstrFileName,0,sizeof(lpstrFileName));
//get the file's full path
if(GetOpenFileName(&g_ofn))
{
ListView_DeleteAllItems(g_listWnd);
InsertIterm();
}
break;
case IDM_COMBINE:
//合并的入口
TCHAR buf2[100];
char fullpath2[100];
ListView_GetItemText(g_listWnd,0,3,buf2,sizeof(buf2));
WideCharToMultiByte(CP_ACP,NULL,buf2,-1,fullpath2,sizeof(fullpath2),NULL,NULL);
FILE *check2;
if(check2 = fopen(fullpath2,"rb"))//打开文件成功
{
bool lqh = 0;
int len;
len = strlen(fullpath2);
if((fullpath2[len - 1] == 'h') && (fullpath2[len - 2] == 'q') && (fullpath2[len - 3] == 'l'))
lqh = 1;//如果后缀名正确,合并
fclose(check2);
if(lqh == 1)
combine(fullpath2,hWnd);
else
{
::MessageBox(hWnd,L"wrong file",L"combine error",MB_OK);
}
ListView_DeleteAllItems(g_listWnd);
}
else
{
::MessageBox(hWnd,L"Please choose a file",L"combine error",1);
}
break;
case IDM_FILE_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_CREATE:
hwndCB = CommandBar_Create(hInst, hWnd, 1);
CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -