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

📄 cabwoman.c

📁 一个关于windows内置cab文件的源码,能够将cab文件解压缩
💻 C
📖 第 1 页 / 共 4 页
字号:

// _________________________________________________________________
//
//                          SBS CabWoman.c
//                Windows Cabinet File Manager V1.00
//                   01-20-1997 Sven B. Schreiber
//                          sbs@orgon.com
// _________________________________________________________________

#include <windows.h>
#include <guistart.h>
#include <cablib.h>
#include "CabWoman.h"

// =================================================================
// REVISION HISTORY
// =================================================================

/*

01-20-1997  V1.00  SBS  Original version.

*/

// =================================================================
// GLOBAL VARIABLES
// =================================================================

HINSTANCE hInst             = NULL;
HWND      hWndMain          = NULL;
BOOL      fMainDlgInit      = FALSE;

HMODULE   hCtl3d32          = NULL;
PROC      Ctl3dRegister     = NULL;
PROC      Ctl3dAutoSubclass = NULL;
PROC      Ctl3dUnregister   = NULL;

// =================================================================
// GLOBAL STRINGS
// =================================================================

BYTE abMainClass       [] = MAIN_CLASS;
BYTE abMainCaption     [] = MAIN_CAPTION;
BYTE abMainError       [] = MAIN_ERROR;
BYTE abMainIcon        [] = MAIN_ICON;

BYTE abVolume          [] = "Vol";
BYTE abVolumes         [] = "Vol";
BYTE abDirectory       [] = "Directory";
BYTE abDirectories     [] = "Directories";
BYTE abCabinet         [] = "Cabinet";
BYTE abCabinets        [] = "Cabinets";
BYTE abFile            [] = "File";
BYTE abFiles           [] = "Files";

BYTE abSectionDefaults [] = "Defaults";
BYTE abKeyVolume       [] = "Volume";
BYTE abKeyDestination  [] = "Destination";
BYTE abExtracting      [] = "Extracting";
BYTE abNull            [] = "";

BYTE abExeFile [MAX_PATH] = "";
BYTE abIniFile [MAX_PATH] = "";

// =================================================================
// GLOBAL TABLES
// =================================================================

BYTE UCase [] =
    {
      0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
     16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
     32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
     48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
     64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
     80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
     96, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
     80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,123,124,125,126,127,
    128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
    144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,
    160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,
    176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,
    192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
    208,209,210,211,212,213,214,215,216,217,218,219,220,221,254,223,
    192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,
    208,209,210,211,212,213,214,247,216,217,218,219,220,221,254,159
    };

// =================================================================
// AUXILIARY ROUTINES
// =================================================================

BOOL LoadSystemDll (PHMODULE phModule,
                    PBYTE    pbModule,
                    DWORD    dProcedures,
                    ...)
    {
    PDWORD          pdArg = (&dProcedures) + 1;
    BYTE            abModule [MAX_PATH];
    HANDLE          hFindFile;
    WIN32_FIND_DATA wfd;
    DWORD           i;
    BOOL            fOK = FALSE;

    *phModule = NULL;
    for (i = 0; i < dProcedures; i++)
        {
        *((PPROC) pdArg [i+i]) = NULL;
        }
    i = GetSystemDirectory (abModule, MAX_PATH);
    if (i && (i < MAX_PATH))
        {
        if (abModule [i-1] != '\\')
            {
            abModule [i++] = '\\';
            }
        if ((i + lstrlen (pbModule)) < MAX_PATH)
            {
            lstrcpy (abModule+i, pbModule);
            hFindFile = FindFirstFile (abModule, &wfd);
            if (hFindFile != INVALID_HANDLE_VALUE)
                {
                FindClose (hFindFile);
                *phModule = LoadLibrary (abModule);
                if (*phModule != NULL)
                    {
                    fOK = TRUE;
                    for (i = 0; i < dProcedures; i++)
                        {
                        *((PPROC) pdArg [i+i]) =
                            GetProcAddress (*phModule,
                                            (PBYTE) pdArg [i+i+1]);
                        fOK = (fOK &&
                               (*((PPROC) pdArg [i+i]) != NULL));
                        }
                    }
                }
            }
        }
    return fOK;
    }

