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

📄 cabwoman.c

📁 一个关于windows内置cab文件的源码,能够将cab文件解压缩
💻 C
📖 第 1 页 / 共 4 页
字号:
    SendDlgItemMessage (hWnd,
                        iDlgItem,
                        LB_SETCURSEL,
                        (WPARAM) dIndex,
                        (LPARAM) 0);

    if (hListBox != NULL)
        {
        PostMessage (hWnd,
                     WM_COMMAND,
                     (WPARAM) MAKELONG (iDlgItem, LBN_SELCHANGE),
                     (LPARAM) hListBox);
        }
    return dCount;
    }

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

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

    if (hListBox != NULL)
        {
        PostMessage (hWnd,
                     WM_COMMAND,
                     (WPARAM) MAKELONG (iDlgItem, LBN_DBLCLK),
                     (LPARAM) hListBox);
        }
    return;
    }

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

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

    dIndex = SendDlgItemMessage (hWnd,
                                 iDlgItem,
                                 LB_FINDSTRINGEXACT,
                                 (WPARAM) -1,
                                 (LPARAM) pbText);

    if (dIndex == LB_ERR) dIndex = MAXDWORD;
    return dIndex;
    }

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

DWORD WINAPI GetListBoxText (HWND  hWnd,
                             int   iDlgItem,
                             PBYTE pbText,
                             DWORD dBytes)
    {
    PBYTE pbBuffer;
    DWORD dIndex, dSize;

    dSize = 0;

    if (dBytes)
        {
        pbText [0] = 0;

        dIndex = SendDlgItemMessage (hWnd,
                                     iDlgItem,
                                     LB_GETCURSEL,
                                     (WPARAM) 0,
                                     (LPARAM) 0);
        if (dIndex != LB_ERR)
            {
            dSize = SendDlgItemMessage (hWnd,
                                        iDlgItem,
                                        LB_GETTEXTLEN,
                                        (WPARAM) dIndex,
                                        (LPARAM) 0);

            if ((dSize != LB_ERR) || (dSize = 0))
                {
                pbBuffer = LocalAlloc (LMEM_FIXED, dSize+1);
                if (pbBuffer != NULL)
                    {
                    dSize = SendDlgItemMessage (hWnd,
                                                iDlgItem,
                                                LB_GETTEXT,
                                                (WPARAM) dIndex,
                                                (LPARAM) pbBuffer);

                    if ((dSize != LB_ERR) || (dSize = 0))
                        {
                        lstrcpyn (pbText, pbBuffer, dBytes);
                        }
                    LocalFree (pbBuffer);
                    }
                }
            }
        }
    return dSize;
    }

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

DWORD WINAPI GetListBoxData (HWND hWnd,
                             int  iDlgItem)
    {
    DWORD dIndex, dData;

    dIndex = SendDlgItemMessage (hWnd,
                                 iDlgItem,
                                 LB_GETCURSEL,
                                 (WPARAM) 0,
                                 (LPARAM) 0);
    if (dIndex != LB_ERR)
        {
        dData = SendDlgItemMessage (hWnd,
                                    iDlgItem,
                                    LB_GETITEMDATA,
                                    (WPARAM) dIndex,
                                    (LPARAM) 0);
        }
    else
        {
        dData = MAXDWORD;
        }
    return dData;
    }

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

HCURSOR WINAPI OpenListBox (HWND hWnd,
                            int  iDlgItem)
    {
    HCURSOR hCursor;

    hCursor = SetCursor (LoadCursor (NULL, IDC_WAIT));
    ClearListBox (hWnd, iDlgItem);

    SendDlgItemMessage (hWnd,
                        iDlgItem,
                        WM_SETREDRAW,
                        (WPARAM) FALSE,
                        (LPARAM) 0);
    return hCursor;
    }

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

DWORD WINAPI CloseListBox (HWND    hWnd,
                           int     iDlgItem,
                           DWORD   dSelect,
                           HCURSOR hCursor)
    {
    HWND  hListBox = GetDlgItem (hWnd, iDlgItem);
    DWORD dCount;

    SendDlgItemMessage (hWnd,
                        iDlgItem,
                        WM_SETREDRAW,
                        (WPARAM) TRUE,
                        (LPARAM) 0);

    dCount = SelectListBoxItem (hWnd, iDlgItem, dSelect);
    if (hListBox != NULL) UpdateWindow (hListBox);
    SetCursor (hCursor);
    return dCount;
    }

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

DWORD WINAPI EnumListBoxItems (HWND  hWnd,
                               int   iDlgItem,
                               PROC  Handler,
                               PVOID pData)
    {
    PBYTE pbBuffer;
    DWORD dCount, dOK, dIndex, dSize, dMaxSize;

    if (dCount = GetListBoxCount (hWnd, iDlgItem))
        {
        dMaxSize = 0;
        dOK      = 0;

        for (dIndex = 0; dIndex < dCount; dIndex++)
            {
            dSize = SendDlgItemMessage (hWnd,
                                        iDlgItem,
                                        LB_GETTEXTLEN,
                                        (WPARAM) dIndex,
                                        (LPARAM) 0);
            if (dSize != LB_ERR)
                {
                dMaxSize = max (dMaxSize, dSize);
                dOK++;
                }
            }
        if (dOK == dCount)
            {
            pbBuffer = LocalAlloc (LMEM_FIXED, ++dMaxSize);
            if (pbBuffer != NULL)
                {
                for (dIndex = 0; dIndex < dCount; dIndex++)
                    {
                    dSize = SendDlgItemMessage (hWnd,
                                                iDlgItem,
                                                LB_GETTEXT,
                                                (WPARAM) dIndex,
                                                (LPARAM) pbBuffer);
                    if (dSize != LB_ERR)
                        {
                        dOK = Handler (pbBuffer,
                                       dSize,
                                       dIndex,
                                       pData);

                        SendDlgItemMessage (hWnd,
                                            iDlgItem,
                                            LB_SETITEMDATA,
                                            (WPARAM) dIndex,
                                            (LPARAM) dOK);
                        }
                    }
                }
            }
        }
    return dCount;
    }

// =================================================================
// BROWSING
// =================================================================

DWORD WINAPI ListVolumes (HWND hWnd,
                          int  iCaption,
                          int  iListBox)
    {
    BYTE    abVolume [] = "?:";
    BYTE    abRoot   [] = "?:\\";
    HCURSOR hCursor;
    DWORD   dVolumes, dMask, dIndex, dCount;

    SetDlgItemText (hWnd, iCaption, abVolumes);

    hCursor  = OpenListBox (hWnd, iListBox);
    dMask    = 1;
    dVolumes = GetLogicalDrives ();

    for (abVolume [0] = 'A'; abVolume [0] <= 'Z'; abVolume [0]++)
        {
        if (dVolumes & dMask)
            {
            abRoot [0] = abVolume [0];

            AddListBoxItem (hWnd,
                            iListBox,
                            abVolume,
                            GetDriveType (abRoot));
            }
        dMask <<= 1;
        }
    abVolume [0] = GetDefaultVolume ();
    dIndex = FindListBoxText (hWnd, iListBox, abVolume);
    dCount = CloseListBox (hWnd, iListBox, dIndex, hCursor);

    printfDlgItem (hWnd,
                   iCaption,
                   "%lu &%s",
                   dCount,
                   (dCount == 1 ? abVolume : abVolumes));
    return dCount;
    }

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

DWORD WINAPI ListDirectories (HWND hWnd,
                              int  iCaption,
                              int  iListBox)
    {
    BYTE            abPath [MAX_PATH];
    HANDLE          hFindFile;
    WIN32_FIND_DATA FindData;
    HCURSOR         hCursor;
    DWORD           dCount;

    GetCurrentDirectory (MAX_PATH, abPath);
    SetDlgItemText (hWnd, IDT_PATH, abPath);
    SetDlgItemText (hWnd, iCaption, abDirectories);

    hCursor   = OpenListBox (hWnd, iListBox);
    hFindFile = FindFirstFile ("*", &FindData);

    while (hFindFile != INVALID_HANDLE_VALUE)
        {
        if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
            {
            if (lstrcmp (FindData.cFileName, "." ) &&
                lstrcmp (FindData.cFileName, ".."))
                {
                AddListBoxItem (hWnd,
                                iListBox,
                                FindData.cFileName,
                                MAXDWORD);
                }
            }
        if (!FindNextFile (hFindFile, &FindData))
            {
            FindClose (hFindFile);
            hFindFile = INVALID_HANDLE_VALUE;
            }
        }
    if (lstrcmp (abPath+1, ":\\"))
        {
        AddListBoxItem (hWnd, iListBox, "..", MAXDWORD);
        }
    dCount = CloseListBox (hWnd, iListBox, 0, hCursor);

    printfDlgItem (hWnd,
                   iCaption,
                   "%lu &%s",
                   dCount,
                   (dCount == 1 ? abDirectory : abDirectories));
    return dCount;
    }

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

DWORD WINAPI ListCabinets (HWND hWnd,
                           int  iCaption,
                           int  iListBox)
    {
    HANDLE          hFindFile;
    WIN32_FIND_DATA FindData;
    HCURSOR         hCursor;
    DWORD           dCount;

    SetDlgItemText (hWnd, iCaption, abCabinets);

    hCursor   = OpenListBox (hWnd, iListBox);
    hFindFile = FindFirstFile ("*", &FindData);

    while (hFindFile != INVALID_HANDLE_VALUE)
        {
        if (!(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
            {
            if (TestCabinetHeader (FindData.cFileName))
                {
                AddListBoxItem (hWnd,
                                iListBox,
                                FindData.cFileName,
                                MAXDWORD);
                }
            }
        if (!FindNextFile (hFindFile, &FindData))
            {
            FindClose (hFindFile);
            hFindFile = INVALID_HANDLE_VALUE;
            }
        }
    dCount = CloseListBox (hWnd, iListBox, 0, hCursor);

    printfDlgItem (hWnd,
                   iCaption,
                   "%lu &%s",
                   dCount,
                   (dCount == 1 ? abCabinet : abCabinets));
    return dCount;
    }

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

DWORD WINAPI ListCabinetDir (PBYTE    pbCabinet,
                             DWORD    dBytes,
                             DWORD    dIndex,
                             PLISTCTL pListCtl)
    {
    HCABINET  hCabinet;
    CAB_ENTRY ce;
    BYTE      abFile [MAX_PATH];
    DWORD     dOffset = MAXDWORD;

    if ((hCabinet = OpenCabinet (pbCabinet)) != NULL)
        {
        while (ScanCabinet (hCabinet, &ce, abFile, MAX_PATH))
            {
            if (ce.iFolder != CAB_FILE_CONTINUED)
                {
                AddListBoxItem (pListCtl->hWnd,
                                pListCtl->iListBox,
                                abFile,
                                dIndex);
                }
            }
        dOffset = CloseCabinet (hCabinet);
        }
    return dOffset;
    }

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

DWORD WINAPI ListFiles (HWND hWnd,
                        int  iCaption,
                        int  iListBox)
    {
    LISTCTL ListCtl = {hWnd, iCaption, iListBox};
    HCURSOR hCursor;
    DWORD   dCount;

    SetDlgItemText (hWnd, iCaption, abFiles);

    hCursor = OpenListBox (hWnd, iListBox);

    dCount = EnumListBoxItems (hWnd,
                               IDL_CABINETS,
                               ListCabinetDir,
                               &ListCtl);

    dCount = CloseListBox (hWnd, iListBox, 0, hCursor);

    printfDlgItem (hWnd,
                   iCaption,
                   "%lu &%s",
                   dCount,
                   (dCount == 1 ? abFile : abFiles));

⌨️ 快捷键说明

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