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

📄 wizmain.c

📁 有关zip的一个开发实例。主要包括图片和程序源代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************    PURPOSE:  Windows Info-ZIP    FUNCTIONS:        WinMain() - calls initialization function, processes message loop        WiZInit() - initializes window data and registers window        WiZMainWndProc() - processes messages        About() - processes messages for "About" dialog box    AUTHOR: Robert A. Heath,  157 Chartwell Rd. Columbia, SC 29210    I place this source module, WizUnZip.c, in the public domain.  Use it as    you will.	 Modifications: M. White - 1995, 1996		- Ported to Borland C		- Ported to WinNT and Win95		- Added dll functionality		- Added zip functionality		- renamed to wizmain.c		- extensively modified for WiZ****************************************************************************/#include <sys/types.h>#include <sys/stat.h>#include <time.h>#include <string.h>#include "wiz.h"#include "wizver.h"#ifdef WIN32#include <winver.h>#else#include <dir.h>#include <ver.h>#endif#ifdef WIN32#define UNZ_DLL_NAME "UNZIP32.DLL\0"#define ZIP_DLL_NAME "ZIP32.DLL\0"#else#define UNZ_DLL_NAME "UNZIP16.DLL\0"#define ZIP_DLL_NAME "ZIP16.DLL\0"#  ifndef TEXT#    define TEXT(x) x#  endif#endifstatic char __based(__segname("STRINGS_TEXT")) szFirstUse[] = "FirstUse"; /* first use keyword in WiZ.INI */char __based(__segname("STRINGS_TEXT")) szDefaultUnzipToDir[] = "DefaultUnzipToDir";char __based(__segname("STRINGS_TEXT")) szDefaultUnzipFromDir[] = "DefaultUnzipFromDir";char __based(__segname("STRINGS_TEXT")) szLBSelectionKey[] = "LBSelection"; /* LBSelection keyword in WiZ.INI */char __based(__segname("STRINGS_TEXT")) szHideStatus[] = "HideStatusWindow";char __based(__segname("STRINGS_TEXT")) szWiZIniFile[] = "WIZ.INI";char __based(__segname("STRINGS_TEXT")) szZipOptionKey[] = "ZipOptions";char __based(__segname("STRINGS_TEXT")) szZipToDirKey[] = "ZipToDir";/* File and Path Name variables */char __based(__segname("STRINGS_TEXT")) szAppName[] = "WiZ";       /* application title        */char __based(__segname("STRINGS_TEXT")) szStatusClass[] = "MsgWndw";/* status window class  */char __based(__segname("STRINGS_TEXT")) szUnzipToDirName[PATH_MAX];    /* extraction ("windll_unzip to") directory name in ANSI *//* Note that szHelpFileName will be expanded to a fully qualified path   and file name when we go search for the help file. */#ifdef WIN32char szHelpFileName[PATH_MAX] = "WIZ32.HLP";#elsechar szHelpFileName[PATH_MAX] = "WIZ16.HLP";#endif#define DLL_WARNING "Cannot find %s."\            " The Dll must be in the application directory, the path, "\            "the Windows directory or the Windows System directory."#define DLL_VERSION_WARNING "%s has the wrong version number."\            " Insure that you have the correct dll's installed, and that "\            "an older dll is not in your path or Windows System directory."#ifdef WIN32extern HWND hSplashScreen;void ShowSplashScreen(void);#endifHANDLE hInst;               /* current instance */HMENU  hMenu;               /* main menu handle */HANDLE hAccTable;HANDLE hHourGlass;          /* handle to hourglass cursor */HANDLE hSaveCursor;         /* current cursor handle */HANDLE hHelpCursor;         /* help cursor */HANDLE hFixedFont;          /* handle to fixed font */HANDLE hOldFont;            /* handle to old font */int hFile;              /* file handle */HWND hWndMain;          /* the main window handle. */HWND hWndList;          /* list box handle */HWND hWndEdit;        /* status   (a.k.a. Messages) window */HWND hWndStatic;HWND hExtract;          /* extract button */HWND hDisplay;          /*display button */HWND hTest;             /* test button */HWND hZipInfo;          /* Zip Info button */HWND hShowComment;      /* show comment button */HWND hHelp;   /* help button */HWND hOpen;   /* open button */HWND hArchive; /* create archive button */HWND hDeleteArchive; /* delete button */HWND hCopyArchive;   /* copy archive button */HWND hMoveArchive;   /* move archive button */HWND hRenameArchive; /* rename archive button */HWND hExit;HWND hMakeDir;HWND hSelectAll;HWND hDeselectAll;HWND hSelectPattern;HWND hClearStatus;HWND hUnzipToDir;HWND hStatusButton;HWND hListBoxButton;int fLB_Selection;UF  uf;WPARAM wLBSelection = IDM_LB_DISPLAY; /* default listbox selection action */HBRUSH hBrush ;         /* brush for  standard window backgrounds  */LPUMB lpumb;LPUSERFUNCTIONS lpUserFunctions;LPZIPUSERFUNCTIONS lpZipUserFunctions;HANDLE hUF       = (HANDLE)NULL;LPDCL lpDCL      = NULL;HANDLE hZUF      = (HANDLE)NULL;HANDLE hDCL      = (HANDLE)NULL;ZCL ZpZCL;ZPOPT ZpOpt;#ifdef WIN32HWND       hRTF;HANDLE  hRTFLib  = (HANDLE)NULL;DWORD dwPlatformId = 0xFFFFFFFF;#endifHINSTANCE hZipDll;HINSTANCE hUnzipDll;HANDLE  hStrings = (HANDLE)NULL;HANDLE  hEditor = (HANDLE)NULL;int ofretval;       /* return value from initial open if filename given */WORD cZippedFiles;      /* total personal records in file   */WORD cListBoxLines; /* max list box lines showing on screen */WORD cLinesMessageWin; /* max visible lines on message window  *//* Forward References */#ifndef USE_UNZIP_LIB_DLL_UNZVAL Unz_Validate;_DLL_UNZIP Unz_SingleEntryPoint;_USER_FUNCTIONS UzInit;#endif#ifndef USE_ZIP_LIB_ZIP_USER_FUNCTIONS ZipInit;_DLL_ZIP ZipArchive;ZIPSETOPTIONS ZipSetOptions;ZIPGETOPTIONS ZipGetOptions;#endifvoid FreeUpMemory(void);#ifdef WIN32BOOL IsNT(VOID);#endifint WINAPI WinMain(HANDLE, HANDLE, LPSTR, int);long WINAPI WiZMainWndProc(HWND, WORD, WPARAM, LPARAM);/****************************************************************************    FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)    PURPOSE: calls initialization function, processes message loop    COMMENTS:        This will initialize the window class if it is the first time this        application is run.  It then creates the window, and processes the        message loop until a WM_QUIT message is received.  It exits the        application by returning the value passed by the PostQuitMessage.****************************************************************************/#ifdef __BORLANDC__#  ifdef WIN32#pragma argsused#  endif#endifint WINAPI WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)HANDLE hInstance;         /* current instance             */HANDLE hPrevInstance;     /* previous instance            */LPSTR lpCmdLine;          /* command line                 */int nCmdShow;             /* show-window type (open/icon) */{#ifdef WIN32char *ptr;DWORD second;   /* Used for timing the splash screen */#if (!defined(USE_UNZIP_LIB) && !defined(USE_ZIP_LIB))DWORD dwVerInfoSize;DWORD dwVerHnd;HANDLE  hMem;         /* handle to mem alloc'ed */#endif#elseHFILE hfile;OFSTRUCT ofs;#endifchar szFullPath[PATH_MAX];int i;BOOL fFirstUse;           /* first use if TRUE         */#ifndef WIN32if (!hPrevInstance)       /* Has application been initialized? */#endif   if (!WiZInit(hInstance))      return 0;           /* Exits if unable to initialize     */#ifdef WIN32      InitCommonControls();if (!hRTFLib)   hRTFLib = LoadLibrary("RICHED32.DLL");if (!hRTFLib)    {    char szErr[255];    wsprintf(szErr, "LoadLibrary Failed. Error Code %ld", GetLastError());    MessageBox(NULL, szErr, szAppName, MB_OK );    return 0;    }IsNT(); /* Are we running on NT? */#endifhStrings = GlobalAlloc( GPTR, (DWORD)sizeof(UMB));if ( !hStrings )   {#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }lpumb = (LPUMB)GlobalLock( hStrings );if ( !lpumb )   {   GlobalFree( hStrings );#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }hDCL = GlobalAlloc( GPTR, (DWORD)sizeof(DCL));if (!hDCL)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }lpDCL = (LPDCL)GlobalLock(hDCL);if (!lpDCL)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }hUF = GlobalAlloc( GPTR, (DWORD)sizeof(USERFUNCTIONS));if (!hUF)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }lpUserFunctions = (LPUSERFUNCTIONS)GlobalLock(hUF);if (!lpUserFunctions)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }hZUF = GlobalAlloc( GPTR, (DWORD)sizeof(ZIPUSERFUNCTIONS));if (!hZUF)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }lpZipUserFunctions = (LPZIPUSERFUNCTIONS)GlobalLock(hZUF);if (!lpZipUserFunctions)   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }uf.fCanDragDrop = FALSE;#ifndef WIN32if ((hHourGlass = GetModuleHandle("SHELL"))!=0)   {   if (GetProcAddress(hHourGlass, "DragAcceptFiles" ))      uf.fCanDragDrop = TRUE;   }#elseuf.fCanDragDrop = TRUE;#endiflpUserFunctions->password = password;lpUserFunctions->print = DisplayBuf;lpUserFunctions->sound = SoundDuring;lpUserFunctions->replace = GetReplaceDlgRetVal;lpUserFunctions->SendApplicationMessage = ReceiveDllMessage;lpZipUserFunctions->print = lpUserFunctions->print;//DisplayBuf;lpZipUserFunctions->password = password;lpZipUserFunctions->comment = comment;hWndMain = CreateWindow(szAppName,      /* window class     */        szAppName,                      /* window name      */        WS_OVERLAPPEDWINDOW,            /* window style     */        0, 0, 0, 0,        (HWND)0,                        /* parent handle    */        (HWND)0,                        /* menu or child ID */        hInstance,                      /* instance         */        NULL);                          /* additional info  */if ( !hWndMain )   {   FreeUpMemory();#ifdef WIN32   FreeLibrary(hRTFLib);#endif   return 0;   }#ifdef WIN32ShowSplashScreen();#endif/* Let's try to find the help file first */#ifdef WIN32if (SearchPath(    NULL,               /* address of search path               */    szHelpFileName,     /* address of filename                  */    NULL,               /* address of extension                 */    PATH_MAX,           /* size, in characters, of buffer       */    szFullPath,         /* address of buffer for found filename */    &ptr                /* address of pointer to file component */   ) != 0)   {   lstrcpy(szHelpFileName, szFullPath);   }#elsehfile = OpenFile(szHelpFileName,  &ofs, OF_SEARCH);if (hfile != HFILE_ERROR)   {   lstrcpy(szHelpFileName, ofs.szPathName);   }#endif#ifndef WIN32_lclose(hfile);#endif#ifndef USE_UNZIP_LIB#ifdef WIN32if (SearchPath(    NULL,               /* address of search path               */    UNZ_DLL_NAME,       /* address of filename                  */    NULL,               /* address of extension                 */    PATH_MAX,           /* size, in characters, of buffer       */    szFullPath,         /* address of buffer for found filename */    &ptr                /* address of pointer to file component */   ) == 0)#elsehfile = OpenFile(UNZ_DLL_NAME,  &ofs, OF_SEARCH);if (hfile == HFILE_ERROR)#endif   {   char str[256];   wsprintf (str, DLL_WARNING, UNZ_DLL_NAME);   MessageBox ((HWND)NULL, str, szAppName, MB_ICONHAND | MB_SYSTEMMODAL | MB_OK);   FreeUpMemory();#ifdef WIN32   DestroyWindow(hSplashScreen);   FreeLibrary(hRTFLib);#endif   return 0;   }#ifndef WIN32else   lstrcpy(szFullPath, ofs.szPathName);_lclose(hfile);#endif#ifdef WIN32/* First we'll check the unzip dll version information */dwVerInfoSize =    GetFileVersionInfoSize(szFullPath, &dwVerHnd);if (dwVerInfoSize)   {   BOOL  fRet, fRetName;   char str[256];   LPSTR   lpstrVffInfo; /* Pointer to block to hold info */   LPSTR lszVer = NULL;   LPSTR lszVerName = NULL;   UINT  cchVer = 0;   /* Get a block big enough to hold the version information */   hMem          = GlobalAlloc(GMEM_MOVEABLE, dwVerInfoSize);   lpstrVffInfo  = GlobalLock(hMem);   /* Get the version information */   if (GetFileVersionInfo(szFullPath, 0L, dwVerInfoSize, lpstrVffInfo))      {      fRet = VerQueryValue(lpstrVffInfo,               TEXT("\\StringFileInfo\\040904E4\\FileVersion"),              (LPVOID)&lszVer,              &cchVer);      fRetName = VerQueryValue(lpstrVffInfo,               TEXT("\\StringFileInfo\\040904E4\\CompanyName"),               (LPVOID)&lszVerName,               &cchVer);      if (!fRet || !fRetName ||         (lstrcmpi(lszVer, UNZ_DLL_VERSION) != 0) ||         (lstrcmpi(lszVerName, COMPANY_NAME) != 0))         {         wsprintf (str, DLL_VERSION_WARNING, UNZ_DLL_NAME);         MessageBox((HWND)NULL, str, szAppName, MB_ICONSTOP | MB_OK);         FreeUpMemory();         GlobalUnlock(hMem);         GlobalFree(hMem);         DestroyWindow(hSplashScreen);         FreeLibrary(hRTFLib);         return 0;         }      }      /* free memory */   GlobalUnlock(hMem);   GlobalFree(hMem);

⌨️ 快捷键说明

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