home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume31 / wizunzip / part05 / wizunzip.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-25  |  10.3 KB  |  257 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: WizUnzip.c
  4.  
  5.     PURPOSE:  Windows Info-ZIP Unzip, an Unzipper for Windows
  6.     FUNCTIONS:
  7.  
  8.         WinMain() - calls initialization function, processes message loop
  9.         WizUnzipInit() - initializes window data and registers window
  10.         WizUnzipWndProc() - processes messages
  11.         About() - processes messages for "About" dialog box
  12.  
  13.     AUTHOR: Robert A. Heath,  157 Chartwell Rd. Columbia, SC 29210
  14.     I place this source module, WizUnzip.c, in the public domain.  Use it as you will.
  15. ****************************************************************************/
  16.  
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <time.h>                
  20. #include <string.h>             
  21. #include "wizunzip.h"
  22.  
  23.  
  24. static char __based(__segname("STRINGS_TEXT")) szFirstUse[] = "FirstUse"; /* first use keyword in WIN.INI */
  25. char __based(__segname("STRINGS_TEXT")) szBeepOnFinish[] = "Beep";
  26. char __based(__segname("STRINGS_TEXT")) szFormatKey[] = "Format";       /* Format keyword in WIN.INI        */
  27. char __based(__segname("STRINGS_TEXT")) szOverwriteKey[] = "Overwrite"; /* Overwrite keyword in WIN.INI     */
  28. char __based(__segname("STRINGS_TEXT")) szTranslateKey[] = "Translate"; /* Translate keyword in WIN.INI     */
  29. char __based(__segname("STRINGS_TEXT")) szLBSelectionKey[] = "LBSelection"; /* LBSelection keyword in WIN.INI */
  30. char __based(__segname("STRINGS_TEXT")) szRecreateDirsKey[] = "Re-createDirs"; /* re-create directory structure WIN.INI keyword             */
  31. char __based(__segname("STRINGS_TEXT")) szUnzipToZipDirKey[] = "UnzipToZipDir"; /* unzip to .ZIP dir WIN.INI keyword */
  32. char __based(__segname("STRINGS_TEXT")) szHideStatus[] = "HideStatusWindow";
  33. char __based(__segname("STRINGS_TEXT")) szHelpFileName[] = "WIZUNZIP.HLP";
  34. char __based(__segname("STRINGS_TEXT")) szYes[] = "yes";
  35. char __based(__segname("STRINGS_TEXT")) szNo[] = "no";
  36.  
  37. /* File and Path Name variables */
  38. char __based(__segname("STRINGS_TEXT")) szAppName[] = "WizUnzip";       /* application title        */
  39. char __based(__segname("STRINGS_TEXT")) szStatusClass[] = "MsgWndw";/* status window class  */
  40.  
  41.                                                 
  42. /* Values for listbox selection WIN.INI keyword
  43.  */
  44. char * LBSelectionTable[] = {
  45.     "extract", "display", "test" 
  46. };
  47. #define LBSELECTIONTABLE_ENTRIES (sizeof(LBSelectionTable)/sizeof(char *))
  48.  
  49. HANDLE hInst;               /* current instance */
  50. HMENU  hMenu;               /* main menu handle */
  51. HANDLE hAccTable;
  52.  
  53. HANDLE hHourGlass;          /* handle to hourglass cursor        */
  54. HANDLE hSaveCursor;         /* current cursor handle         */
  55. HANDLE hHelpCursor;         /* help cursor                      */
  56. HANDLE hFixedFont;          /* handle to fixed font             */
  57. HANDLE hOldFont;            /* handle to old font               */
  58.  
  59. int hFile;                /* file handle             */
  60. HWND hWndMain;        /* the main window handle.                */
  61. HWND hWndList;            /* list box handle        */
  62. HWND hWndStatus;        /* status   (a.k.a. Messages) window */
  63. HWND hExtract;          /* extract button               */
  64. HWND hDisplay;          /*display button                */
  65. HWND hTest;             /* test button              */
  66. HWND hShowComment;          /* show comment button          */
  67.  
  68. UF  uf;
  69.  
  70. /* Global values defined by WIN.INI settings: */
  71. #if 0
  72. BOOL bHelp = FALSE;     /* Shift-F1 has been struck when TRUE       */
  73. BOOL bRecreateDirs; /* re-create directory structures when TRUE */
  74. BOOL bTranslate = FALSE;    /* translate LF to CR-LF                    */
  75. WORD wFormat = 0;       /* display format: 0 = short, 1 = long */
  76. BOOL bOverwrite = FALSE;    /* overwrite or prompt: IDM_OVERWRITE, IDM_PROMPT */
  77. BOOL bUnzipToZipDir = FALSE; /* unzip only to .ZIP directory        */
  78. BOOL bBeepOnFinish = FALSE;
  79. BOOL bDoAll;
  80. BOOL bIconSwitched = FALSE; /* set true after 1st valid action  */
  81.  
  82. BOOL bStatusMaxed = FALSE;  /* status box is maximized      */
  83. #endif
  84. WORD wLBSelection = IDM_LB_DISPLAY; /* default listbox selection action */
  85.  
  86.  
  87.  
  88. HBRUSH hBrush ;         /* brush for  standard window backgrounds  */
  89.  
  90. LPUMB   lpumb;
  91. HANDLE  hStrings;
  92.  
  93. int ofretval;       /* return value from initial open if filename given */
  94.  
  95. WORD cZippedFiles;      /* total personal records in file   */
  96. WORD cListBoxLines; /* max list box lines showing on screen */
  97. WORD cLinesMessageWin; /* max visible lines on message window  */
  98. WORD cchComment;            /* length of comment in .ZIP file   */
  99.  
  100.  
  101. /* Forward References */
  102. int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int);
  103. long FAR PASCAL WizUnzipWndProc(HWND, WORD, WORD, LONG);
  104.  
  105.  
  106. /****************************************************************************
  107.  
  108.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  109.  
  110.     PURPOSE: calls initialization function, processes message loop
  111.  
  112.     COMMENTS:
  113.  
  114.         This will initialize the window class if it is the first time this
  115.         application is run.  It then creates the window, and processes the
  116.         message loop until a WM_QUIT message is received.  It exits the
  117.         application by returning the value passed by the PostQuitMessage.
  118.  
  119. ****************************************************************************/
  120.  
  121. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  122. HANDLE hInstance;         /* current instance             */
  123. HANDLE hPrevInstance;     /* previous instance            */
  124. LPSTR lpCmdLine;          /* command line                 */
  125. int nCmdShow;             /* show-window type (open/icon) */
  126. {
  127.     int i;
  128.  
  129.  
  130.     if (!hPrevInstance)                 /* Has application been initialized? */
  131.         if (!WizUnzipInit(hInstance))
  132.             return 0;              /* Exits if unable to initialize     */
  133.  
  134.  
  135.     hStrings = GlobalAlloc( GPTR, (DWORD)sizeof(UMB));
  136.     if ( !hStrings )
  137.         return 0;
  138.  
  139.     lpumb = (LPUMB)GlobalLock( hStrings );
  140.     if ( !lpumb )
  141.     {
  142.         GlobalFree( hStrings );
  143.         return 0;
  144.     }
  145. #if 0
  146.     lpszDirName = lpszFileName + 128;
  147.     lpszOrigDirName = lpszDirName + 128;
  148.     lpszTotalsLine = lpszOrigDirName + 128;
  149.     lpszBuffer = lpszTotalsLine + 80;
  150.     lpmsg = (MSG __far *)(lpszBuffer + 256);
  151.     lpOfStruct = (OFSTRUCT __far *)(((char __far *)lpmsg) + sizeof(MSG));
  152.     lpofn = (OPENFILENAME __far *)(((char __far *)lpOfStruct) + sizeof(OFSTRUCT));
  153. #endif
  154.  
  155.     uf.fCanDragDrop = FALSE;
  156.     if (hHourGlass = GetModuleHandle("SHELL"))
  157.     {
  158.         if (GetProcAddress(hHourGlass, "DragAcceptFiles" ))
  159.             uf.fCanDragDrop = TRUE;
  160.     }
  161.     
  162.     if (_fstrlen(lpCmdLine))            /* if filename passed on start-up   */
  163.     {
  164.         if ((ofretval = OpenFile(lpCmdLine, &lpumb->of, OF_EXIST)) >= 0)
  165.         {
  166.             lstrcpy(lpumb->szFileName, lpumb->of.szPathName); /* save file name */
  167.         }
  168.     }
  169.  
  170.     /* Get initial Re-create dirs format */
  171.     GetProfileString(szAppName, szRecreateDirsKey, szNo, lpumb->szBuffer, 256);
  172.     uf.fRecreateDirs = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  173.  
  174.     /* Get translate flag */
  175.     GetProfileString(szAppName, szTranslateKey, szNo, lpumb->szBuffer, 256);
  176.     uf.fTranslate = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  177.  
  178.     /* Get initial display format: short or long */
  179.     GetProfileString(szAppName, szFormatKey, "long", lpumb->szBuffer, 256);
  180.     uf.fFormatLong = (WORD)(!lstrcmpi(lpumb->szBuffer, "long") ? 1 : 0);
  181.  
  182.     /* Get overwrite option: yes=IDM_OVERWRITE, no=IDM_PROMPT */
  183.     GetProfileString(szAppName, szOverwriteKey, szNo, lpumb->szBuffer, 256);
  184.     uf.fOverwrite = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  185.  
  186.     /* Get Unzip to .ZIP dir option: yes or no  */
  187.     GetProfileString(szAppName, szUnzipToZipDirKey, szNo, lpumb->szBuffer, 256);
  188.     uf.fUnzipToZipDir = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  189.  
  190.     /* Get Unzip to .ZIP dir option: yes or no  */
  191.     GetProfileString(szAppName, szBeepOnFinish, szNo, lpumb->szBuffer, 256);
  192.     uf.fBeepOnFinish = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  193.  
  194.     /* Get Hide Status Window option */
  195.     GetProfileString(szAppName, szHideStatus, szNo, lpumb->szBuffer, 256);
  196.     uf.fStatusHidden = (BOOL)(!lstrcmpi(lpumb->szBuffer, szYes));
  197.  
  198.     /* Get default listbox selection operation */
  199.     GetProfileString(szAppName, szLBSelectionKey, "display", lpumb->szBuffer, 256);
  200.  
  201.     for (i = 0; i < LBSELECTIONTABLE_ENTRIES &&
  202.         lstrcmpi(LBSelectionTable[i], lpumb->szBuffer) ; i++)
  203.     {
  204.         ;
  205.     }
  206.  
  207.     wLBSelection = IDM_LB_DISPLAY;      /* assume default is to display     */
  208.     if (i < LBSELECTIONTABLE_ENTRIES)
  209.         wLBSelection = IDM_LB_EXTRACT + i;
  210.  
  211.     hWndMain = CreateWindow(szAppName,  /* window class     */
  212.         szAppName,                      /* window name      */
  213.         WS_OVERLAPPEDWINDOW,            /* window style     */
  214.         0,                              /* x position       */
  215.         0,                              /* y position       */
  216.         CW_USEDEFAULT,                  /* width            */
  217.         0,                              /* height           */
  218.         (HWND)0,                        /* parent handle    */
  219.         (HWND)0,                        /* menu or child ID */
  220.         hInstance,                      /* instance         */
  221.         NULL);                          /* additional info  */
  222.  
  223.     if ( !hWndMain )
  224.         return 0;
  225.  
  226.     /* On first use, throw up About box, saying what WizUnzip is, etc.
  227.      */
  228.     GetProfileString(szAppName, szFirstUse, szYes, lpumb->szBuffer, 256);
  229.     if (!lstrcmpi(lpumb->szBuffer, szYes))
  230.     {
  231.         WriteProfileString(szAppName, szFirstUse, szNo);
  232.         PostMessage(hWndMain, WM_COMMAND, IDM_ABOUT, 0L);
  233.     }
  234.     hHelpCursor = LoadCursor(hInstance, "HelpCursor");
  235.  
  236.     ShowWindow(hWndMain, nCmdShow);
  237.     UpdateWindow(hWndMain);
  238.  
  239.     while ( GetMessage(&lpumb->msg, 0, 0, 0) )
  240.     {
  241.         if ( !TranslateAccelerator(hWndMain, hAccTable, &lpumb->msg) )
  242.         {
  243.             TranslateMessage(&lpumb->msg);
  244.             DispatchMessage(&lpumb->msg);
  245.         }
  246.     }
  247.     /* Don't turn on compiler aliasing or C7 will move */
  248.     /* the following assignment after the GlobalFree() */
  249.     /* which contains the memory for pumb! */
  250.     i = (int)lpumb->msg.wParam;
  251.  
  252.     GlobalUnlock( hStrings );
  253.     GlobalFree( hStrings );
  254.  
  255.     return i;
  256. }
  257.