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

📄 winmain.cpp

📁 zip压缩
💻 CPP
📖 第 1 页 / 共 5 页
字号:
         if (pFile1->dwModified != pFile2->dwModified) {            result = ((pFile1->dwModified > pFile2->dwModified) ? -1 : 1);         }         break;      case 4: // Attributes - String Sort         result = _tcscmp(BuildAttributesString(szBuffer1, pFile1->dwAttributes),                          BuildAttributesString(szBuffer2, pFile2->dwAttributes));         break;      case 5: // Compressed Size - Smallest to Largest         if (pFile1->dwCompressedSize != pFile2->dwCompressedSize) {            result = ((pFile1->dwCompressedSize < pFile2->dwCompressedSize) ? -1 : 1);         }         break;      case 6: // Ratio - Smallest to Largest         int factor1, factor2;         factor1 = ratio(pFile1->dwSize, pFile1->dwCompressedSize);         factor2 = ratio(pFile2->dwSize, pFile2->dwCompressedSize);         result = factor1 - factor2;         break;      case 7: // Method - String Sort         result = _stricmp(pFile1->szPathAndMethod + strlen(pFile1->szPathAndMethod) + 1,                           pFile2->szPathAndMethod + strlen(pFile2->szPathAndMethod) + 1);         break;      case 8: // CRC - Smallest to Largest         if (pFile1->dwCRC != pFile2->dwCRC) {            result = ((pFile1->dwCRC < pFile2->dwCRC) ? -1 : 1);         }         break;      case 9: // Comment - String Sort         result = _stricmp(pFile1->szComment ? pFile1->szComment : "",                           pFile2->szComment ? pFile2->szComment : "");         break;   }   // If the sort resulted in a tie, we use the name to break the tie.   if (result == 0) {      result = _stricmp(pFile1->szPathAndMethod, pFile2->szPathAndMethod);   }   return result;}//******************************************************************************//***** Helper/Utility Functions//******************************************************************************void SetCaptionText(LPCTSTR szPrefix) {   TCHAR szCaption[_MAX_PATH + 32];   if (szPrefix) {      _stprintf(szCaption, TEXT("%s - "), szPrefix);   } else {      *szCaption = 0;   }   if (*g_szZipFile) {      size_t lenPrefix = _tcslen(szCaption);      MBSTOTSTR(szCaption + lenPrefix, GetFileFromPath(g_szZipFile),                countof(szCaption) - lenPrefix);   } else {      _tcscat(szCaption, TEXT("Pocket UnZip"));   }   SetWindowText(g_hWndMain, szCaption);}//******************************************************************************void DrawBanner(HDC hdc) {   // If we were not passed in a DC, then get one now.   BOOL fReleaseDC = FALSE;   if (!hdc) {      hdc = GetDC(g_hWndMain);      fReleaseDC = TRUE;   }   // Compute the banner rectangle.   RECT rc;   GetClientRect(g_hWndMain, &rc);   rc.top += g_cyCmdBar;   rc.bottom = rc.top + 22;   // Fill in the background with a light grey brush.   FillRect(hdc, &rc, (HBRUSH)GetStockObject(LTGRAY_BRUSH));   // Draw a highlight line across the top of our banner.   POINT pt[2] = { { rc.left, rc.top + 1 }, { rc.right, rc.top + 1 } };   SelectObject(hdc, GetStockObject(WHITE_PEN));   Polyline(hdc, pt, 2);   // Get the ZIP file image.  We do this only once and cache the result.   // Note that you do not need to free icons as they are a resource.   static HICON hIcon = NULL;   if (!hIcon) {      hIcon = (HICON)LoadImage(g_hInst, MAKEINTRESOURCE(IDI_ZIPFILE),                               IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);   }   // Draw the ZIP file image.   DrawIconEx(hdc, rc.left + 6, rc.top + 3, hIcon, 16, 16, 0, NULL, DI_NORMAL);   // Set our font and colors.   HFONT hFontStock = (HFONT)SelectObject(hdc, g_hFontBanner);   SetTextColor(hdc, RGB(0, 0, 0));   SetBkMode(hdc, TRANSPARENT);   rc.left   += 26;   rc.right  -= 48;   rc.bottom -=  2;   // Decide what text to display.   TCHAR szPath[_MAX_PATH + 16];   if (g_hWndWaitFor) {      _tcscpy(szPath, TEXT("Initializing..."));   } else if (*g_szZipFile) {      if (g_fLoading) {#ifdef UNICODE         _stprintf(szPath, TEXT("Loading %S"), g_szZipFile);#else         _stprintf(szPath, TEXT("Loading %s"), g_szZipFile);#endif      } else {         MBSTOTSTR(szPath, g_szZipFile, countof(szPath));      }   } else {      _tcscpy(szPath, TEXT("No File Loaded"));   }   // Draw the banner text.   DrawText(hdc, szPath, _tcslen(szPath), &rc,            DT_NOPREFIX | DT_SINGLELINE | DT_LEFT | DT_VCENTER);   // Remove all non stock objects from the DC   SelectObject(hdc, hFontStock);   // Free our DC if we created it.   if (fReleaseDC) {      ReleaseDC(g_hWndMain, hdc);   }}//******************************************************************************void AddDeleteColumns() {   static int curColumns = 0;   int column, newColumns = (g_fExpandedView ? countof(g_columns) : 4);   // Are we adding columns?   if (newColumns > curColumns) {      // Set up column structure.      TCHAR szColumn[32];      LV_COLUMN lvc;      lvc.mask = LVCF_TEXT | LVCF_FMT;      lvc.pszText = szColumn;      // Loop through each column we need to add.      for (column = curColumns; column < newColumns; column++) {         // Build the real column string.         _stprintf(szColumn, (g_columns[column].format == LVCFMT_LEFT) ?                   TEXT("%s   ") : TEXT("   %s"), g_columns[column].szName);         // Insert the column with the correct format.         lvc.fmt = g_columns[column].format;         ListView_InsertColumn(g_hWndList, column, &lvc);      }   // Otherwise, we are removing columns.   } else {      // Loop through each column we need to delete and delete them.      for (column = curColumns - 1; column >= newColumns; column--) {         ListView_DeleteColumn(g_hWndList, column);      }   }   // Store our new column count statically to help us with the next call to   // AddDeleteColumns().   curColumns = newColumns;   // Re-calcualte our column widths.   ResizeColumns();}//******************************************************************************void ResizeColumns() {   // Hide the window since we are going to be doing some column shifting.   ShowWindow(g_hWndList, SW_HIDE);   // Resize all the columns to best fit both the column data and the header.   for (int column = 0; column < countof(g_columns); column++) {      ListView_SetColumnWidth(g_hWndList, column, LVSCW_AUTOSIZE_USEHEADER);   }   // Show the window again.   ShowWindow(g_hWndList, SW_SHOW);}//******************************************************************************LPCTSTR GetZipErrorString(int error) {   switch (error) {      case PK_OK: // no error         return TEXT("Operation completed successfully.");      case PK_WARN: // warning error         return TEXT("There were warnings during the operation.");      case PK_ERR:    // error in zipfile      case PK_BADERR: // severe error in zipfile         return TEXT("The operation could not be successfully completed.  ")                TEXT("Possible causes are that the ZIP file contains errors, ")                TEXT("or that an error occurred while trying to create a ")                TEXT("directory or file.");      case PK_MEM:  // insufficient memory      case PK_MEM2: // insufficient memory      case PK_MEM3: // insufficient memory      case PK_MEM4: // insufficient memory      case PK_MEM5: // insufficient memory         return TEXT("There is not enough memory to perform the operation.  ")                TEXT("Try closing other running applications or adjust your ")                TEXT("memory configuration.");      case PK_NOZIP: // zipfile not found or corrupt.         return TEXT("The ZIP file either contains errors or could not be found.");      case PK_PARAM: // bad or illegal parameters specified         break; // Not used in the Windows CE port.      case PK_FIND: // no files found in ZIP file         return TEXT("The ZIP file contains errors that prevented the ")                TEXT("operation from completing successfully.  A possible ")                TEXT("cause is that one or more of the files listed as being ")                TEXT("in the ZIP file could not actually be found within the ")                TEXT("ZIP file itself.");      case PK_DISK: // disk full or file locked         return TEXT("An error occurred while attempting to save a file.  ")                TEXT("Possible causes are that your file storage is full or ")                TEXT("read only, or that a file with the same name already ")                TEXT("exists and is locked by another application.");      case PK_EOF: // unexpected end of file         return TEXT("The ZIP file contains errors that prevented the ")                TEXT("operation from completing successfully.  A possible ")                TEXT("cause is that your ZIP file is incomplete and might be ")                TEXT("truncated.");      case IZ_UNSUP:  // no files found: all unsup. compr/encrypt.         return TEXT("None of the files could be processed because they were ")                TEXT("all compressed using an unsupported compression or ")                TEXT("encryption algorithm.");      case IZ_BADPWD: // no files found: all had bad password.         return TEXT("None of the files could be processed because all the ")                TEXT("password(s) specified were incorrect.");      case PK_EXCEPTION: // exception occurred         return TEXT("An internal error occurred.  Possible causes are that ")                TEXT("you are out of memory, you are out of file storage ")                TEXT("space, the ZIP file contains unexpected errors, or there ")                TEXT("is a bug in our program (that's why it's free).");      case IZ_CTRLC:  // canceled by user's interaction      case PK_ABORTED: // user aborted         return TEXT("The operation was aborted.");   }   return TEXT("An unknown error occurred while processing the ZIP file.");}//******************************************************************************void AddFileToListView(FILE_NODE *pFile) {   // Set up our List View Item structure.   LV_ITEM lvi;   ZeroMemory(&lvi, sizeof(lvi));   lvi.mask    = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM;   lvi.pszText = LPSTR_TEXTCALLBACK;   lvi.lParam  = (LPARAM)pFile;   lvi.iImage  = IMAGE_GENERIC;   // Special case Volume Labels.   if (pFile->dwAttributes & ZFILE_ATTRIBUTE_VOLUME) {      pFile->szType = "Volume Label";      lvi.iImage = IMAGE_VOLUME;   // Special case folders.   } else if (pFile->dwAttributes & FILE_ATTRIBUTE_DIRECTORY) {      pFile->szType = "Folder";      lvi.iImage = IMAGE_FOLDER;   // Do a lookup on the file extension.   } else {      // Locate the file portion of our path.      LPCSTR pszFile = GetFileFromPath(pFile->szPathAndMethod);      // Find the extension portion of our file.      LPCSTR pszExt = MBSRCHR(pszFile, '.');      // Search our known extension list for this extension.      if (pszExt && *(pszExt + 1)) {         // Loop through our linked list         for (FILE_TYPE_NODE *pft = g_pftHead; pft; pft = pft->pNext) {            // Check for a match.            if (!_stricmp(pszExt + 1, pft->szExtAndDesc)) {               // We found a match, store the image and type string and exit loop.               lvi.iImage = pft->image;               pFile->szType = pft->szExtAndDesc + strlen(pft->szExtAndDesc) + 1;               if (!*pFile->szType) {                  pFile->szType = NULL;               }               break;            }         }      }   }   // Add the item to our list.   ListView_InsertItem(g_hWndList, &lvi);}//******************************************************************************void EnableAllMenuItems(UINT uMenuItem, BOOL fEnabled) {#ifdef _WIN32_WCE   HMENU hMenu = CommandBar_GetMenu(g_hWndCmdBar, 0);#else   HMENU hMenu = GetMenu(g_hWndMain);#endif   EnableMenuItem(hMenu, uMenuItem, fEnabled ? MF_ENABLED : MF_GRAYED);   SendMessage(g_hWndCmdBar, TB_ENABLEBUTTON, uMenuItem, MAKELONG(fEnabled, 0));}//******************************************************************************void CheckAllMenuItems(UINT uMenuItem, BOOL fChecked) {#ifdef _WIN32_WCE   HMENU hMenu = CommandBar_GetMenu(g_hWndCmdBar, 0);#else   HMENU hMenu = GetMenu(g_hWndMain);#endif   CheckMenuItem(hMenu, uMenuItem, fChecked ? MF_CHECKED : MF_UNCHECKED);   SendMessage(g_hWndCmdBar, TB_PRESSBUTTON, uMenuItem, MAKELONG(fChecked, 0));}//******************************************************************************void CenterWindow(HWND hWnd) {   RECT rc, rcParent;   // Get our window rectangle.   GetWindowRect(hWnd, &rc);   // Get our parent's window rectangle.   GetWindowRect(GetParent(hWnd), &rcParent);   // Center our window over our parent's window.   SetWindowPos(hWnd, NULL,      rcParent.left + ((rcParent.right  - rcParent.left) - (rc.right  - rc.left)) / 2,      rc

⌨️ 快捷键说明

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