⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winmain.cpp

📁 完整的解压zip文件的源码。包含密码功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//******************************************************************************//// File:        WINMAIN.CPP//// Description: This module contains all the Windows specific code for Pocket//              UnZip.  It contains the entire user interface.  This code knows//              almost nothing about the Info-ZIP code.  All Info-ZIP related//              functions are wrapped by helper functions in INTRFACE.CPP.  The//              code in this module only calls those wrapper functions and//              INTRFACE.CPP handles all the details and callbacks of the //              Info-ZIP code.//// Copyright:   All the source files for Pocket UnZip, except for components//              written by the Info-ZIP group, are copyrighted 1997 by Steve P.//              Miller.  The product "Pocket UnZip" itself is property of the//              author and cannot be altered in any way without written consent//              from Steve P. Miller.//// Disclaimer:  All project files are provided "as is" with no guarantee of//              their correctness.  The authors are not liable for any outcome//              that is the result of using this source.  The source for Pocket//              UnZip has been placed in the public domain to help provide an//              understanding of its implementation.  You are hereby granted//              full permission to use this source in any way you wish, except//              to alter Pocket UnZip itself.  For comments, suggestions, and//              bug reports, please write to stevemil@pobox.com.//// Functions:   WinMain//              InitializeApplication//              ShutdownApplication//              RegisterUnzip//              BuildImageList//              WndProc//              OnCreate//              OnFileOpen//              OnActionView//              OnActionSelectAll//              OnViewExpandedView//              OnHelp//              OnGetDispInfo//              OnDeleteItem//              OnItemChanged//              Sort//              CompareFunc//              SetCaptionText//              DrawBanner//              AddDeleteColumns//              ResizeColumns//              GetZipErrorString//              AddFileToListView//              EnableAllMenuItems//              CheckAllMenuItems//              CenterWindow//              AddTextToEdit//              FormatValue//              BuildAttributesString//              BuildTypeString//              GetFileFromPath//              ForwardSlashesToBackSlashesA//              ForwardSlashesToBackSlashesW//              DeleteDirectory(LPTSTR szPath);//              RegWriteKey//              RegReadKey//              WriteOptionString//              WriteOptionInt//              GetOptionString//              GetOptionInt//              DisableEditing//              EditSubclassProc//              GetMenuString//              InitializeMRU//              AddFileToMRU//              RemoveFileFromMRU//              ActivateMRU//              ReadZipFileList//              DlgProcProperties//              MergeValues//              CheckThreeStateBox//              ExtractOrTestFiles//              DlgProcExtractOrTest//              FolderBrowser//              DlgProcBrowser//              SubclassSaveAsDlg//              DlgProcExtractProgress//              DlgProcViewProgress//              UpdateProgress//              PromptToReplace//              DlgProcReplace//              DlgProcPassword//              DlgProcViewAssociation//              DlgProcComment//              DlgProcAbout////// Date      Name          History// --------  ------------  -----------------------------------------------------// 02/01/97  Steve Miller  Created (Version 1.0 using Info-ZIP UnZip 5.30)////******************************************************************************extern "C" {#define __WINMAIN_CPP__#define UNZIP_INTERNAL#include "unzip.h"#include "version.h"   // Only needed by consts.h (VERSION_DATE & VersionDate)#include "consts.h"    // Only include once - defines constant string messages.#include "crypt.h"     // Needed to pick up CRYPT define if set and return values.#include <commctrl.h>  // Common controls - mainly ListView and ImageList#include <commdlg.h>   // Common dialogs - OpenFile dialog#ifndef _WIN32_WCE#include <shlobj.h>    // On NT, we use the SHBrowseForFolder() stuff.#include <shellapi.h>  // CommandLineToArgvW() and ExtractIconEx()#endif#include "intrface.h"  // Interface between Info-ZIP and us#include "winmain.h"   // Us}#include <tchar.h>     // Must be outside of extern "C" block//******************************************************************************//***** "Local" Global Variables//******************************************************************************static LPCTSTR         g_szAppName     = TEXT("Pocket UnZip");static LPCTSTR         g_szClass       = TEXT("PocketUnZip");static LPCTSTR         g_szRegKey      = TEXT("Software\\Pocket UnZip");static LPCTSTR         g_szTempDir     = NULL;static HWND            g_hWndList      = NULL;static HWND            g_hWndCmdBar    = NULL;static int             g_cyCmdBar      = 0;static HFONT           g_hFontBanner   = NULL;static HICON           g_hIconMain     = NULL;static WNDPROC         g_wpSaveAsDlg   = NULL;static WNDPROC         g_wpEdit        = NULL;static int             g_sortColumn    = -1;static BOOL            g_fExpandedView = FALSE;static BOOL            g_fLoading      = FALSE;static BOOL            g_fSkipped      = FALSE;static BOOL            g_fViewing      = FALSE;static HWND            g_hWndWaitFor   = NULL;static FILE_TYPE_NODE *g_pftHead       = NULL;#ifdef _WIN32_WCEstatic LPCTSTR         g_szHelpFile    = TEXT("\\windows\\punzip.htp");#elsestatic LPCTSTR         g_szHelpFile    = TEXT("punzip.html");#endifstatic COLUMN g_columns[] = {   { TEXT("Name"),       LVCFMT_LEFT  },   { TEXT("Size"),       LVCFMT_RIGHT },   { TEXT("Type"),       LVCFMT_LEFT  },   { TEXT("Modified"),   LVCFMT_LEFT  },   { TEXT("Attributes"), LVCFMT_LEFT  },   { TEXT("Compressed"), LVCFMT_RIGHT },   { TEXT("Ratio"),      LVCFMT_RIGHT },   { TEXT("Method"),     LVCFMT_LEFT  },   { TEXT("CRC"),        LVCFMT_LEFT  },   { TEXT("Comment"),    LVCFMT_LEFT  }};//******************************************************************************//***** Local Function Prototypes//******************************************************************************// Startup and Shutdown Functionsvoid InitializeApplication(LPCTSTR szZipFile);void ShutdownApplication();void RegisterUnzip();void BuildImageList();// Our Main Window's Message HandlerLRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);// Event Handlers for our Main Windowint OnCreate();void OnFileOpen();void OnActionView();void OnActionSelectAll();void OnViewExpandedView();void OnHelp();// Event Handlers for our List Viewvoid OnGetDispInfo(LV_DISPINFO *plvdi);void OnDeleteItem(NM_LISTVIEW *pnmlv);void OnItemChanged(NM_LISTVIEW *pnmlv);// List View Sort Functionsvoid Sort(int sortColumn, BOOL fForce);int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM sortColumn);// Helper/Utility Functionsvoid SetCaptionText(LPCTSTR szPrefix);void DrawBanner(HDC hdc);void AddDeleteColumns();void ResizeColumns();LPCTSTR GetZipErrorString(int error);void AddFileToListView(FILE_NODE *pFile);void EnableAllMenuItems(UINT uMenuItem, BOOL fEnabled);void CheckAllMenuItems(UINT uMenuItem, BOOL fChecked);void CenterWindow(HWND hWnd);void AddTextToEdit(LPCSTR szText);LPTSTR FormatValue(LPTSTR szValue, DWORD dwValue);LPTSTR BuildAttributesString(LPTSTR szBuffer, DWORD dwAttributes);LPCSTR BuildTypeString(FILE_NODE *pFile, LPSTR szType);LPCSTR GetFileFromPath(LPCSTR szPath);void ForwardSlashesToBackSlashesA(LPSTR szBuffer);void ForwardSlashesToBackSlashesW(LPWSTR szBuffer);void DeleteDirectory(LPTSTR szPath);// Registry Functionsvoid RegWriteKey(HKEY hKeyRoot, LPCTSTR szSubKey, LPCTSTR szValue);BOOL RegReadKey(HKEY hKeyRoot, LPCTSTR szSubKey, LPTSTR szValue, DWORD cBytes);void WriteOptionString(LPCTSTR szOption, LPCTSTR szValue);void WriteOptionInt(LPCTSTR szOption, DWORD dwValue);LPTSTR GetOptionString(LPCTSTR szOption, LPCTSTR szDefault, LPTSTR szValue, DWORD nSize);DWORD GetOptionInt(LPCTSTR szOption, DWORD dwDefault);// EDIT Control Subclass Functionsvoid DisableEditing(HWND hWndEdit);LRESULT CALLBACK EditSubclassProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);// MRU Functionsvoid InitializeMRU();void AddFileToMRU(LPCSTR szFile);void RemoveFileFromMRU(LPCTSTR szFile);void ActivateMRU(UINT uIDItem);// Open Zip File Functionsvoid ReadZipFileList(LPCWSTR wszPath);// Zip File Properties Dialog FunctionsBOOL CALLBACK DlgProcProperties(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);void MergeValues(int *p1, int p2);void CheckThreeStateBox(HWND hDlg, int nIDButton, int state);// Extract/Test Dialog Functionsvoid ExtractOrTestFiles(BOOL fExtract);BOOL CALLBACK DlgProcExtractOrTest(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);// Folder Browsing Dialog FunctionsBOOL FolderBrowser(LPTSTR szPath, DWORD dwLength);BOOL CALLBACK DlgProcBrowser(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);void SubclassSaveAsDlg();// Extraction/Test/View Progress Dialog FunctionsBOOL CALLBACK DlgProcExtractProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);BOOL CALLBACK DlgProcViewProgress(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);void UpdateProgress(EXTRACT_INFO *pei, BOOL fFull);// Replace File Dialog Functionsint PromptToReplace(LPCSTR szPath);BOOL CALLBACK DlgProcReplace(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);// Password Dialog FunctionsBOOL CALLBACK DlgProcPassword(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);// View Association Dialog FunctionsBOOL CALLBACK DlgProcViewAssociation(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);// Comment Dialog FunctionsBOOL CALLBACK DlgProcComment(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);// About Dialog FunctionsBOOL CALLBACK DlgProcAbout(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);//******************************************************************************//***** WinMain - Our one and only entry point//******************************************************************************// Entrypoint is a tiny bit different on Windows CE - UNICODE command line.#ifdef _WIN32_WCEextern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                               LPTSTR lpCmdLine, int nCmdShow)#elseextern "C" int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                              LPSTR lpCmdLine, int nCmdShow)#endif{   // Wrap the whole ball of wax in a big exception handler.   __try {      // Store global instance handle.      g_hInst = hInstance;      // Create our banner font.  We need to do this before creating our window.      // This font handle will be deleted in ShutdownApplication().      LOGFONT lf;      ZeroMemory(&lf, sizeof(lf));      lf.lfHeight = 16;      lf.lfWeight = FW_BOLD;      lf.lfCharSet = ANSI_CHARSET;      lf.lfOutPrecision = OUT_DEFAULT_PRECIS;      lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;      lf.lfQuality = DEFAULT_QUALITY;      lf.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;      _tcscpy(lf.lfFaceName, TEXT("MS Sans Serif"));      g_hFontBanner = CreateFontIndirect(&lf);      // Define the window class for our application's main window.      WNDCLASS wc;      ZeroMemory(&wc, sizeof(wc));      wc.lpszClassName = g_szClass;      wc.hInstance     = hInstance;      wc.lpfnWndProc   = WndProc;      wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);      TCHAR *szZipPath = NULL;#ifdef _WIN32_WCE      // Get our main window's small icon.  On Windows CE, we need to send ourself      // a WM_SETICON in order for our task bar to update itself.      g_hIconMain = (HICON)LoadImage(hInstance, MAKEINTRESOURCE(IDI_UNZIP),                                      IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);      wc.hIcon = g_hIconMain;      // On Windows CE, we only need the WS_VISIBLE flag.      DWORD dwStyle = WS_VISIBLE;      // Get and store command line file (if any).      if (lpCmdLine && *lpCmdLine) {         szZipPath = lpCmdLine;      }#else      // On NT we add a cursor, icon, and nenu to our application's window class.      wc.hCursor      = LoadCursor(NULL, IDC_ARROW);      wc.hIcon        = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_UNZIP));      wc.lpszMenuName = MAKEINTRESOURCE(IDR_UNZIP);      // On Windows NT, we use the standard overlapped window style.      DWORD dwStyle = WS_OVERLAPPEDWINDOW;      TCHAR szBuffer[_MAX_PATH];      // Get and store command line file (if any).      if (lpCmdLine && *lpCmdLine) {         mbstowcs(szBuffer, lpCmdLine, countof(szBuffer));         szZipPath = szBuffer;      }#endif      // Register our window class with the OS.      if (!RegisterClass(&wc)) {         DebugOut(TEXT("RegisterClass() failed [%u]"), GetLastError());      }      // Create our main window using our registered window class.      g_hWndMain = CreateWindow(wc.lpszClassName, g_szAppName, dwStyle,                                CW_USEDEFAULT, CW_USEDEFAULT,                                 CW_USEDEFAULT, CW_USEDEFAULT,                                NULL, NULL, hInstance, NULL);      // Quit now if we failed to create our main window.      if (!g_hWndMain) {         DebugOut(TEXT("CreateWindow() failed [%u]"), GetLastError());         ShutdownApplication();         return 0;      }      // Make sure our window is visible.  Really only needed for NT.      ShowWindow(g_hWndMain, nCmdShow);      // Load our keyboard accelerator shortcuts.      MSG    msg;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -