home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / popupx / setup.exe / _SETUP.1 / frmSample.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-07-01  |  11.1 KB  |  299 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Object = "{D3732FCB-1082-11D2-AB9F-000000000000}#1.0#0"; "PopupX-Trial.ocx"
  4. Begin VB.Form frmSample 
  5.    AutoRedraw      =   -1  'True
  6.    BackColor       =   &H80000001&
  7.    BorderStyle     =   1  'Fixed Single
  8.    ClientHeight    =   375
  9.    ClientLeft      =   15
  10.    ClientTop       =   15
  11.    ClientWidth     =   4680
  12.    ControlBox      =   0   'False
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   375
  17.    ScaleWidth      =   4680
  18.    ShowInTaskbar   =   0   'False
  19.    StartUpPosition =   3  'Windows Default
  20.    Begin PopupX_Evaluation.PopupMenu PopupMenu1 
  21.       Left            =   2040
  22.       Top             =   90
  23.       _ExtentX        =   847
  24.       _ExtentY        =   847
  25.       ParentHwnd      =   4056
  26.    End
  27.    Begin VB.CommandButton Command1 
  28.       Height          =   315
  29.       Left            =   30
  30.       Picture         =   "frmSample.frx":0000
  31.       Style           =   1  'Graphical
  32.       TabIndex        =   1
  33.       Top             =   30
  34.       UseMaskColor    =   -1  'True
  35.       Width           =   855
  36.    End
  37.    Begin ComctlLib.StatusBar StatusBar1 
  38.       Align           =   2  'Align Bottom
  39.       Height          =   375
  40.       Left            =   0
  41.       TabIndex        =   0
  42.       Top             =   0
  43.       Width           =   4680
  44.       _ExtentX        =   8255
  45.       _ExtentY        =   661
  46.       SimpleText      =   ""
  47.       _Version        =   327682
  48.       BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  49.          NumPanels       =   2
  50.          BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  51.             AutoSize        =   1
  52.             Bevel           =   0
  53.             Object.Width           =   5556
  54.             TextSave        =   ""
  55.             Key             =   ""
  56.             Object.Tag             =   ""
  57.          EndProperty
  58.          BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  59.             Style           =   5
  60.             Alignment       =   1
  61.             AutoSize        =   2
  62.             Object.Width           =   2619
  63.             Picture         =   "frmSample.frx":0296
  64.             TextSave        =   "1:38 AM"
  65.             Key             =   ""
  66.             Object.Tag             =   ""
  67.          EndProperty
  68.       EndProperty
  69.    End
  70. Attribute VB_Name = "frmSample"
  71. Attribute VB_GlobalNameSpace = False
  72. Attribute VB_Creatable = False
  73. Attribute VB_PredeclaredId = True
  74. Attribute VB_Exposed = False
  75. Option Compare Text
  76. Option Explicit
  77. Dim WFD As WIN32_FIND_DATA, hItem&, hFile&
  78. Dim fileCount&, fileCount1&, TotalFiles%, Running%, hLB&, FileSpec$, UseFileSpec%
  79. Const vbBackslash = "\"
  80. Const vbAllFiles = "*.*"
  81. Const vbKeyDot = 46
  82. Dim currdir() As String
  83. Dim currdir1() As String
  84. Dim ActiveMenu As String
  85. Private Const HWND_TOPMOST = -1
  86. Private Const SWP_NOACTIVATE = &H10
  87. Private Const SWP_SHOWWINDOW = &H40
  88. Private Const SWP_HIDEWINDOW = &H80
  89. Private Const SWP_NOZORDER = &H4
  90. Private Const SWP_NOMOVE = &H2
  91. Private Const SWP_NOREPOSITION = &H200
  92. Private Const SWP_NOSIZE = &H1
  93. Private Sub Command1_Click()
  94.     ActiveMenu = "Browse"
  95.     PopupMenu1.ShowPopupMenu "Browse", ScaleX(Command1.Left, vbTwips, vbPixels), ScaleY(Command1.Top, vbTwips, vbPixels)
  96. End Sub
  97. Private Sub Form_Load()
  98. Move 0, Screen.Height - Height, Screen.Width
  99. SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE
  100. PopupMenu1.Enabled = True
  101. End Sub
  102. Private Function addDrives()
  103. 'Retrieves Local Drives and adds them to the POPUPMENU
  104. Dim drvbitmask&, maxpwr%, pwr%
  105. drvbitmask& = GetLogicalDrives()
  106.     ' If GetLogicalDrives() succeeds, the return value is a bitmask representing
  107.     ' the currently available disk drives. Bit position 0 (the least-significant bit)
  108.     ' is drive A, bit position 1 is drive B, bit position 2 is drive C, and so on.
  109.     ' If the function fails, the return value is zero.
  110.     ' GetLogicalDriveStrings() could be used here instead,
  111.     ' but it's string buffer would have to be parsed...
  112.     If drvbitmask& Then
  113.         ' Get & search each available drive
  114.         maxpwr% = Int(Log(drvbitmask&) / Log(2))   ' a little math...
  115.         For pwr% = 2 To maxpwr%
  116.             If (2 ^ pwr% And drvbitmask&) Then _
  117.                 'test if drive has at least one file in root dir
  118.                 hItem& = FindFirstFile((Chr$(vbKeyA + pwr%) & ":\") & vbAllFiles, WFD)
  119.                 If hItem& <> INVALID_HANDLE_VALUE Then
  120.                     'drive contains at least one file... so we will display a submenu
  121.                     PopupMenu1.AppendMenu (Chr$(vbKeyA + pwr%)), (Chr$(vbKeyA + pwr%) & ":\"), True
  122.                 Else
  123.                     'drive does not contain files or is inaccessible... so we will just display the drive letter
  124.                     PopupMenu1.AppendMenu (Chr$(vbKeyA + pwr%)), (Chr$(vbKeyA + pwr%) & ":\")
  125.                 End If
  126.             End If
  127.         Next
  128.     End If
  129. End Function
  130. Private Function addDirs(curpath$)  ' curpath$ is passed w/ trailing "\"
  131.     If Right(curpath, 1) <> "\" Then curpath = curpath & "\"
  132.     Dim i%
  133.     fileCount = 0
  134.     fileCount1 = 0
  135.     ReDim currdir(1, 10) As String
  136.     ReDim currdir1(1, 10) As String
  137.     '''''If Not Running% Then Exit Function
  138.     ' This loop finds *every* subdir and file in the current dir
  139.     hItem& = FindFirstFile(curpath$ & vbAllFiles, WFD)
  140.     If hItem& <> INVALID_HANDLE_VALUE Then
  141.         
  142.         Do
  143.             ' Tests for subdirs only...
  144.             If (WFD.dwFileAttributes And vbDirectory) Then
  145.                 
  146.                 ' If not a  "." or ".." DOS subdir...
  147.                 If Asc(WFD.cFileName) <> vbKeyDot Then
  148.                     ' This is executed in the mnuFindFiles_Click()
  149.                     ' call though it isn't used...
  150.                     'TotalDirs% = TotalDirs% + 1
  151.                     ' This is the heart of a recursive proc...
  152.                     ' Cache the subdirs of the current dir in the 1 based array.
  153.                     ' This proc calls itself below for each subdir cached in the array.
  154.                     ' (re-allocating the array only once every 10 itinerations improves speed)
  155.                     If (fileCount Mod 10) = 0 Then ReDim Preserve currdir(1, fileCount + 10)
  156.                     currdir(0, fileCount) = Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
  157.                     currdir(1, fileCount) = -1
  158.                     fileCount = fileCount + 1
  159.                 End If
  160.             
  161.             ' File size and attribute tests can be used here, i.e:
  162.             ' ElseIf (WFD.dwFileAttributes And vbHidden) = False Then  'etc...
  163.             
  164.             ' Get a total file count for mnuFolderInfo_Click()
  165.             ElseIf Not UseFileSpec% Then
  166.             If (fileCount1 Mod 10) = 0 Then ReDim Preserve currdir1(1, fileCount1 + 10)
  167.             currdir1(0, fileCount1) = Left$(WFD.cFileName, InStr(WFD.cFileName, vbNullChar) - 1)
  168.             currdir1(1, fileCount1) = 0
  169.  '           PopupMenu1.AppendMenu WFD.cFileName, curpath$ & WFD.cFileName
  170.             fileCount1 = fileCount1 + 1
  171.             End If
  172.         
  173.         ' Get the next subdir or file
  174.         
  175.         Loop While FindNextFile(hItem&, WFD)
  176.         
  177.         ' Close the search handle
  178.         Call FindClose(hItem&)
  179.     End If
  180.  QuickSort 0, fileCount - 1
  181.  QuickSort1 0, fileCount1 - 1
  182. On Error GoTo erradddirs
  183. For i = 0 To fileCount - 1
  184.     PopupMenu1.AppendMenu currdir(0, i), curpath & currdir(0, i), Val(currdir(1, i))
  185. Next i
  186. For i = 0 To fileCount1 - 1
  187.     PopupMenu1.AppendMenu currdir1(0, i), curpath & currdir1(0, i), Val(currdir1(1, i))
  188. Next i
  189. Exit Function
  190. erradddirs:
  191. MsgBox Error
  192. End Function
  193. Private Function QuickSort(First&, ByVal Last&) As Boolean
  194. If Last < 1 Then Exit Function
  195. Dim Switch As Boolean
  196. Dim BuffArray(1, 1) As String
  197. Dim RemFirst&, RemLast&, p&
  198. Dim i As Long
  199. RemFirst = First
  200. RemLast = Last
  201. p = First
  202.     Switch = False
  203.     Do While Switch = False And p < Last
  204.         If currdir(0, p) > currdir(0, Last) Then
  205.             For i = 0 To 1
  206.                 BuffArray(i, 1) = currdir(i, p)
  207.                 currdir(i, p) = currdir(i, Last)
  208.                 currdir(i, Last) = BuffArray(i, 1)
  209.             Next i
  210.             First = First + 1
  211.             p = Last
  212.             Switch = True
  213.         End If
  214.     If Switch = False Then Last = Last - 1
  215.     Loop
  216.     Switch = False
  217.     Do While Switch = False And p > First
  218.         If currdir(0, p) < currdir(0, First) Then
  219.             For i = 0 To 1
  220.                 BuffArray(i, 1) = currdir(i, p)
  221.                 currdir(i, p) = currdir(i, First)
  222.                 currdir(i, First) = BuffArray(i, 1)
  223.             Next i
  224.             Last = Last - 1
  225.             p = First
  226.             Switch = True
  227.         End If
  228.         If Switch = False Then First = First + 1
  229.     Loop
  230. Loop Until First = p And Last = p
  231. If p - RemFirst > 1 Then QuickSort RemFirst, p - 1
  232. If RemLast - p > 1 Then QuickSort p + 1, RemLast
  233. End Function
  234. Private Function QuickSort1(First&, ByVal Last&) As Boolean
  235. If Last < 1 Then Exit Function
  236. Dim Switch As Boolean
  237. Dim BuffArray(1, 1) As String
  238. Dim RemFirst&, RemLast&, p&
  239. Dim i As Long
  240. RemFirst = First
  241. RemLast = Last
  242. p = First
  243.     Switch = False
  244.     Do While Switch = False And p < Last
  245.         If currdir1(0, p) > currdir1(0, Last) Then
  246.             For i = 0 To 1
  247.                 BuffArray(i, 1) = currdir1(i, p)
  248.                 currdir1(i, p) = currdir1(i, Last)
  249.                 currdir1(i, Last) = BuffArray(i, 1)
  250.             Next i
  251.             First = First + 1
  252.             p = Last
  253.             Switch = True
  254.         End If
  255.     If Switch = False Then Last = Last - 1
  256.     Loop
  257.     Switch = False
  258.     Do While Switch = False And p > First
  259.         If currdir1(0, p) < currdir1(0, First) Then
  260.             For i = 0 To 1
  261.                 BuffArray(i, 1) = currdir1(i, p)
  262.                 currdir1(i, p) = currdir1(i, First)
  263.                 currdir1(i, First) = BuffArray(i, 1)
  264.             Next i
  265.             Last = Last - 1
  266.             p = First
  267.             Switch = True
  268.         End If
  269.         If Switch = False Then First = First + 1
  270.     Loop
  271. Loop Until First = p And Last = p
  272. If p - RemFirst > 1 Then QuickSort1 RemFirst, p - 1
  273. If RemLast - p > 1 Then QuickSort1 p + 1, RemLast
  274. End Function
  275. Private Sub PopupMenu1_GetMenuContent(ActiveMenu As String, Caption As String, ItemData As String)
  276. Dim Waitcurs As CWaitCursor
  277. Set Waitcurs = New CWaitCursor
  278. Waitcurs.SetCursor
  279. 'Debug.Print Key
  280. 'Debug.Print itemvalue
  281. Select Case ActiveMenu
  282. Case "Browse"
  283. If ItemData = "" Then
  284.     addDrives
  285.     PopupMenu1.AppendMenu "-"
  286.     PopupMenu1.AppendMenu "&Quit", "-1"
  287.     addDirs (ItemData)
  288. End If
  289. End Select
  290. End Sub
  291. Private Sub PopupMenu1_MenuClick(ActiveMenu As String, Caption As String, ItemData As String)
  292. If ItemData = "-1" Then
  293.     Unload Me
  294.     Dim retval As Long
  295.     retval = Module1.ShellExecute(hwnd, "open", ItemData & Chr(0), vbNull, vbNull, 5)
  296.      
  297. End If
  298. End Sub
  299.