// -----------------------------------------------------------------

BOOL UnloadSystemDll (PHMODULE phModule)
    {
    BOOL fOK;

    if (fOK = (*phModule != NULL))
        {
        FreeLibrary (*phModule);
        *phModule = NULL;
        }
    return fOK;
    }

// -----------------------------------------------------------------

DWORD WINAPI GetFile (PBYTE pbSource,
                      PBYTE pbItem,
                      PBYTE pbTarget,
                      DWORD dBytes)
    {
    DWORD i, j, k, n;

    i = (pbSource [0] ? (pbSource [1] == ':' ? 2 : 0) : 0);
    k = j = i;
    do
        {
        if (pbSource [i] == '.' )     j = i;
        if (pbSource [i] == '\\') k = j = i;
        }
    while (pbSource [i++]);

    if (pbSource [j] != '.' ) j = i - 1;
    if (pbSource [k] == '\\') k++;

    i = (pbItem [0] == '.' ? j : k);
    if ((n = i + lstrlen (pbItem)) < dBytes)
        {
        lstrcpyn (pbTarget,   pbSource, i+1);
        lstrcpy  (pbTarget+i, pbItem);
        }
    else
        {
        if ((n = 0) < dBytes) pbTarget [0] = 0;
        }
    return n;
    }

// -----------------------------------------------------------------

PBYTE WINAPI GetFileName (PBYTE pbPath)
    {
    DWORD i, j;

    j = i = (pbPath [0] ? (pbPath [1] == ':' ? 2 : 0) : 0);

    while (pbPath [i++])
        {
        if (pbPath [i-1] == '\\') j = i;
        }
    return pbPath+j;
    }

// -----------------------------------------------------------------

BOOL WINAPI SetDirectory (PBYTE pbVolume,
                          PBYTE pbDirectory)
    {
    BYTE  abPath [MAX_PATH];
    DWORD dSize;
    BOOL  fOK = FALSE;

    if (SetCurrentDirectory (pbDirectory) ||
        SetCurrentDirectory (pbVolume))
        {
        dSize = GetCurrentDirectory (MAX_PATH, abPath);

        if ((dSize < MAX_PATH) && dSize)
            {
            WritePrivateProfileString (abSectionDefaults,
                                       abKeyVolume,
                                       pbVolume,
                                       GetFileName (abIniFile));

            WritePrivateProfileString (abSectionDefaults,
                                       pbVolume,
                                       abPath,
                                       GetFileName (abIniFile));

            fOK = TRUE;
            }
        }
    return fOK;
    }

// -----------------------------------------------------------------

BOOL WINAPI SetDefaultDirectory (PBYTE pbVolume)
    {
    BYTE  abPath [MAX_PATH];
    DWORD dSize;

    dSize = GetPrivateProfileString (abSectionDefaults,
                                     pbVolume,
                                     abNull,
                                     abPath,
                                     MAX_PATH,
                                     GetFileName (abIniFile));

    return SetDirectory (pbVolume, (dSize ? abPath : pbVolume));
    }

// -----------------------------------------------------------------

BYTE WINAPI GetDefaultVolume (void)
    {
    BYTE  abPath [MAX_PATH];
    DWORD dSize;

    dSize = GetPrivateProfileString (abSectionDefaults,
                                     abKeyVolume,
                                     abNull,
                                     abPath,
                                     MAX_PATH,
                                     GetFileName (abIniFile));

    if ((dSize < 2) || (abPath [1] != ':'))
        {
        dSize = GetCurrentDirectory (MAX_PATH, abPath);

        if ((dSize >= MAX_PATH) ||
            (dSize < 2) || (abPath [1] != ':'))
            {
            dSize = 0;
            }
        }
    return UCase [(dSize ? abPath [0] : 'C')];
    }

// -----------------------------------------------------------------

BOOL printfDlgItem (HWND  hWnd,
                    int   iDlgItem,
                    PBYTE pbFormat,
                    ...)
    {
    BYTE abBuffer [MAX_MESSAGE];

    wvsprintf (abBuffer, pbFormat, (PVOID) ((&pbFormat)+1));
    return SetDlgItemText (hWnd, iDlgItem, abBuffer);
    }

// -----------------------------------------------------------------

BOOL ClearDlgItem (HWND  hWnd,
                   int   iDlgItem)
    {
    return SetDlgItemText (hWnd, iDlgItem, abNull);
    }

// =================================================================
// WINDOW MANAGEMENT
// =================================================================

BOOL WINAPI CenterWindow (HWND hWnd)
    {
    RECT SysRect, WndRect;

    return ((hWnd != NULL) &&
            GetWindowRect (GetDesktopWindow (), &SysRect) &&
            GetWindowRect (hWnd, &WndRect) &&
            MoveWindow (hWnd,
                        ((SysRect.right - SysRect.left) -
                         (WndRect.right - WndRect.left)) / 2,
                        ((SysRect.bottom - SysRect.top) -
                         (WndRect.bottom - WndRect.top)) / 2,
                        WndRect.right  - WndRect.left,
                        WndRect.bottom - WndRect.top,
                        TRUE));
    }

// -----------------------------------------------------------------

LRESULT WINAPI Dispatcher (DISPATCH  Dispatch [],
                           DWORD     dEvent,
                           HWND      hWnd,
                           UINT      uMsg,
                           WPARAM    wParam,
                           LPARAM    lParam)
    {
    DWORD i;

    i = 0;
    while ((Dispatch [i].dEvent != DEFAULT_HANDLER) &&
           (Dispatch [i].dEvent != DEFAULT_RESULT)  &&
           (Dispatch [i].dEvent != dEvent)) i++;

    return (Dispatch [i].dEvent != DEFAULT_RESULT
            ? Dispatch [i].xHandler (hWnd, uMsg, wParam, lParam)
            : (LRESULT) Dispatch [i].xHandler);
    }

// =================================================================
// LIST BOX MANAGEMENT
// =================================================================

void WINAPI ClearListBox (HWND hWnd,
                          int  iDlgItem)
    {
    HWND hListBox = GetDlgItem (hWnd, iDlgItem);

    SendDlgItemMessage (hWnd,
                        iDlgItem,
                        LB_RESETCONTENT,
                        (WPARAM) 0,
                        (LPARAM) 0);

    if (hListBox != NULL) UpdateWindow (hListBox);
    return;
    }

// -----------------------------------------------------------------

DWORD WINAPI GetListBoxCount (HWND hWnd,
                              int  iDlgItem)
    {
    DWORD dCount;

    dCount = SendDlgItemMessage (hWnd,
                                 iDlgItem,
                                 LB_GETCOUNT,
                                 (WPARAM) 0,
                                 (LPARAM) 0);

    if (dCount == LB_ERR) dCount = 0;
    return dCount;
    }

// -----------------------------------------------------------------

DWORD WINAPI AddListBoxItem (HWND  hWnd,
                             int   iDlgItem,
                             PBYTE pbText,
                             DWORD dData)
    {
    DWORD dIndex;

    dIndex = SendDlgItemMessage (hWnd,
                                 iDlgItem,
                                 LB_ADDSTRING,
                                 (WPARAM) 0,
                                 (LPARAM) pbText);

    if ((dIndex == LB_ERR) || (dIndex == LB_ERRSPACE))
        {
        dIndex = MAXDWORD;
        }
    else
        {
        SendDlgItemMessage (hWnd,
                            iDlgItem,
                            LB_SETITEMDATA,
                            (WPARAM) dIndex,
                            (LPARAM) dData);
        }
    return dIndex;
    }

// -----------------------------------------------------------------

DWORD WINAPI SelectListBoxItem (HWND  hWnd,
                                int   iDlgItem,
                                DWORD dSelect)
    {
    HWND   hListBox = GetDlgItem (hWnd, iDlgItem);
    DWORD  dCount, dIndex;

    dCount = GetListBoxCount (hWnd, iDlgItem);

    dIndex = ((dSelect < dCount) || (dSelect == MAXDWORD)
              ? dSelect
              : dCount-1);

⌨️ 快捷键说明

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