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

📄 wndproc.c

📁 有关zip的一个开发实例。主要包括图片和程序源代码。
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Windows Info-ZIP Window Procedure, wndproc.c. * Author: Robert A. Heath, 157 Chartwell Rd., Columbia, SC 29210 * I, Robert Heath, place this source code module in the public domain. * * Modifications: 1995, 1996 M. White */#include <sys/types.h>#include <sys/stat.h>#include <time.h>#include <string.h>#include <stdio.h>#include <ctype.h>#ifdef __BORLANDC__#  include <dir.h>#else#  include <direct.h>#endif#include "wiz.h"#include "helpids.h"/* For a some reason I haven't bothered to try to figure out * shellapi.h must follow wiz.h */#include <shellapi.h>FARPROC lpOldEditProc;extern LRESULT CALLBACK SubClassEditProc(HWND, WORD, WPARAM, LPARAM);char LongFileTrailer[] =     "%7lu  %7lu %4s                    %u file%s";char ShortFileTrailer[] = "%7lu                    %u file%s";char Far HeadersShort[]  = " Length    Date    Time    Name";char Far HeadersLong[]  =  " Length     Size Ratio   Date     Time   Name";char Far *Headers[] = {HeadersShort, HeadersLong};char szTotalsLine[80];              /* text for totals of zip archive */BOOL fUpdateEntries, bSizing = FALSE, bMouseButtonDown = FALSE;OPENFILENAME ofnTemp; /* Open file name structure for edit box save and open *//* Forward Refs */void GetDirectory(LPSTR lpDir);void GetHelpContext(WPARAM wParam);extern LPUSERFUNCTIONS lpUserFunctions;HWND hPatternSelectDlg; /* pattern select modeless dialog   */static UINT uCommDlgHelpMsg;   /* common dialog help message ID */DWORD dwCommDlgHelpId = HELPID_HELP; /* what to pass to WinHelp() */char szFormatKeyword[2][6] = { "short", "long" };static BOOL move_flag = FALSE;static BOOL rename_flag = FALSE;DWORD dwHelpContextId;LPSTR lpchLast;#ifndef WIN32/* Trailers are the lines just above the totals */static char * __based(__segname("STRINGS_TEXT")) szTrailers[2] = {" ------                    -------","-------  -------  ---                    -------"} ;#endifstatic char __based(__segname("STRINGS_TEXT")) szCantChDir[] =   "Internal error: Cannot change directory. Common dialog error code is 0x%lX.";/* size of char in SYSTEM font in pixels */#ifndef WIN32short dxChar, dyChar;#elselong dxChar, dyChar;#endif/*       This will allow you to perform a hit test on a line in the         list box, however, you then tend to lose the concept of being         able to do ctrl-mouse click and undo selections. It wasn't         important enough to spend any more time fooling with.*/#if 0void MapCursorToListItem(void);void MapCursorToListItem(void){DWORD          dwpos;LV_HITTESTINFO lvhti;UINT           state;LV_ITEM        lvi;int            iItemClicked;if (ListView_GetItemCount(hWndList))   {   /* Find out where the cursor was */   dwpos = GetMessagePos();   lvhti.pt.x = LOWORD(dwpos);   lvhti.pt.y = HIWORD(dwpos);   MapWindowPoints(HWND_DESKTOP, hWndList, &lvhti.pt, 1);   state = lvhti.pt.x;   lvhti.pt.x = 0;   /* Now do a hittest with this point. We keep testing so we can      find out if the mouse click was anywhere on the row.    */   while (((iItemClicked = ListView_HitTest(hWndList, &lvhti)) < 0) &&         (lvhti.pt.x < (int)state))         {         lvhti.pt.x++;         }   /* Okay, have we clicked on a live item? */   if (lvhti.flags & LVHT_ONITEM)      {      lvi.mask      = LVIF_STATE;      lvi.stateMask = LVIS_SELECTED | LVIS_FOCUSED;      lvi.iItem     = iItemClicked;      lvi.iSubItem  = 0;      ListView_GetItem(hWndList, &lvi);      if (lvi.state & LVIS_SELECTED)         lvi.state = 0;      else         lvi.state = LVIS_SELECTED | LVIS_FOCUSED;      ListView_SetItem(hWndList, &lvi);      }   }}#endifLPSTR lstrrchr(LPSTR lpszSrc, char chFind){LPSTR   lpszFound = (LPSTR)0;LPSTR   lpszT;if ( lpszSrc )   {   for (lpszT = lpszSrc; *lpszT; ++lpszT)       {       if ((*lpszT) == chFind)          lpszFound = lpszT;       }   }return lpszFound;}/* Copy only the path portion of current file name into * given buffer, lpszDestDir, translate into ANSI. */void GetArchiveDir(LPSTR lpszDestDir){LPSTR lpchLast;/* strip off filename to make directory name    */lstrcpy(lpszDestDir, lpumb->szFileName);if ((lpchLast = lstrrchr(lpszDestDir, '\\'))!=0)   *lpchLast = '\0';else if ((lpchLast = lstrrchr(lpszDestDir, ':'))!=0)   *(++lpchLast) = '\0'; /* clobber char AFTER the colon! */}void GetDirectory(LPSTR lpDir){LPSTR lpchLast;/* If no '\\' then set directory name to "" */if ((lpchLast = lstrrchr(lpDir, '\\')) == 0)   {   lpDir[0] = '\0';   return;   }/* strip off filename to make directory name    */if ((lpchLast = lstrrchr(lpDir, '\\'))!=0)   *lpchLast = '\0';else if ((lpchLast = lstrrchr(lpDir, ':'))!=0)   *(++lpchLast) = '\0'; /* clobber char AFTER the colon! */}/* * FUNCTION: SetCaption(HWND hWnd) * PURPOSE: Set new caption for main window */voidSetCaption(HWND hWnd){#define SIMPLE_NAME_LEN 15static BOOL FirstTime = TRUE;WORD wMenuState;char szSimpleFileName[SIMPLE_NAME_LEN+1];  /* just the 8.3 part in ANSI char set */LPSTR lpszFileNameT;        /* pointer to simple filename               */BOOL    fIconic = IsIconic(hWnd);   /* is window iconic ?   */BOOL fWndEnabled; /* Is button to be enabled? *//* point to simple filename in OEM char set */if ((((lpszFileNameT = lstrrchr(lpumb->szFileName, '\\'))!=0) ||   ((lpszFileNameT = lstrrchr(lpumb->szFileName, ':')))!=0))   lpszFileNameT++;else   lpszFileNameT = lpumb->szFileName;#ifndef WIN32_fstrncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);#elsestrncpy(szSimpleFileName, lpszFileNameT, SIMPLE_NAME_LEN);#endifszSimpleFileName[SIMPLE_NAME_LEN] = '\0'; /* force termination */wMenuState = (WORD)(szSimpleFileName[0] ? MF_ENABLED : MF_GRAYED);fWndEnabled = (BOOL) (szSimpleFileName[0] ? TRUE : FALSE);/* Enable/Disable menu items */EnableMenuItem(hMenu, IDM_SELECT_ALL, wMenuState|MF_BYCOMMAND);EnableMenuItem(hMenu, IDM_DESELECT_ALL, wMenuState|MF_BYCOMMAND);EnableMenuItem(hMenu, IDM_SELECT_BY_PATTERN, wMenuState|MF_BYCOMMAND);/* Enable/Disable buttons */if (!FirstTime)   {   WinAssert(hSelectAll);   EnableWindow( hSelectAll, fWndEnabled);   WinAssert(hDeselectAll);   EnableWindow( hDeselectAll, fWndEnabled);   WinAssert(hSelectPattern);   EnableWindow( hSelectPattern, fWndEnabled);   }if ((lstrlen(szUnzipToDirName) == 2) && (szUnzipToDirName[1] == ':') &&   szSimpleFileName[0])   {   lstrcpy(szUnzipToDirName, lpumb->szFileName);   if ((lpszFileNameT = lstrrchr(szUnzipToDirName, '\\'))!=0)      lpszFileNameT[0] = '\0';   if (lstrlen(szUnzipToDirName) == 2)      lstrcat(szUnzipToDirName, "\\");   }if (!szSimpleFileName[0])   lstrcpy(szSimpleFileName, "No Zip File");wsprintf(lpumb->szBuffer, "%s - %s %s %s",               (LPSTR)szAppName,               (LPSTR)(szSimpleFileName),               (LPSTR)(!fIconic && szUnzipToDirName[0] ? " - " : ""),               (LPSTR)(!fIconic ? szUnzipToDirName : ""));SetWindowText(hWnd, lpumb->szBuffer);FirstTime = FALSE;}/* * FUNCTION: WiZWndMainProc(HWND, unsigned, WORD, LONG) * * PURPOSE:  Processes messages * * MESSAGES: * * WM_DESTROY      - destroy window * WM_SIZE         - window size has changed * WM_QUERYENDSESSION - willing to end session? * WM_ENDSESSION   - end Windows session * WM_CLOSE        - close the window * WM_SIZE         - window resized * WM_PAINT        - windows needs to be painted * WM_DROPFILES    - open a dropped file * COMMENTS: * WM_COMMAND processing: *    IDM_OPEN -  open a new file. *    IDM_EXIT -  exit. *    IDM_ABOUT - display "About" box. */LRESULT WINAPI WiZMainWndProc(HWND hWnd, WORD wMessage, WPARAM wParam, LPARAM lParam){HDC hDC;                /* device context       */TEXTMETRIC    tm;           /* text metric structure    */char drive;#ifndef WIN32FARPROC lpfnAbout, lpfnSelectDir;#endifchar *ptr;switch (wMessage)    {    case WM_CREATE: /* create  window       */      hInst = ((LPCREATESTRUCT)lParam)->hInstance;      hAccTable = LoadAccelerators(hInst, "WiZAccels");      hBrush = CreateSolidBrush(GetSysColor(BG_SYS_COLOR)); /* background */      hMenu = GetMenu(hWnd);      /* Get an hourglass cursor to use during file transfers */      hHourGlass = LoadCursor(0, IDC_WAIT);      hFixedFont = GetStockObject(ANSI_FIXED_FONT);      hDC = GetDC(hWnd);  /* get device context */      hOldFont = SelectObject(hDC, hFixedFont);      GetTextMetrics(hDC, &tm);      ReleaseDC(hWnd, hDC);      dxChar = tm.tmAveCharWidth;      dyChar = tm.tmHeight + tm.tmExternalLeading + tm.tmInternalLeading;      WinAssert(hWnd);#ifndef WIN32      hWndList = CreateWindow("listbox", NULL,                        WS_CHILD|WS_DLGFRAME|WS_VSCROLL|LBS_NOTIFY|                        LBS_EXTENDEDSEL|ES_NOHIDESEL,                        0, 0,                        0, 0,                        hWnd, (HMENU)IDM_LISTBOX,                        GetWindowWord (hWnd, GWW_HINSTANCE), NULL);#else      hWndList = CreateWindow(WC_LISTVIEW, NULL,                        WS_CHILD | WS_DLGFRAME |                        LVS_REPORT | LVS_SHOWSELALWAYS |                        LVS_SORTASCENDING,                        0, 0,                        0, 0,                        hWnd, (HMENU)IDM_LISTBOX,                        (HANDLE)GetWindowLong (hWnd, GWL_HINSTANCE), NULL);#endif      WinAssert(hWndList);      SendMessage(hWndList, WM_SETFONT, (WPARAM)hFixedFont, FALSE);      WinAssert(hWnd);#ifdef WIN32      {      LV_COLUMN lvc;      int       iCol;      char      szText[6][20]= {"Name", "Orig Size", "Comp Size","Ratio","  Date",                  "Time"};      /* Initialize the LV_COLUMN structure. */      lvc.mask    = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;      lvc.fmt     = LVCFMT_LEFT;      lvc.cx      = 95;      for (iCol = 0; iCol < 6; iCol++)          {          lvc.pszText = szText[iCol];          lvc.iSubItem = iCol;          if (ListView_InsertColumn(hWndList, iCol, &lvc) == -1)              return FALSE;          }      ListView_SetColumnWidth(hWndList, 0, MAKELPARAM((int)30*dxChar, 0));      ListView_SetColumnWidth(hWndList, 1, MAKELPARAM((int)11*dxChar, 0));      ListView_SetColumnWidth(hWndList, 2, MAKELPARAM((int)11*dxChar, 0));      ListView_SetColumnWidth(hWndList, 3, MAKELPARAM((int)7*dxChar, 0));      ListView_SetColumnWidth(hWndList, 4, MAKELPARAM((int)10*dxChar, 0));      ListView_SetColumnWidth(hWndList, 5, MAKELPARAM((int)7*dxChar, 0));      }#endif /* WIN32 */#ifndef WIN32      hWndStatic = CreateWindow("StaticClass", "WiZ Edit/Status Window",                            WS_OVERLAPPEDWINDOW|WS_SIZEBOX,                            0, 0,                            0, 0,                            hWnd,

⌨️ 快捷键说明

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