📄 winmain.cpp
字号:
} else { g_pftHead = pft; } pftLast = pft; } // Assign this image list to our tree control. ListView_SetImageList(g_hWndList, hil, LVSIL_SMALL);}//******************************************************************************//***** Our Main Window's Message Handler//******************************************************************************LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CREATE: g_hWndMain = hWnd; return OnCreate(); case WM_ERASEBKGND: DrawBanner((HDC)wParam); return 0; case WM_SIZE: // Resize our list view control to match our client area. MoveWindow(g_hWndList, 0, g_cyCmdBar + 22, LOWORD(lParam), HIWORD(lParam) - (g_cyCmdBar + 22), TRUE);#ifndef _WIN32_WCE // On NT we have to resize our toolbar as well. MoveWindow(g_hWndCmdBar, 0, 0, LOWORD(lParam), g_cyCmdBar, TRUE);#endif return 0; case WM_SETFOCUS: // Always direct focus to our list control. SetFocus(g_hWndList); return 0; case WM_DESTROY: PostQuitMessage(0); return 0; case WM_HELP: OnHelp(); return 0; case WM_PRIVATE: switch (wParam) {#ifdef _WIN32_WCE case MSG_SUBCLASS_DIALOG: SubclassSaveAsDlg(); return 0;#endif case MSG_ADD_TEXT_TO_EDIT: AddTextToEdit((LPCSTR)lParam); return 0; case MSG_PROMPT_TO_REPLACE: return PromptToReplace((LPCSTR)lParam);#if CRYPT case MSG_PROMPT_FOR_PASSWORD: return DialogBoxParam(g_hInst, MAKEINTRESOURCE(IDD_PASSWORD), g_hDlgProgress, (DLGPROC)DlgProcPassword, lParam);#endif case MSG_UPDATE_PROGRESS_PARTIAL: UpdateProgress((EXTRACT_INFO*)lParam, FALSE); return 0; case MSG_UPDATE_PROGRESS_COMPLETE: UpdateProgress((EXTRACT_INFO*)lParam, TRUE); return 0; } return 0; case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case LVN_GETDISPINFO: OnGetDispInfo((LV_DISPINFO*)lParam); return 0; case LVN_DELETEITEM: OnDeleteItem((NM_LISTVIEW*)lParam); return 0; case LVN_COLUMNCLICK: Sort(((NM_LISTVIEW*)lParam)->iSubItem, FALSE); return 0; case LVN_ITEMCHANGED: OnItemChanged((NM_LISTVIEW*)lParam); return 0; case NM_DBLCLK: case NM_RETURN: OnActionView(); return 0; } return 0; case WM_COMMAND: switch (LOWORD(wParam)) { case IDM_FILE_OPEN: OnFileOpen(); return 0; case IDM_FILE_PROPERTIES: DialogBox(g_hInst, MAKEINTRESOURCE(IDD_PROPERTIES), hWnd, (DLGPROC)DlgProcProperties); return 0; case IDM_FILE_CLOSE: SendMessage(hWnd, WM_CLOSE, 0, 0); return 0; case IDM_ACTION_EXTRACT_ALL: OnActionSelectAll(); // Fall through to IDM_ACTION_EXTRACT case IDM_ACTION_EXTRACT: ExtractOrTestFiles(TRUE); return 0; case IDM_ACTION_TEST_ALL: OnActionSelectAll(); // Fall through to IDM_ACTION_TEST case IDM_ACTION_TEST: ExtractOrTestFiles(FALSE); return 0; case IDM_ACTION_VIEW: OnActionView(); return 0; case IDM_ACTION_SELECT_ALL: OnActionSelectAll(); return 0; case IDM_VIEW_EXPANDED_VIEW: OnViewExpandedView(); return 0; case IDM_VIEW_COMMENT: DialogBox(g_hInst, MAKEINTRESOURCE(IDD_COMMENT), hWnd, (DLGPROC)DlgProcComment); return 0; case IDM_HELP_ABOUT: DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ABOUT), hWnd, (DLGPROC)DlgProcAbout); return 0; case IDHELP: return SendMessage(hWnd, WM_HELP, 0, 0); default: // Check to see if a MRU file was selected. if ((LOWORD(wParam) >= MRU_START_ID) && (LOWORD(wParam) < (MRU_START_ID + MRU_MAX_FILE))) { ActivateMRU(LOWORD(wParam)); } } } return DefWindowProc(hWnd, uMsg, wParam, lParam);}//******************************************************************************//***** Event Handlers for our Main Window//******************************************************************************int OnCreate() { // Our toolbar buttons. static TBBUTTON tbButton[] = { { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 0, IDM_FILE_OPEN, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 1, IDM_FILE_PROPERTIES, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 2, IDM_ACTION_EXTRACT, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 3, IDM_ACTION_EXTRACT_ALL, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 4, IDM_ACTION_TEST, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 5, IDM_ACTION_TEST_ALL, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 6, IDM_ACTION_VIEW, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 0, 0, 0, TBSTYLE_SEP, 0, 0, 0, -1 }, { 7, IDM_VIEW_EXPANDED_VIEW, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 }, { 8, IDM_VIEW_COMMENT, 0, TBSTYLE_BUTTON, 0, 0, 0, -1 } }; // Our toolbar buttons' tool tip text. static LPTSTR szToolTips[] = { TEXT(""), // Menu TEXT("Open (Ctrl+O)"), TEXT("Properties (Alt+Enter)"), TEXT("Extract Selected Files"), TEXT("Extract All Files"), TEXT("Test Selected Files"), TEXT("Test All Files"), TEXT("View Selected File"), TEXT("Expanded View"), TEXT("View Zip File Comment") }; // Initialize the common controls. InitCommonControls(); // Check to see if we have a help file. BOOL fHelp = (GetFileAttributes(g_szHelpFile) != 0xFFFFFFFF); // Set our window's icon so it can update the task bar. if (g_hIconMain) { SendMessage(g_hWndMain, WM_SETICON, FALSE, (LPARAM)g_hIconMain); } // Create the tree control. Our main window will resize it to fit. g_hWndList = CreateWindow(WC_LISTVIEW, TEXT(""), WS_VSCROLL | WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SHOWSELALWAYS, 0, 0, 0, 0, g_hWndMain, NULL, g_hInst, NULL);#ifdef _WIN32_WCE // Create a command bar and add the toolbar bitmaps to it. g_hWndCmdBar = CommandBar_Create(g_hInst, g_hWndMain, 1); CommandBar_AddBitmap(g_hWndCmdBar, g_hInst, IDB_TOOLBAR, 9, 16, 16); CommandBar_InsertMenubar(g_hWndCmdBar, g_hInst, IDR_UNZIP, 0); CommandBar_AddButtons(g_hWndCmdBar, countof(tbButton), tbButton); CommandBar_AddAdornments(g_hWndCmdBar, fHelp ? CMDBAR_HELP : 0, 0); // Add tool tips to the tool bar. CommandBar_AddToolTips(g_hWndCmdBar, countof(szToolTips), szToolTips); // Store the height of the command bar for later calculations. g_cyCmdBar = CommandBar_Height(g_hWndCmdBar); // We set our wait window handle to our menu window within our command bar. // This is the last window that will be painted during startup of our app. g_hWndWaitFor = GetWindow(g_hWndCmdBar, GW_CHILD); // Add the help item to our help menu if we have a help file. if (fHelp) { HMENU hMenu = GetSubMenu(CommandBar_GetMenu(g_hWndCmdBar, 0), 3); InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED, IDHELP, TEXT("&Help")); }#else // Create a tool bar and add the toolbar bitmaps to it. g_hWndCmdBar = CreateToolbarEx(g_hWndMain, WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS, 1, 9, g_hInst, IDB_TOOLBAR, tbButton, countof(tbButton), 16, 16, 16, 16, sizeof(TBBUTTON)); // Get our tool tip control. HWND hWndTT = (HWND)SendMessage(g_hWndCmdBar, TB_GETTOOLTIPS, 0, 0); // Set our tool tip strings. TOOLINFO ti; ti.cbSize = sizeof(ti); int tip = 0, button; while (SendMessage(hWndTT, TTM_ENUMTOOLS, tip++, (LPARAM)&ti)) { for (button = 0; button < countof(tbButton); button++) { if (tbButton[button].idCommand == (int)ti.uId) { ti.lpszText = szToolTips[tbButton[button].iBitmap + 1]; SendMessage(hWndTT, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); break; } } } // Store the height of the tool bar for later calculations. RECT rc; GetWindowRect(g_hWndCmdBar, &rc); g_cyCmdBar = rc.bottom - rc.top; // We set our wait window handle to our toolbar. // This is the last window that will be painted during the startup of our app. g_hWndWaitFor = g_hWndCmdBar; // Add the help item to our help menu if we have a help file. if (fHelp) { HMENU hMenu = GetSubMenu(GetMenu(g_hWndMain), 3); InsertMenu(hMenu, 0, MF_BYPOSITION | MF_SEPARATOR, 0, NULL); InsertMenu(hMenu, 0, MF_BYPOSITION | MF_ENABLED, IDHELP, TEXT("&Help\tF1")); }#endif // _WIN32_WCE // Enable Full Row Select - This feature is supported on Windows CE and was // introduced to Win95/NT with IE 3.0. If the user does not have a // COMCTL32.DLL that supports this feature, then they will just see the // old standard First Column Select. SendMessage(g_hWndList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | SendMessage(g_hWndList, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)); // Get our expanded view option from the registry. g_fExpandedView = GetOptionInt(TEXT("ExpandedView"), FALSE); // Show or remove menu check for expanded view option. CheckAllMenuItems(IDM_VIEW_EXPANDED_VIEW, g_fExpandedView); // Create our columns. AddDeleteColumns(); // Set our current sort column to our name column Sort(0, TRUE); return 0;}//******************************************************************************void OnFileOpen() { TCHAR szPath[_MAX_PATH] = TEXT(""); OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = g_hWndMain; ofn.hInstance = g_hInst; ofn.lpstrFilter = TEXT("ZIP files (*.zip)\0*.zip\0SFX files (*.exe)\0*.exe\0All Files (*.*)\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrFile = szPath; ofn.nMaxFile = countof(szPath); ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST; ofn.lpstrDefExt = TEXT("zip"); if (GetOpenFileName(&ofn)) { ReadZipFileList(szPath); }}//******************************************************************************void OnActionView() { // We only allow a view if one item is selected. int count = ListView_GetSelectedCount(g_hWndList); if (count != 1) { return; } // Query the selected item for its FILE_NODE. LV_ITEM lvi; ZeroMemory(&lvi, sizeof(lvi)); lvi.mask = LVIF_IMAGE | LVIF_PARAM; lvi.iItem = ListView_GetNextItem(g_hWndList, -1, LVNI_SELECTED); ListView_GetItem(g_hWndList, &lvi); FILE_NODE *pfn = (FILE_NODE*)lvi.lParam; // Bail out if the selected item is a folder or volume label. if (pfn->dwAttributes & (FILE_ATTRIBUTE_DIRECTORY | ZFILE_ATTRIBUTE_VOLUME)) { MessageBox(g_hWndMain, TEXT("You cannot view folders or volume labels."), g_szAppName, MB_ICONINFORMATION | MB_OK); return; } // Make sure our temporary directory exists. CreateDirectory(g_szTempDir, NULL);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -