home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 22 / CD_ASCQ_22_0695.iso / win / prg / zipserv / ddezip.fr_ / ddezip.fr
Text File  |  1995-01-29  |  17KB  |  564 lines

  1. VERSION 2.00
  2. Begin Form ZipForm 
  3.    AutoRedraw      =   -1  'True
  4.    BackColor       =   &H00C0C0C0&
  5.    BorderStyle     =   3  'Fixed Double
  6.    Caption         =   "Compression Plus Quick Demo"
  7.    ClientHeight    =   2448
  8.    ClientLeft      =   1020
  9.    ClientTop       =   1476
  10.    ClientWidth     =   7248
  11.    Height          =   2868
  12.    Icon            =   DDEZIP.FRX:0000
  13.    Left            =   972
  14.    LinkMode        =   1  'Source
  15.    LinkTopic       =   "ZipForm"
  16.    ScaleHeight     =   2448
  17.    ScaleWidth      =   7248
  18.    Top             =   1104
  19.    Width           =   7344
  20.    Begin SSCheck KeepDate 
  21.       Caption         =   "&Keep Date"
  22.       Font3D          =   0  'None
  23.       Height          =   276
  24.       Left            =   5256
  25.       TabIndex        =   19
  26.       Top             =   288
  27.       Width           =   1788
  28.    End
  29.    Begin TextBox txtComment 
  30.       Height          =   324
  31.       Left            =   1092
  32.       TabIndex        =   17
  33.       Text            =   " "
  34.       Top             =   1224
  35.       Width           =   3936
  36.    End
  37.    Begin CommandButton HideButton 
  38.       Caption         =   "&Hide"
  39.       Height          =   396
  40.       Left            =   7092
  41.       TabIndex        =   16
  42.       Top             =   1884
  43.       Width           =   972
  44.    End
  45.    Begin SSCheck Overwrite 
  46.       Caption         =   "&Overwrite existing"
  47.       Enabled         =   0   'False
  48.       Font3D          =   0  'None
  49.       Height          =   312
  50.       Left            =   1776
  51.       TabIndex        =   14
  52.       Top             =   2052
  53.       Width           =   1644
  54.    End
  55.    Begin SSCheck Hidden 
  56.       Caption         =   "&Hidden Process"
  57.       Font3D          =   0  'None
  58.       Height          =   312
  59.       Left            =   1788
  60.       TabIndex        =   13
  61.       Top             =   1632
  62.       Value           =   -1  'True
  63.       Width           =   1524
  64.    End
  65.    Begin TextBox Password 
  66.       Height          =   312
  67.       HelpContextID   =   37
  68.       Left            =   5292
  69.       PasswordChar    =   "#"
  70.       TabIndex        =   12
  71.       Top             =   1092
  72.       Width           =   1752
  73.    End
  74.    Begin SSCheck StorePath 
  75.       Caption         =   "&Store path"
  76.       Font3D          =   0  'None
  77.       Height          =   276
  78.       Left            =   5256
  79.       TabIndex        =   11
  80.       Top             =   516
  81.       Width           =   1788
  82.    End
  83.    Begin SSCheck chkPassword 
  84.       Caption         =   "Pass&word"
  85.       Font3D          =   0  'None
  86.       Height          =   288
  87.       Left            =   5256
  88.       TabIndex        =   10
  89.       Top             =   732
  90.       Width           =   1788
  91.    End
  92.    Begin CSOptList optTask 
  93.       Alignment       =   0  'Left
  94.       BorderEffect    =   0  'None
  95.       BorderStyle     =   1  'Fixed Single
  96.       Caption         =   "Task"
  97.       Contents        =   DDEZIP.FRX:0302
  98.       FontBold        =   -1  'True
  99.       FontItalic      =   0   'False
  100.       FontName        =   "MS Sans Serif"
  101.       FontSize        =   "6.5"
  102.       FontStrikethru  =   0   'False
  103.       FontUnderline   =   0   'False
  104.       Height          =   888
  105.       ItemAlignment   =   0  'Left
  106.       ItemFontBold    =   -1  'True
  107.       ItemFontItalic  =   0   'False
  108.       ItemFontName    =   "MS Sans Serif"
  109.       ItemFontSize    =   "6.5"
  110.       ItemFontStrikethru=   0   'False
  111.       ItemFontUnderline=   0   'False
  112.       ItemForeColor   =   &H00000000&
  113.       Left            =   5280
  114.       LeftMargin      =   240
  115.       ListIndex       =   0
  116.       ShadowColor     =   &H00808080&
  117.       Spacing         =   240
  118.       TabIndex        =   9
  119.       ThreeD          =   -1  'True
  120.       Top             =   1488
  121.       TopMargin       =   300
  122.       Width           =   1764
  123.    End
  124.    Begin SSCheck Recursive 
  125.       Caption         =   "&Recurse"
  126.       Font3D          =   0  'None
  127.       Height          =   312
  128.       Left            =   5244
  129.       TabIndex        =   8
  130.       Top             =   36
  131.       Width           =   1788
  132.    End
  133.    Begin TextBox Text3 
  134.       Height          =   324
  135.       Left            =   1104
  136.       TabIndex        =   6
  137.       Text            =   " "
  138.       Top             =   852
  139.       Width           =   3936
  140.    End
  141.    Begin TextBox Text2 
  142.       Height          =   324
  143.       Left            =   1104
  144.       TabIndex        =   5
  145.       Text            =   " "
  146.       Top             =   492
  147.       Width           =   3936
  148.    End
  149.    Begin TextBox Text1 
  150.       Height          =   324
  151.       Left            =   1104
  152.       TabIndex        =   3
  153.       Text            =   " "
  154.       Top             =   144
  155.       Width           =   3936
  156.    End
  157.    Begin CommandButton Command1 
  158.       Caption         =   "E&xit"
  159.       Height          =   855
  160.       Left            =   3492
  161.       TabIndex        =   1
  162.       Top             =   1584
  163.       Width           =   1575
  164.    End
  165.    Begin CommandButton btnExecute 
  166.       Caption         =   "&Execute"
  167.       Enabled         =   0   'False
  168.       Height          =   855
  169.       Left            =   108
  170.       TabIndex        =   0
  171.       Top             =   1596
  172.       Width           =   1575
  173.    End
  174.    Begin Label Label4 
  175.       BackStyle       =   0  'Transparent
  176.       Caption         =   "Comment"
  177.       Height          =   240
  178.       Left            =   96
  179.       TabIndex        =   18
  180.       Top             =   1260
  181.       Width           =   972
  182.    End
  183.    Begin Label DDELabel 
  184.       Caption         =   "Label1"
  185.       Height          =   816
  186.       Left            =   7080
  187.       TabIndex        =   15
  188.       Top             =   132
  189.       Visible         =   0   'False
  190.       Width           =   5124
  191.    End
  192.    Begin Label Label3 
  193.       BackStyle       =   0  'Transparent
  194.       Caption         =   "Destination"
  195.       Height          =   240
  196.       Left            =   120
  197.       TabIndex        =   7
  198.       Top             =   900
  199.       Width           =   972
  200.    End
  201.    Begin Label Label2 
  202.       BackStyle       =   0  'Transparent
  203.       Caption         =   "Files to ZIP"
  204.       Height          =   240
  205.       Left            =   132
  206.       TabIndex        =   4
  207.       Top             =   552
  208.       Width           =   972
  209.    End
  210.    Begin Label Label1 
  211.       BackStyle       =   0  'Transparent
  212.       Caption         =   "ZIP file:"
  213.       Height          =   216
  214.       Left            =   132
  215.       TabIndex        =   2
  216.       Top             =   168
  217.       Width           =   972
  218.    End
  219. End
  220. Option Explicit
  221. Declare Function FindWindow% Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any)
  222. Declare Function ShowWindow% Lib "User" (ByVal hWnd%, ByVal nCmdShow%)
  223. Declare Function APISetFocus% Lib "User" Alias "SetFocus" (ByVal Handle As Integer)
  224. Declare Function GetWindow% Lib "User" (ByVal hWnd%, ByVal wCmd%)
  225. Const SW_HIDE = 0
  226. Const SW_RESTORE = 9
  227. Const GW_OWNER = 4
  228. Dim OwnerHandle%, ZipComment$
  229.  
  230. Sub btnExecute_Click ()
  231.     Select Case optTask.ListIndex
  232.        Case 0
  233.           btnZip_Click
  234.        Case 1
  235.           btnUnzip_Click
  236.     End Select
  237. End Sub
  238.  
  239. Sub btnUnzip_Click ()
  240.     Dim ZipFileName$, FileToUnZip$, Destination$, RestorePath As Integer, Passwrd As String
  241.     ZipFileName$ = Text1
  242.     FileToUnZip$ = "*.*"
  243.     Destination$ = Text3
  244.     RestorePath = StorePath
  245.     Passwrd = IIf(chkPassword = True, Trim(Password), "")
  246.     Unzip_It ZipFileName$, Destination$, FileToUnZip$, RestorePath, Passwrd
  247. End Sub
  248.  
  249. Sub btnZip_Click ()
  250.     Dim ZipFileName$, KepDate As Integer, StorPath As Integer, Passwrd As String, Recurse As Integer
  251.     ReDim FilesToZip$(1 To 1)
  252.     ZipFileName$ = Text1
  253.     FilesToZip$(1) = Text2
  254.     KepDate = KeepDate
  255.     StorPath = StorePath
  256.     Recurse = Recursive
  257.     Passwrd = IIf(chkPassword = True, Trim(Password), "")
  258.     Zip_It ZipFileName$, FilesToZip$(), KepDate, StorPath, Recurse, Passwrd
  259. End Sub
  260.  
  261. Sub chkPassword_Click (Value As Integer)
  262.     If Value Then
  263.        Password.Visible = True
  264.     Else
  265.        Password.Visible = False
  266.     End If
  267. End Sub
  268.  
  269. Sub Command1_Click ()
  270.     End
  271. End Sub
  272.  
  273. 'Provide DDE Server functions through a single
  274. 'hidden label control on DDEForm in HIDE_DDE.EXE:
  275. Sub DDELabel_Change ()
  276.     Dim DDEInstruction$, DDEResponse$, start&
  277.     'This procedure gets *and* sets the Caption property,
  278.     'which can cause event recursion. Therefore, we'll
  279.     'set/check a static variable to prevent recursion.
  280.     Static ChangeActive%
  281.     If ChangeActive% Then Exit Sub
  282.     'Evevnt already active
  283.     ChangeActive% = True
  284.     'Set active flag
  285.     'At this point, the Change event has fired
  286.     'because an instruction has been received via a
  287.     'DDE link. Process the instruction accordingly:
  288.  
  289.     'DDELabel.Caption holds the request and must be formatted as:
  290.     '  fixed length string, 100 long, the path and name of the ZIP file
  291.     '  1 character long string, value 0 - Zip, 1 - Unzip
  292.     '  fixed lenght string, 100 long,
  293.     '       the path and name (wild characters) of the files to Zip
  294.     '       or
  295.     '       the destination path of the files to unzip
  296.     '  one character
  297.     '       0 or 1 if not zero that keeps the date at zipping, overwrites at unzipping
  298.     '  one character
  299.     '       0 or 1 if not zero that stores the path at zipping, restores the path at unzipping
  300.     ' there are converting procedures using ZipInfo variable for a structure
  301.     ' From String to zipvalues: GetZipInfo DDELabel.Caption
  302.     ' From Zipvalues to string: s$ = ZipPass$()
  303.  
  304.     DDEInstruction$ = DDELabel.Caption
  305.     'DDEResponse$ = "I am DDEZIP. Good evening"
  306.     'GoTo ToEnd
  307.     If DDEInstruction$ > "" Then
  308.         GetZipInfo DDEInstruction$
  309.     
  310.         'Fetch instruction
  311.         Text1 = ZipInfo.ZipFile
  312.         optTask.ListIndex = ZipInfo.Task
  313.         Select Case ZipInfo.Task
  314.            Case 0
  315.               Text2 = ZipInfo.FilesToZip
  316.               KeepDate = ZipInfo.KeepDate
  317.               StorePath = ZipInfo.StorePath
  318.               Recursive = ZipInfo.Recursive
  319.               txtComment = Trim(ZipInfo.Comment)
  320.               Password = Trim(ZipInfo.Password)
  321.            Case Else
  322.               Text3 = ZipInfo.Destination
  323.               Overwrite = ZipInfo.Overwrite
  324.               StorePath = ZipInfo.RestorePath
  325.               Password = Trim(ZipInfo.Password)
  326.         End Select
  327.         If Password > "" Then
  328.            chkPassword = True
  329.         Else
  330.            chkPassword = False
  331.         End If
  332.         'Execute
  333.         btnExecute_Click
  334.         If txtComment > "" Then
  335.            txtComment_LostFocus
  336.         End If
  337.     Else
  338.         'sending Null string terminates ddezip
  339.         End
  340.     End If
  341.     'give back a EndOfProcess message
  342.     DoEvents
  343.     DDELabel.Caption = "-1"
  344.     DDEResponse$ = "-1"
  345.     DoEvents
  346.     'wait for "ACK"
  347.     'start& = Timer
  348.     'Do While Not DDELabel.Caption = "ACK" And Timer - start& < 2
  349.     'Loop
  350.     'give an acknowledgdment to the client application
  351.     'Select Case ZipInfo.Task
  352.     '   Case 0
  353.     '      DDEResponse$ = ZipInfo.ZipFile + " created/updated containing " + ZipInfo.FilesToZip
  354.     '   Case 1
  355.     '      DDEResponse$ = ZipInfo.ZipFile + " exploded to " + ZipInfo.Destination
  356.     'End Select
  357.     'Post status or result back to DDELabel control
  358.     'The DDE client can fetch it if desired.
  359. 'ToEnd:
  360.     DDELabel.Caption = DDEResponse$
  361.     ChangeActive% = False
  362. End Sub
  363.  
  364. Sub Form_Load ()
  365.     Dim FindTitle$, PreviousHandle%, R%
  366.     optTask_Click
  367.     ZipEcho% = False
  368.     OverW% = False
  369.     'Detect if previous instance of this app is loaded
  370.     'The app may be visible or *totally* hidden, so we'll
  371.     'use the FindWindow function to locate and activate
  372.     '(show if hidden, or set focus if already visible)
  373.     'the previous instance
  374.     FindTitle$ = "Hidden DDE Server"
  375.     PreviousHandle% = FindWindow%(0&, FindTitle$)
  376.     If PreviousHandle% Then
  377.        'We found a previous instance
  378.        R% = ShowWindow%(PreviousHandle%, SW_RESTORE)
  379.        'Unhide app
  380.        R% = APISetFocus%(PreviousHandle%)
  381.        'Set focus
  382.        End
  383.        'This (second) instance can now terminate
  384.     Else
  385.        Me.Caption = FindTitle$
  386.        'First instance is loading here
  387.        HideButton_Click
  388.        'Hide this instance
  389.     End If
  390. End Sub
  391.  
  392. Sub Form_Paint ()
  393.     Dim R%
  394.     If OwnerHandle% Then
  395.        'A second instance has unhidden and set focus to
  396.        'this instance, causing this Form_Paint event
  397.        'to occur. However, only the DDEForm is visible,
  398.        'not the background/owner window. Reinstate this
  399.        'instance in the Task List and ALT+TAB order by
  400.        'unhiding the background/owner window:
  401.        R% = ShowWindow(OwnerHandle%, SW_RESTORE)
  402.        'Reset handle variable for next
  403.        'hide/show/paint cycle
  404.        OwnerHandle% = 0
  405.     Else
  406.        'OwnerHandle% is zero, so this instance is not
  407.        'currently hidden
  408.     End If
  409. End Sub
  410.  
  411. Sub Hidden_Click (Value As Integer)
  412.     ZipEcho% = Not Value
  413. End Sub
  414.  
  415. Sub HideButton_Click ()
  416.     Dim R%
  417.     Me.Hide
  418.     'Get the handle of this application's
  419.     'background/owner:
  420.     OwnerHandle% = GetWindow(Me.hWnd, GW_OWNER)
  421.     'Hide the background/owner window, thereby removing
  422.     'this app from the Task List and ALT+TAB order:
  423.     R% = ShowWindow(OwnerHandle%, SW_HIDE)
  424. End Sub
  425.  
  426. Sub optTask_Click ()
  427.     Select Case optTask.ListIndex
  428.        Case 0
  429.           KeepDate.Enabled = True
  430.           StorePath.Caption = "&Store Path"
  431.           Label2.Visible = True
  432.           Text2.Visible = True
  433.           Label3.Visible = False
  434.           Text3.Visible = False
  435.           Overwrite.Enabled = False
  436.           Text2_Change
  437.        Case 1
  438.           KeepDate.Enabled = False
  439.           StorePath.Caption = "Re&store Path"
  440.           Label2.Visible = False
  441.           Text2.Visible = False
  442.           Label3.Visible = True
  443.           Text3.Visible = True
  444.           Overwrite.Enabled = True
  445.           Text3_Change
  446.     End Select
  447. End Sub
  448.  
  449. Sub Overwrite_Click (Value As Integer)
  450.     OverW% = Value
  451. End Sub
  452.  
  453. Sub Text1_Change ()
  454.     Dim d$, f$
  455.     On Error GoTo NotAPath
  456.     d$ = ExtractPath(Trim(Text1))
  457.     If Len(d$) > 3 And Right$(d$, 1) = "\" Then
  458.        d$ = Left$(d$, Len(d$) - 1)
  459.     End If
  460.     If Trim(d$) > "" Then
  461.         If GetAttr(Trim(d$)) = 16 Then
  462.            f$ = ExtractFile(Trim(Text1))
  463.            If (Len(f$) <= 8 And Len(f$) > 0) Or (Len(f$) > 4 And Len(f$) <= 12 And Right$(UCase$(f$), 4) = ".ZIP") Then
  464.               Text1.Tag = True
  465.            Else
  466.               Text1.Tag = False
  467.            End If
  468.         Else
  469.             Text1.Tag = False
  470.         End If
  471.     Else
  472.         Text1.Tag = False
  473.     End If
  474.    
  475. Text1Exit:
  476.     If optTask.ListIndex = 0 Then
  477.         If Val(Text1.Tag) And Val(Text2.Tag) Then
  478.            btnExecute.Enabled = True
  479.         Else
  480.            btnExecute.Enabled = False
  481.         End If
  482.     Else
  483.         If Val(Text1.Tag) And Val(Text3.Tag) Then
  484.            btnExecute.Enabled = True
  485.         Else
  486.            btnExecute.Enabled = False
  487.         End If
  488.     End If
  489.     Exit Sub
  490. NotAPath:
  491.     Text1.Tag = False
  492.     Resume Text1Exit
  493. End Sub
  494.  
  495. Sub Text2_Change ()
  496.     If optTask.ListIndex = 0 Then
  497.        If Trim(Text2) > "" Then
  498.           If Len(Dir$(Trim(Text2))) > 0 Then
  499.              Text2.Tag = True
  500.           Else
  501.              Text2.Tag = False
  502.           End If
  503.        Else
  504.           Text2.Tag = False
  505.        End If
  506.     End If
  507.     If Val(Text2.Tag) And Val(Text1.Tag) Then
  508.        btnExecute.Enabled = True
  509.     Else
  510.        btnExecute.Enabled = False
  511.     End If
  512. End Sub
  513.  
  514. Sub Text3_Change ()
  515.     On Error GoTo NotAFile
  516.     If optTask.ListIndex = 1 Then
  517.        If Trim(Text3) > "" Then
  518.           If GetAttr(Trim(Text3)) = 16 Then
  519.              Text3.Tag = True
  520.           Else
  521.              Text3.Tag = False
  522.           End If
  523.        Else
  524.           Text3.Tag = False
  525.        End If
  526.     End If
  527. Text3Exit:
  528.     If Val(Text1.Tag) And Val(Text3.Tag) Then
  529.        btnExecute.Enabled = True
  530.     Else
  531.        btnExecute.Enabled = False
  532.     End If
  533.     Exit Sub
  534. NotAFile:
  535.     Text3.Tag = False
  536.     Resume Text3Exit
  537. End Sub
  538.  
  539. Sub txtComment_LostFocus ()
  540.     Dim c$, ZipFile$, C_Err_Code%, Handle%
  541.  
  542.     c$ = Trim(txtComment.Text)
  543.     If c$ <> ZipComment$ Then
  544.         ZipFile$ = RTrim$(Text1)
  545.         C_Err_Code% = EtZipOpen(ZipFile$, 0, Handle%)
  546.         If C_Err_Code% Then GoTo CommentError
  547.         C_Err_Code% = EtZipNewComment(Handle%, c$)
  548.         EtZipClose Handle%
  549.         If C_Err_Code% Then GoTo CommentError
  550.         ZipComment$ = c$
  551.         txtComment.Text = ZipComment$
  552.     End If
  553.     Exit Sub
  554.  
  555.  
  556. CommentError:
  557.     MsgBox "Unable to install new comment", 48, "File Write Error"
  558.     txtComment.Text = ZipComment$
  559.  
  560.  
  561.  
  562. End Sub
  563.  
  564.