home *** CD-ROM | disk | FTP | other *** search
- /*
- * DllAPI.cpp
- * Copyright (c) 1998-1999, Xceed Software Inc.
- *
- * Description:
- * Sample application using the Xceed Zip 4 DLL API interface.
- * This file contains the entry point of the application.
- *
- */
-
- #include "stdafx.h"
- #include "resource.h"
- #include "Examples.h"
-
-
- #define MAX_LOADSTRING 100
-
- // Global Variables:
- HINSTANCE hInst; // current instance
- TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
- TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
-
- // Foward declarations of functions included in this code module:
- ATOM MyRegisterClass(HINSTANCE hInstance);
- BOOL InitInstance(HINSTANCE, int);
- LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
- LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
-
- // Xceed Zip Dll instance
- HMODULE hXceedZipDll;
-
- int APIENTRY WinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int nCmdShow)
- {
- MSG msg;
- HACCEL hAccelTable;
-
- // Initialize global strings
- LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
- LoadString(hInstance, IDC_API, szWindowClass, MAX_LOADSTRING);
- MyRegisterClass(hInstance);
-
- // Perform application initialization:
- if (!InitInstance (hInstance, nCmdShow))
- {
- return FALSE;
- }
-
- hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_API);
-
- // Initialize the Xceed Zip Compression Library for Dll API access
- hXceedZipDll = LoadLibrary( "XceedZip.dll" );
-
- LPFNXCEEDZIPINITDLL lpfnInitDll = ( LPFNXCEEDZIPINITDLL ) GetProcAddress( hXceedZipDll, "XceedZipInitDLL" );
-
- if( lpfnInitDll )
- {
- lpfnInitDll();
- }
-
- // Main message loop:
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
-
- LPFNXCEEDZIPSHUTDOWNDLL lpfnShutdown = ( LPFNXCEEDZIPSHUTDOWNDLL ) GetProcAddress( hXceedZipDll, "XceedZipShutdownDLL" );
-
- if( lpfnShutdown )
- {
- lpfnShutdown();
- }
-
- FreeLibrary( hXceedZipDll );
-
- return msg.wParam;
- }
-
-
-
- //
- // FUNCTION: MyRegisterClass()
- //
- // PURPOSE: Registers the window class.
- //
- // COMMENTS:
- //
- // This function and its usage is only necessary if you want this code
- // to be compatible with Win32 systems prior to the 'RegisterClassEx'
- // function that was added to Windows 95. It is important to call this function
- // so that the application will get 'well formed' small icons associated
- // with it.
- //
- ATOM MyRegisterClass(HINSTANCE hInstance)
- {
- WNDCLASSEX wcex;
-
- wcex.cbSize = sizeof(WNDCLASSEX);
-
- wcex.style = CS_HREDRAW | CS_VREDRAW;
- wcex.lpfnWndProc = (WNDPROC)WndProc;
- wcex.cbClsExtra = 0;
- wcex.cbWndExtra = 0;
- wcex.hInstance = hInstance;
- wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_API);
- wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
- wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wcex.lpszMenuName = (LPCSTR)IDC_API;
- wcex.lpszClassName = szWindowClass;
- wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
-
- return RegisterClassEx(&wcex);
- }
-
- //
- // 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;
-
- hInst = hInstance; // Store instance handle in our global variable
-
- hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
-
- if (!hWnd)
- {
- return FALSE;
- }
-
- ShowWindow(hWnd, nCmdShow);
- UpdateWindow(hWnd);
-
- 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)
- {
- static HWND hList = NULL;
-
- // For preview example
- static HXCEEDZIP hCurrent = NULL;
-
- switch (message)
- {
- case WM_CREATE:
- {
- RECT rClient;
- GetClientRect( hWnd, &rClient );
-
- hList = CreateWindow( "LISTBOX", "", WS_BORDER | WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT,
- rClient.left, rClient.top, rClient.right, rClient.bottom,
- hWnd, ( HMENU )11, hInst, 0 );
-
- break;
- }
-
- case WM_SIZE:
- {
- RECT rClient;
- GetClientRect( hWnd, &rClient );
-
- MoveWindow( hList, rClient.left, rClient.top, rClient.right, rClient.bottom, TRUE );
-
- break;
- }
-
- case WM_COMMAND:
- {
- int wmId = LOWORD(wParam);
- int wmEvent = HIWORD(wParam);
-
- // Parse the menu selections:
- switch (wmId)
- {
- case IDM_ABOUT:
- DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
- break;
- case IDM_EXIT:
- DestroyWindow(hWnd);
- break;
- case IDM_OPTIONS_REPLACE:
- {
- HMENU hMenu = GetMenu( hWnd );
-
- CheckMenuItem( hMenu, wmId,
- MF_BYCOMMAND & ( GetMenuState( hMenu, wmId, MF_BYCOMMAND ) ^ MF_CHECKED ) );
- break;
- }
- case IDM_OPTIONS_CLEAR:
- SendMessage( hList, LB_RESETCONTENT, 0, 0 );
- break;
-
- //
- // Zip example
- //
- case IDM_XCEED_ZIP:
- {
- DoZipExample( hWnd, hList );
-
- break;
- }
-
- //
- // Unzip example
- //
- case IDM_XCEED_UNZIP:
- {
- DoUnzipExample( hList );
-
- break;
- }
-
- //
- // Preview example
- //
- case IDM_XCEED_PREVIEW:
- {
- XceedZipFunctions* pFuncs = ( XceedZipFunctions* ) GetProcAddress( hXceedZipDll, "g_xzFunctions" );
-
- if ( hCurrent )
- {
- // Abort the operation
- pFuncs->lpfnXzSetAbort( hCurrent, TRUE );
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) "The previewing operation is being aborted." );
- }
- else
- {
- DoPreviewExample( hWnd, hList, &hCurrent );
- }
-
- ModifyMenu( GetMenu( hWnd ), IDM_XCEED_PREVIEW, MF_BYCOMMAND | MF_STRING, IDM_XCEED_PREVIEW,
- ( hCurrent ? "Abort &Preview files" : "&Preview files" ) );
-
- break;
- }
-
- //
- // Listing zip file example
- //
- case IDM_XCEED_LIST:
- {
- DoListingExample( hWnd, hList );
-
- break;
- }
-
- //
- // Testing zip file example
- //
- case IDM_XCEED_TEST:
- {
- DoTestingExample( hWnd, hList );
-
- break;
- }
-
- //
- // Getting zip file contents example
- //
- case IDM_XCEED_GET:
- {
- DoGetContentsExample( hWnd, hList );
-
- break;
- }
-
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- break;
- }
-
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
-
- // When XceedZip triggers an event, and you specified handling events with
- // a window message, your window receives this message. Then, the wParam
- // contains the XceedZip event id, as found in XceedZipAPI.h, and the lParam
- // is a pointer to the parameters structure. Depending on if you created
- // your HXCEEDZIP with XzCreateXceedZipA or XzCreateXceedZipW, you need
- // to typecast lParam to the equivalent structure. For the sake of these
- // examples, when using the window message, we use Ansi calls. For an example
- // on using Unicode calls, take a look at "MyCallback" in "Examples.cpp"
- // Since this project is compiling in Ansi, not in Unicode, we can use the
- // typenames that do not end with an A or W. These are automatically mapped
- // to the correct type, depending if "UNICODE" is defined.
- // (see XceedZipAPI.h)
- case WM_USER_XCEEDZIPEVENT:
- {
- switch( wParam )
- {
- // Another disk is required
- case XM_INSERTDISK:
- {
- // We typecast lParam to the correct structure pointer
- xcdInsertDiskParams* pParams = ( xcdInsertDiskParams * ) lParam;
- int nAnswer = IDCANCEL;
-
- if ( pParams->lDiskNumber == 0 )
- {
- nAnswer = MessageBox( hWnd, "Please insert the last disk of the set.", "Disk required",
- MB_ICONQUESTION | MB_OKCANCEL );
- }
- else
- {
- char szMsg[ 100 ];
- wsprintf( szMsg, "Please insert disk #%d.", pParams->lDiskNumber );
- nAnswer = MessageBox( hWnd, szMsg, "Disk required", MB_ICONQUESTION | MB_OKCANCEL );
- }
-
- // We modify the bDiskInserted member to reflect the desired action
- pParams->bDiskInserted = ( nAnswer == IDOK );
-
- break;
- }
- // A file is evaluated for zipping
- case XM_ZIPPREPROCESSINGFILE:
- {
- xcdZipPreprocessingFileParams* pParams = ( xcdZipPreprocessingFileParams * ) lParam;
- // Here, you could change some information about this file, or reject
- // the file based on your own custom filtering conditions.
- break;
- }
- // A file would be evaluated in a similar zip operation
- case XM_PREVIEWINGFILE:
- {
- xcdPreviewingFileParams* pParams = ( xcdPreviewingFileParams * ) lParam;
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) pParams->szFilename );
- break;
- }
- // A file is found in the zip file
- case XM_LISTINGFILE:
- {
- xcdListingFileParams* pParams = ( xcdListingFileParams * ) lParam;
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) pParams->szFilename );
- break;
- }
- // A file is skipped for some reason
- case XM_SKIPPINGFILE:
- {
- xcdSkippingFileParams* pParams = ( xcdSkippingFileParams * ) lParam;
-
- // Display the skipped filename
- char szMsg[ 300 ];
- wsprintf( szMsg, "Skipping file %s", pParams->szFilename );
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) szMsg );
-
- // Get and display the reason. You can see that each structure contains
- // the handle top the instance that triggered the event (hZip).
- szMsg[ 0 ] = ' ';
-
- LPFNXZGETERRORDESCRIPTIONA pDesc = ( LPFNXZGETERRORDESCRIPTIONA ) GetProcAddress( hXceedZipDll, "XzGetErrorDescriptionA" );
-
- if( pDesc )
- {
- pDesc( pParams->hZip, xvtSkippingReason, pParams->xReason, szMsg+1, 299 );
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) szMsg );
- }
-
- break;
- }
- // A file will be tested. If an error occurs, a SkippingFile or
- // Warning event will occur
- case XM_TESTINGFILE:
- {
- xcdTestingFileParams* pParams = ( xcdTestingFileParams * ) lParam;
- // Here, we could verify that the list of files is what we expect
- break;
- }
- // The FileStatus event is the triggered event along the actual
- // processing. That's why it's the best place for status messages.
- case XM_FILESTATUS:
- {
- xcdFileStatusParams* pParams = ( xcdFileStatusParams * ) lParam;
-
- // When starting to process a file, we display it's name
- if ( pParams->lBytesProcessed == 0 )
- {
- LPFNXZGETCURRENTOPERATION pOper = ( LPFNXZGETCURRENTOPERATION ) GetProcAddress( hXceedZipDll, "XzGetCurrentOperation" );
-
- if( pOper )
- {
- char szMsg[ 300 ] = { 0 };
-
- // Starting to process this file
- switch( pOper( pParams->hZip ) )
- {
- case xcoZipping:
- {
- wsprintf( szMsg, "Zipping %s", pParams->szFilename );
- break;
- }
- case xcoTestingZipFile:
- {
- wsprintf( szMsg, "Testing %s", pParams->szFilename );
- break;
- }
- }
-
- if ( szMsg[ 0 ] )
- {
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) szMsg );
- }
- }
- }
-
- // We could insert here code to update a file status progress bar.
-
- break;
- }
- // The GlobalStatus event gives the global progression
- case XM_GLOBALSTATUS:
- {
- xcdGlobalStatusParams* pParam = ( xcdGlobalStatusParams * ) lParam;
- break;
- }
- // When spanning, we could handle this to wipe inserted disks.
- case XM_DISKNOTEMPTY:
- {
- xcdDiskNotEmptyParams* pParams = ( xcdDiskNotEmptyParams * ) lParam;
- break;
- }
- // The process is completed. This is highly usefull when working
- // in background processing
- case XM_PROCESSCOMPLETED:
- {
- xcdProcessCompletedParams* pParams = ( xcdProcessCompletedParams * ) lParam;
-
- XceedZipFunctions* pFuncs = ( XceedZipFunctions* ) GetProcAddress( hXceedZipDll, "g_xzFunctions" );
-
- if( pFuncs && pFuncs->lpfnXzGetCurrentOperation( pParams->hZip ) == xcoPreviewing )
- {
- // Since the previewing is done in background, we release handles here!
- char szMsg[ 200 ];
- pFuncs->lpfnXzGetErrorDescriptionA( pParams->hZip, xvtError, pParams->xResult, szMsg, 200 );
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) szMsg );
-
- pFuncs->lpfnXzDestroyXceedZip( hCurrent );
- hCurrent = NULL;
-
- ModifyMenu( GetMenu( hWnd ), IDM_XCEED_PREVIEW, MF_BYCOMMAND | MF_STRING, IDM_XCEED_PREVIEW, "&Preview files" );
- }
-
- break;
- }
- // When creating a zip file, we can assign a global comment here.
- // When reading a zip file, we can retrieve the global comment here.
- // When modifying a zip file, we both can get and set the comment here.
- case XM_ZIPCOMMENT:
- {
- xcdZipCommentParams* pParams = ( xcdZipCommentParams * ) lParam;
- break;
- }
- // If you want to zip memory, do start here
- case XM_QUERYMEMORYFILE:
- {
- xcdQueryMemoryFileParams* pParams = ( xcdQueryMemoryFileParams * ) lParam;
- break;
- }
- // This is triggered when you handle QueryMemoryFile
- case XM_ZIPPINGMEMORYFILE:
- {
- xcdZippingMemoryFileParams* pParams = ( xcdZippingMemoryFileParams * ) lParam;
- break;
- }
- // This is triggered when you redirect to memory through the
- // UnzipPreprocessingFile event.
- case XM_UNZIPPINGMEMORYFILE:
- {
- xcdUnzippingMemoryFileParams* pParams = ( xcdUnzippingMemoryFileParams * ) lParam;
- break;
- }
- // A recoverable inconsistency was encountered
- case XM_WARNING:
- {
- xcdWarningParams* pParams = ( xcdWarningParams * ) lParam;
-
- // Display the affected file and the message
- char szWarning[ 200 ] = { 0 };
-
- LPFNXZGETERRORDESCRIPTIONA pDesc = ( LPFNXZGETERRORDESCRIPTIONA ) GetProcAddress( hXceedZipDll, "XzGetErrorDescriptionA" );
-
- if( pDesc )
- {
- pDesc( pParams->hZip, xvtWarning, pParams->xWarning, szWarning, 200 );
- }
-
- char szMsg[ 200 ];
- wsprintf( szMsg, "Warning for file %s: %s", pParams->szFilename, szWarning );
- SendMessage( hList, LB_ADDSTRING, 0, ( LPARAM ) szMsg );
-
- break;
- }
- // The provided password is incorrect
- case XM_INVALIDPASSWORD:
- {
- xcdInvalidPasswordParams* pParams = ( xcdInvalidPasswordParams * ) lParam;
- break;
- }
- // A file is about to be replaced
- case XM_REPLACINGFILE:
- {
- xcdReplacingFileParams* pParams = ( xcdReplacingFileParams * ) lParam;
- break;
- }
- // When updating a zip file, this is triggered while reading the
- // original zip file.
- case XM_ZIPCONTENTSSTATUS:
- {
- xcdZipContentsStatusParams* pParam = ( xcdZipContentsStatusParams * ) lParam;
- break;
- }
- }
- break;
- }
- default:
- return DefWindowProc(hWnd, message, wParam, lParam);
- }
- return 0;
- }
-
- // Mesage handler for about box.
- LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return TRUE;
-
- case WM_COMMAND:
- if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
- {
- EndDialog(hDlg, LOWORD(wParam));
- return TRUE;
- }
- break;
- }
- return FALSE;
- }
-