home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / code_gen / codewiz / codewiz.ba_ / codewiz.ba
Encoding:
INI File  |  1995-03-28  |  35.9 KB  |  1,217 lines

  1. [1]
  2. GetSysDir returns the path of the Windows System directory.  Pass it the name of the string you want SysPath assigned to.
  3.  
  4. [Code]
  5. 'Declares for GetSystemDir
  6. Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  7.  
  8. Sub GetSystemDir (SystemPath$)
  9. DIM Sys As String * 256   
  10. x = GetSystemDirectory(Sys, Len(Sys))
  11. x = InStr(1, Sys, Chr$(0))
  12. SystemPath$ = Left$(Sys, Instr(Sys,Chr$(0))-1)
  13. End Sub
  14.  
  15. [Stop]
  16. [2]
  17. Loaded tells if an app of the passed classname is loaded
  18. [Code]
  19. 'Declares for Loaded
  20. Declare Function FindWindow Lib "user" (ByVal CName As Any, ByVal Caption As Any)
  21.  
  22. Function Loaded (ClassName$)
  23. Loaded = FindWindow(ClassName$, 0&)
  24. End Function
  25. [Stop]
  26. [3]
  27. RestoreApp restores the windows whose handle you pass to it.
  28. [Code]
  29. 'Declares for RestoreApp
  30. Declare Function IsIconic Lib "user" (ByVal hWnd As Any)
  31.  
  32. Sub RestoreApp (wHandle)
  33. WM_SYSCOMMAND = &H112
  34. SC_RESTORE = &HF120
  35.  
  36. If IsIconic(Instance) Then
  37. T = PostMessage(Instance, WM_SYSCOMMAND, SC_RESTORE, 0)
  38. WaitSecs 1
  39. End If
  40. End Sub
  41. [Stop]
  42. [4]
  43. Tracks a popup menu.
  44.  
  45. Pass it the number (going from right to left) of the menu you wish to view, the X & Y coordinates at which it should pop up (as returned by a mousedown event), the form on which the mousedown event took place (and over which the menu should appear), and the form to which the menu belongs (which may or may not be the same as the previous form).
  46. [Code]
  47. 'TrackPopupMenu declares
  48. Declare Function TrackPopupMenu% Lib "user" (ByVal hMenu%, ByVal wFlags%, ByVal X%, ByVal Y%, ByVal r2%, ByVal hWnd%, ByVal r1&)
  49. Declare Function GetMenu% Lib "user" (ByVal hWnd%)
  50. Declare Function GetSubMenu% Lib "user" (ByVal hMenu%, ByVal nPos%)
  51.  
  52.  
  53. Sub TrackPopUp (Menu As Integer, X As Single, Y As Single, F as Form, MenuForm As Form)
  54.           Const PIXEL = 3
  55.           Const TWIP = 1
  56.           F.ScaleMode = PIXEL
  57.           InPixels = F.ScaleWidth
  58.           F.ScaleMode = TWIP
  59.           ix = (X + F.Left) \ (F.ScaleWidth \ InPixels)
  60.           iy = (Y + (F.Top + (F.Height - F.ScaleHeight - (F.Width - F.ScaleWidth)))) \ (F.ScaleWidth \ InPixels)
  61.           hMenu% = GetMenu(MenuForm.hWnd)
  62.           hSubMenu% = GetSubMenu(hMenu%, Menu)
  63.           '2 tells it to use right mouse button, 1 the left button
  64.           r = TrackPopupMenu(hSubMenu%, 2, ix, iy, 0, MenuForm.hWnd, 0)
  65. End Sub
  66. [Stop]
  67. [5]
  68. Extracts icons from a specified Exe file. 
  69.  
  70.  
  71. [Code]
  72. 'Declares for IconExtractor
  73. Const GWW_HINSTANCE = (-6)
  74. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  75. Declare Function ExtractIcon Lib "shell" (ByVal lpHandle As Integer, ByVal lpExe As String, ByVal lpiconindex As Integer) As Integer
  76. Declare Function DrawIcon Lib "USER" (ByVal lpHandle As Integer, ByVal xcoord As Integer, ByVal ycoord As Integer, ByVal Hicon As Integer) As Integer
  77.  
  78. Sub IconExtractor (ExeFile$, F as Form, Pic as Picture)
  79. Handle = F.hWnd
  80. z = SCREEN.HEIGHT
  81.     Select Case z
  82.         Case 7000
  83.             X = 2: Y = 1
  84.         Case 7200
  85.             X = 3: Y = 0
  86.         Case 9000
  87.             X = 3: Y = 0
  88.         Case Is > 9000
  89.             X = 8: Y = 4
  90.     End Select
  91.                 
  92.     Static Looper
  93.     Looper = Looper + 1
  94.     Inst = GetWindowWord(Handle, GWW_HINSTANCE)
  95.     Hicon = ExtractIcon(Inst, ExeFile$, Looper - 1)
  96.     If Hicon = 0 Then
  97.         If Looper > 0 Then
  98.             Hicon = ExtractIcon(Inst, ExeFile$, 0)
  99.             Looper = 1
  100.         Else Beep: Exit Sub
  101.         End If
  102.     End If
  103.     F.Pic.CLS
  104.     Draw = DrawIcon(F.Pic.hDC, X, Y, Hicon)
  105. End Sub
  106.  
  107. [Stop]
  108. [6]
  109. Testlength can be used to test whether more than a specified number of characters has been entered into a textbox. If so, it deletes backwards from the insertion point until the text length is within the specified limit.
  110. [Code]
  111. 'Declares for TestLength
  112. Global Const MB_ICONEXCLAMATION = 48
  113.  
  114. Sub TestLength (C As Control, L As Integer)
  115. Select Case Len(C.Text)
  116. Case Is <= L
  117. Exit Sub
  118. Case Else
  119. MsgBox "This field is limited to " + Str$(L) + " characters only! ", MB_ICONEXCLAMATION, "CopyFlow"
  120. LeftText$ = Left$(C.Text, C.SelStart)
  121. RightText$ = Mid$(C.Text, C.SelStart + 1)
  122. LeftText$ = Left$(LeftText$, L - Len(RightText$))
  123. C.Text = LeftText$ + RightText$
  124. End Select
  125. End Sub
  126.  
  127. [Stop]
  128. [7]
  129. The Exists%() function returns a value of TRUE if the specified file exists, or FALSE if it doesn't.
  130. [Code]
  131. Function Exists% (F$)
  132. On Error Resume Next
  133. X& = FileLen(F$)
  134. If X& Then Exists% = True
  135. End Function
  136.  
  137. [Stop]
  138. [8]
  139. Function determines if passed pathname is valid
  140. [Code]
  141. '------------------------------------------------------
  142. ' Function:   IsValidPath as integer
  143. ' arguments:  DestPath$         a string that is a full path
  144. '             DefaultDrive$     the default drive.  eg.  "C:"
  145. '
  146. '  If DestPath$ does not include a drive specification,
  147. '  IsValidPath uses Default Drive
  148. '
  149. '  When IsValidPath is finished, DestPath$ is reformated
  150. '  to the format "X:\dir\dir\dir\"
  151. '
  152. ' Result:  True (-1) if path is valid.
  153. '          False (0) if path is invalid
  154. '-------------------------------------------------------
  155. Function IsValidPath (DestPath$, ByVal DefaultDrive$) As Integer
  156.  
  157.     '----------------------------
  158.     ' Remove left and right spaces
  159.     '----------------------------
  160.     DestPath$ = RTrim$(LTrim$(DestPath$))
  161.     
  162.  
  163.     '-----------------------------
  164.     ' Check Default Drive Parameter
  165.     '-----------------------------
  166.     If Right$(DefaultDrive$, 1) <> ":" Or Len(DefaultDrive$) <> 2 Then
  167.         MsgBox "Bad default drive parameter specified in IsValidPath Function.  You passed,  """ + DefaultDrive$ + """.  Must be one drive letter and "":"".  For example, ""C:"", ""D:""...", 64, "Setup Kit Error"
  168.         GoTo parseErr
  169.     End If
  170.     
  171.  
  172.     '-------------------------------------------------------
  173.     ' Insert default drive if path begins with root backslash
  174.     '-------------------------------------------------------
  175.     If Left$(DestPath$, 1) = "\" Then
  176.         DestPath$ = DefaultDrive + DestPath$
  177.     End If
  178.     
  179.     '-----------------------------
  180.     ' check for invalid characters
  181.     '-----------------------------
  182.     On Error Resume Next
  183.     tmp$ = Dir$(DestPath$)
  184.     If Err <> 0 Then
  185.         GoTo parseErr
  186.     End If
  187.     
  188.  
  189.     '-----------------------------------------
  190.     ' Check for wildcard characters and spaces
  191.     '-----------------------------------------
  192.     If (InStr(DestPath$, "*") <> 0) GoTo parseErr
  193.     If (InStr(DestPath$, "?") <> 0) GoTo parseErr
  194.     If (InStr(DestPath$, " ") <> 0) GoTo parseErr
  195.          
  196.     
  197.     '------------------------------------------
  198.     ' Make Sure colon is in second char position
  199.     '------------------------------------------
  200.     If Mid$(DestPath$, 2, 1) <> Chr$(58) Then GoTo parseErr
  201.     
  202.  
  203.     '-------------------------------
  204.     ' Insert root backslash if needed
  205.     '-------------------------------
  206.     If Len(DestPath$) > 2 Then
  207.       If Right$(Left$(DestPath$, 3), 1) <> "\" Then
  208.         DestPath$ = Left$(DestPath$, 2) + "\" + Right$(DestPath$, Len(DestPath$) - 2)
  209.       End If
  210.     End If
  211.  
  212.     '-------------------------
  213.     ' Check drive to install on
  214.     '-------------------------
  215.     drive$ = Left$(DestPath$, 1)
  216.     ChDrive (drive$)                                                        ' Try to change to the dest drive
  217.     If Err <> 0 Then GoTo parseErr
  218.     
  219.     '-----------
  220.     ' Add final \
  221.     '-----------
  222.     If Right$(DestPath$, 1) <> "\" Then
  223.         DestPath$ = DestPath$ + "\"
  224.     End If
  225.     
  226.  
  227.     '-------------------------------------
  228.     ' Root dir is a valid dir
  229.     '-------------------------------------
  230.     If Len(DestPath$) = 3 Then
  231.         If Right$(DestPath$, 2) = ":\" Then
  232.             GoTo ParseOK
  233.         End If
  234.     End If
  235.     
  236.  
  237.     '------------------------
  238.     ' Check for repeated Slash
  239.     '------------------------
  240.     If InStr(DestPath$, "\\") <> 0 Then GoTo parseErr
  241.         
  242.     '--------------------------------------
  243.     ' Check for illegal directory names
  244.     '--------------------------------------
  245.     legalChar$ = "!#$%&'()-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`{}~."
  246.     BackPos = 3
  247.     forePos = InStr(4, DestPath$, "\")
  248.     Do
  249.         temp$ = Mid$(DestPath$, BackPos + 1, forePos - BackPos - 1)
  250.         
  251.         '----------------------------
  252.         ' Test for illegal characters
  253.         '----------------------------
  254.         For i = 1 To Len(temp$)
  255.             If InStr(legalChar$, UCase$(Mid$(temp$, i, 1))) = 0 Then GoTo parseErr
  256.         Next i
  257.  
  258.         '-------------------------------------------
  259.         ' Check combinations of periods and lengths
  260.         '-------------------------------------------
  261.         periodPos = InStr(temp$, ".")
  262.         length = Len(temp$)
  263.         If periodPos = 0 Then
  264.             If length > 8 Then GoTo parseErr                         ' Base too long
  265.         Else
  266.             If periodPos > 9 Then GoTo parseErr                      ' Base too long
  267.             If length > periodPos + 3 Then GoTo parseErr             ' Extension too long
  268.             If InStr(periodPos + 1, temp$, ".") <> 0 Then GoTo parseErr' Two periods not allowed
  269.         End If
  270.  
  271.         BackPos = forePos
  272.         forePos = InStr(BackPos + 1, DestPath$, "\")
  273.     Loop Until forePos = 0
  274.  
  275. ParseOK:
  276.     IsValidPath = True
  277.     Exit Function
  278.  
  279. parseErr:
  280.     IsValidPath = False
  281. End Function
  282.  
  283. [Stop]
  284. [9]
  285. Creates the passed path
  286. [Code]
  287. Function CreatePath (ByVal DestPath$) As Integer
  288. '---------------------------------------------
  289. ' Create the path contained in DestPath$
  290. ' First char must be drive letter, followed by
  291. ' a ":\" followed by the path, if any.
  292. '---------------------------------------------
  293.  
  294.     Screen.MousePointer = 11
  295.  
  296.     '---------------------------------------------
  297.     ' Add slash to end of path if not there already
  298.     '---------------------------------------------
  299.     If Right$(DestPath$, 1) <> "\" Then
  300.         DestPath$ = DestPath$ + "\"
  301.     End If
  302.           
  303.  
  304.     '-----------------------------------
  305.     ' Change to the root dir of the drive
  306.     '-----------------------------------
  307.     On Error Resume Next
  308.     ChDrive DestPath$
  309.     If Err <> 0 Then GoTo errorOut
  310.     ChDir "\"
  311.  
  312.     '-------------------------------------------------
  313.     ' Attempt to make each directory, then change to it
  314.     '-------------------------------------------------
  315.     BackPos = 3
  316.     forePos = InStr(4, DestPath$, "\")
  317.     Do While forePos <> 0
  318.         temp$ = Mid$(DestPath$, BackPos + 1, forePos - BackPos - 1)
  319.  
  320.         Err = 0
  321.         MkDir temp$
  322.         If Err <> 0 And Err <> 75 Then GoTo errorOut
  323.  
  324.         Err = 0
  325.         ChDir temp$
  326.         If Err <> 0 Then GoTo errorOut
  327.  
  328.         BackPos = forePos
  329.         forePos = InStr(BackPos + 1, DestPath$, "\")
  330.     Loop
  331.                  
  332.     CreatePath = True
  333.     Screen.MousePointer = 0
  334.     Exit Function
  335.                  
  336. errorOut:
  337.     MsgBox "Error While Attempting to Create Directories on Destination Drive.", 48, "SETUP"
  338.     CreatePath = False
  339.     Screen.MousePointer = 0
  340.  
  341. End Function
  342.  
  343. [Stop]
  344. [10]
  345. Creates a Program Manager group.
  346.  
  347. [Code]
  348. Sub CreateProgManGroup (x As Form, GroupName$, GroupPath$)
  349. '-------------------------------------------------------------
  350. ' Procedure: CreateProgManGroup
  351. ' Arguments: X           The Form where a Label1 exist
  352. '            GroupName$  A string that contains the group name
  353. '            GroupPath$  A string that contains the group file
  354. '                        name  ie 'myapp.grp'
  355. '-------------------------------------------------------------
  356.     
  357.     Screen.MousePointer = 11
  358.     
  359.     '----------------------------------------------------------------------
  360.     ' Windows requires DDE in order to create a program group and item.
  361.     ' Here, a Visual Basic label control is used to generate the DDE messages
  362.     '----------------------------------------------------------------------
  363.     On Error Resume Next
  364.  
  365.     
  366.     '--------------------------------
  367.     ' Set LinkTopic to PROGRAM MANAGER
  368.     '--------------------------------
  369.     x.Label1.LinkTopic = "ProgMan|Progman"
  370.     x.Label1.LinkMode = 2
  371.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  372.       z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  373.     Next                                                     ' for debug windows.
  374.     x.Label1.LinkTimeout = 100
  375.  
  376.  
  377.     '---------------------
  378.     ' Create program group
  379.     '---------------------
  380.     x.Label1.LinkExecute "[CreateGroup(" + GroupName$ + Chr$(44) + GroupPath$ + ")]"
  381.  
  382.  
  383.     '-----------------
  384.     ' Reset properties
  385.     '-----------------
  386.     x.Label1.LinkTimeout = 50
  387.     x.Label1.LinkMode = 0
  388.     
  389.     Screen.MousePointer = 0
  390. End Sub
  391.  
  392. [Stop]
  393. [11]
  394. Creates a program manager item
  395. [Code]
  396. Sub CreateProgManItem (x As Form, CmdLine$, IconTitle$)
  397.  
  398. '----------------------------------------------------------
  399. ' Procedure: CreateProgManItem
  400. '
  401. ' Arguments: X           The form where Label1 exists
  402. '
  403. '            CmdLine$    A string that contains the command
  404. '                        line for the item/icon.
  405. '                        ie 'c:\myapp\setup.exe'
  406. '
  407. '            IconTitle$  A string that contains the item's
  408. '                        caption
  409. '----------------------------------------------------------
  410.     
  411.     Screen.MousePointer = 11
  412.     
  413.     '----------------------------------------------------------------------
  414.     ' Windows requires DDE in order to create a program group and item.
  415.     ' Here, a Visual Basic label control is used to generate the DDE messages
  416.     '----------------------------------------------------------------------
  417.     On Error Resume Next
  418.  
  419.  
  420.     '---------------------------------
  421.     ' Set LinkTopic to PROGRAM MANAGER
  422.     '---------------------------------
  423.     x.Label1.LinkTopic = "ProgMan|Progman"
  424.     x.Label1.LinkMode = 2
  425.     For i% = 1 To 10                                         ' Loop to ensure that there is enough time to
  426.       z% = DoEvents()                                        ' process DDE Execute.  This is redundant but needed
  427.     Next                                                     ' for debug windows.
  428.     x.Label1.LinkTimeout = 100
  429.  
  430.     
  431.     '------------------------------------------------
  432.     ' Create Program Item, one of the icons to launch
  433.     ' an application from Program Manager
  434.     '------------------------------------------------
  435.     x.Label1.LinkExecute "[AddItem(" + CmdLine$ + Chr$(44) + IconTitle$ + Chr$(44) + ",,)]"
  436.     
  437.     '-----------------
  438.     ' Reset properties
  439.     '-----------------
  440.     x.Label1.LinkTimeout = 50
  441.     x.Label1.LinkMode = 0
  442.     
  443.     Screen.MousePointer = 0
  444. End Sub
  445.  
  446. [Stop]
  447. [12]
  448. obtain LoWord of Long
  449. [Code]
  450. Function LoWord%(LongVal&)
  451. LOWORD% = LongVal& AND 65535
  452. End Function
  453.  
  454.  
  455. [Stop]
  456. [13]
  457. obtain hiword of long
  458. [Code]
  459. Function HIWORD%(LongVal&)
  460. HIWORD% = LongVal& \ 65536 ' (note: '\', not '/')
  461. End Function
  462. [Stop]
  463. [14]
  464. Function creates confirmation box using specified text, returns True if Yes button pressed, False if No button pressed
  465. [Code]
  466. Function Confirm% (Ask$)
  467. If MsgBox(Ask$, 52, App.Title) = 6 Then Confirm% = True
  468. End Function
  469.  
  470. [Stop]
  471. [15]
  472. Function returns a passed path with backslash at end.
  473. [Code]
  474. Function FixPath$ (Test$)
  475. 'sticks a backslash on the end of test$ if there's
  476. 'not one there already
  477. Dim T$
  478. T$ = Test$
  479. If Right$(T$, 1) <> "\" Then T$ = T$ + "\"
  480. FixPath$ = T$
  481. End Function
  482.  
  483. [Stop]
  484. [16]
  485. Function returns handle of first window matching partial name parameter
  486.  
  487. [Code]
  488. 'Declares for SearchWindowLIst
  489. Declare Function GetWindow% Lib "USER" (ByVal hWnd%, ByVal wCmd%)
  490. Global Const GW_HWNDFIRST = 0
  491. Global Const GW_HWNDNEXT = 2
  492. Declare Function GetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String, ByVal aint As Integer) As Integer
  493.  
  494. Function SearchWindowList% (Cap$)
  495. 'returns handle of first window that matches partial
  496. 'caption passed to function
  497. SearchWindowList% = 0
  498. Dim w%, Y%, winCap As String * 255
  499. w% = GetWindow%(MAKerMain.hWnd, GW_HWNDFIRST)
  500. Do While w% <> 0
  501.    Y% = GetWindowText(w%, winCap, 254)
  502.    If Left$(winCap, Len(Cap$)) = Cap$ Then
  503.       SearchWindowList% = w%
  504.       Exit Do
  505.    End If
  506.    w% = GetWindow%(w%, GW_HWNDNEXT)
  507. Loop
  508. End Function
  509.  
  510.  
  511. [Stop]
  512. [17]
  513. Function removes path from fully-qualified file name, returns file name only.
  514. [Code]
  515. Function StripPath$ (T$)
  516. Dim x%, ct%
  517. StripPath$ = T$
  518. x% = InStr(T$, "\")
  519. Do While x%
  520.    ct% = x%
  521.    x% = InStr(ct% + 1, T$, "\")
  522. Loop
  523. If ct% > 0 Then StripPath$ = Mid$(T$, ct% + 1)
  524. End Function
  525.  
  526. [Stop]
  527. [18]
  528. Trims spaces CHR$(0)'s from string returned by API function.
  529. [Code]
  530. Function FixAPIString$ (ByVal test$)
  531. FixAPIString$ = Trim(Left$(test$, InStr(test$, Chr$(0)) - 1))
  532. End Function
  533.  
  534.  
  535. [Stop]
  536. [19]
  537. Finds and restores a previous running instance of your app
  538. [Code]
  539. Sub FindAndRestorePrevInstance (Cap$)
  540. Dim X%
  541. If App.PrevInstance Then
  542.    AppActivate Cap$
  543.    SendKeys ("% R")
  544.    End
  545. End If
  546. End Sub
  547.  
  548. [Stop]
  549. [20]
  550. This code in Load procedure detects previous instance of program
  551. [Code]
  552. Sub Form_Load () 
  553. If App.PrevInstance Then 
  554.    msg$ = App.EXEName & " already running " 
  555.    MsgBox msg$, 48 
  556.    End 
  557. End If 
  558. End Sub
  559.  
  560.  
  561. [Stop]
  562. [21]
  563. This routine will copy any size and type of file giving a visual progress indication to the user.  Simply pass the Source Filename, Target Filename, and name of the control to use as a progress guage. The code below uses a standard Panel3D1 control from THREED.VBX but any control that gives the desired effect may be used. The progress range is 1 to 100 but can be any range.
  564. [Code]
  565. Sub VisualFileCopy (SourceFileName As String, TargetFileName As String, 
  566. ProgressGuage As Control)
  567.  
  568.    Dim I As Integer
  569.    Dim SourceFileNo As Integer
  570.    Dim TargetFileNo As Integer
  571.    Dim SourceFileSize As Long
  572.    Dim CopyBuffer As String
  573.    
  574.    On Error GoTo FileCopyErrorRoutine
  575.    SourceFileSize = FileLen(SourceFileName)
  576.    CopyBuffer = Space$(25000)             'AS LARGE AS POSSIBLE UNDER 65,000
  577.    
  578. '--KILL THE CURRENT TARGET FILE IF IT EXISTS
  579.    If Len(Dir$(TargetFileName)) Then
  580.       Kill TargetFileName
  581.    End If
  582.  
  583. '--OPEN FILES
  584.    SourceFileNo = FreeFile
  585.    Open SourceFileName For Binary Access Read As SourceFileNo
  586.    TargetFileNo = FreeFile
  587.    Open TargetFileName For Binary Access Write As TargetFileNo
  588.  
  589. '--COPY SOURCE FILE TO TARGET FILE
  590.    For I = 1 To SourceFileSize \ Len(CopyBuffer)
  591.       Get #SourceFileNo, , CopyBuffer
  592.       ProgressGuage.FloodPercent = I * Len(CopyBuffer) / SourceFileSize * 100  
  593. 'UPDATE PROGRESS GUAGE
  594.       Put #TargetFileNo, , CopyBuffer
  595.       DoEvents
  596.    Next I
  597.  
  598. '--COPY ANY ODD PORTION OF THE SOURCE FILE REMAINING
  599.    CopyBuffer = Space$(SourceFileSize - Loc(TargetFileNo))
  600.    If Len(CopyBuffer) Then
  601.       Get #SourceFileNo, , CopyBuffer
  602.       Put #TargetFileNo, , CopyBuffer
  603.    End If
  604.    Close SourceFileNo
  605.    Close TargetFileNo
  606.  
  607. Exit Sub
  608.  
  609. FileCopyErrorRoutine:
  610.    MsgBox Error$
  611.    Exit Sub
  612. End Sub
  613.  
  614.  
  615.  
  616.  
  617.  
  618. [Stop]
  619. [22]
  620.  
  621. [Code]
  622.  
  623. Sub waitforeventstofinish (NbrTimes As Integer)
  624.    
  625.    Dim dummy As Integer
  626.  
  627.     Dim i As Integer
  628.  
  629.     For i = 1 To NbrTimes
  630.         dummy% = DoEvents()
  631.     Next i
  632.  
  633. End Sub
  634.  
  635.  
  636. [Stop]
  637. [23]
  638. Use this code with the Startup form procedure. Use CenterMe for non-MDI windows such as a dialog box. You should use CenterMe BEFORE you use Show to display the form. For two reasons: 
  639. 1.) If you use CenterMe after Show, you will see the form move at run-time. This looks very unprofessional.
  640. 2.) If you display the form as modal (form.Show 1) and then use CenterMe, Visual Basic won't listen to the next command following Show until your new form is removed from the screen. You can use CenterMe in the Form_Load event, causing the form to be centered each time it's loaded, or before the Show method.
  641.  
  642. You can use CenterMe in the Form_Resize event. This will make the window always centered, even if the user changes the size of your form.
  643.  
  644.  
  645. [Code]
  646.  
  647.     Sub CenterMe (frm as Form)
  648.         Dim x, y        'New directions for the form
  649.         
  650.         x = (Screen.Width - frm.Width) / 2
  651.         y = (Screen.Height - frm.Height) / 2
  652.         frm.Move x, y        'Change the location of the form
  653.     End Sub
  654.  
  655.  
  656.  
  657. [Stop]
  658. [24]
  659. This routine will move a menu caption to the far right of a menu. (Usually this is the Help caption.)
  660. [Code]
  661.  
  662. Form_Load event.
  663. Menu.Caption= Chr$(8) & Menu.Caption
  664. 'Replace Menu with a real control menu name such as menuHelp.
  665.  
  666.  
  667.  
  668. [Stop]
  669. [25]
  670. Discarding Letters:  The following code only accepts the digits zero through nine.
  671. [Code]
  672.  
  673. Sub Text1_KeyPress (KeyAscii As Integer)
  674.     If KeyAscii < Asc (" ") Then        'Is this Control Char
  675.         Exit Sub
  676.     End If
  677.  
  678.     If KeyAscii < Asc ("0") Or KeyAscii > Asc ("9") Then
  679.         KeyAscii = 0
  680.     End If
  681. End Sub
  682.  
  683. [Stop]
  684. [26]
  685. This subroutine (DoKeyPress) discards any characters that can't be in a number format. The only characters allowed are:
  686.     0 - 9 All digits
  687.     -        A minus, only if it is the first character
  688.     .       Periods are allowed
  689.  
  690.  
  691. [Code]
  692.  
  693. 'Type this code in a module or the declarations of a form.
  694. 'There is also another subroutine DoKeyPress uses, CheckPeriod.
  695.  
  696. Sub DoKeyPress (t As Control, KeyAscii As Integer)
  697.     If KeyAscii < Asc(" ") Then     ' Is this Control char?
  698.         Exit Sub                    ' Yes, let it pass
  699.     End If
  700.  
  701.     CheckPeriod t                   ' Remove excess periods
  702.  
  703.     If KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Then
  704.         ' keep digit
  705.     ElseIf KeyAscii = Asc(".") Then
  706.         ' keep .
  707.     ElseIf KeyAscii = Asc("-") And t.SelStart = 0 Then
  708.         ' Keep - only if first char
  709.     Else
  710.         KeyAscii = 0                ' Discard all other chars
  711.     End If
  712.  
  713.   
  714.     ' This code keeps you from typing any characters in front of
  715.     ' a minus sign.
  716.     
  717.     If Mid$(t.Text, t.SelStart + t.SelLength + 1, 1) = "-" Then
  718.         KeyAscii = 0                ' Discard chars before -
  719.     End If
  720. End Sub
  721.  
  722.  
  723.  
  724. [Stop]
  725. [27]
  726. Use this with the DoKeyPress subroutine. The subroutine, DoKeyPress needs the procedure. This subroutine makes sure a text box never has more than one period in it. You can also use this subroutine separate with your project.
  727. [Code]
  728.  
  729. Sub CheckPeriod (t As Control)
  730.  
  731.     Dim i As Integer
  732.     
  733.     i = InStr(1, t.Text, ".")   ' Look for a period
  734.     If i > 0 And InStr(i + 1, t.Text, ".") > 0 Then
  735.         t.SelStart = t.SelStart - 1
  736.         t.SelLength = 1         ' Select new period
  737.         t.SelText = ""          ' Remove new period
  738.     End If
  739. End Sub
  740.  
  741.  
  742.  
  743.  
  744. [Stop]
  745. [28]
  746. The Visual Basic textbox control does not support Overtype mode. Add this code to a textbox to enable the Insert key.
  747. [Code]
  748.  
  749. Sub Text1_KeyPress (KeyAscii As Integer)
  750.     If KeyAscii <> 8 And KeyAscii <> 13 And Text1.SelLength = 0 Then
  751.         Text1.SelLength = 1
  752.     End If
  753. End Sub
  754.  
  755.  
  756. [Stop]
  757. [29]
  758. How to format a floppy disk from Visual Basic.
  759.  
  760. [Code]
  761. 'Declares for Format a Floppy Disk
  762.  
  763. Type Rect
  764.     Left As Integer
  765.     Top As Integer
  766.     Right As Integer
  767.     Bottom As Integer
  768. End Type
  769.  
  770. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) 
  771. Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lpRect As Rect)
  772. Declare Function IsWindow Lib "User" (ByVal hWnd As Integer) As Integer
  773. Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine As String, ByVal nCmdShow As Integer) As Integer 
  774. Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer Declare Function GetActiveWindow Lib "User" () As Integer 
  775. Declare Function LockWindowUpdate Lib "User" (ByVal hwndLock As Integer) As Integer
  776. Declare Function GetDesktopWindow Lib "User" () As Integer 
  777. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer 
  778. Declare Function PostMessage Lib "User" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Long) As Integer 
  779. Const WM_COMMAND = &H111
  780. Const WM_CLOSE = &H10 
  781. Dim wFlag% 
  782. Dim lpDlgRect As Rect 
  783. Dim lpDskRect As Rect 
  784. Const SWP_NOSIZE = &H1 
  785. Const SWP_NOZORDER = &H4
  786.  
  787.  
  788.  
  789. Sub CenterDialog (WinText As String)
  790.    Do
  791.     If FindWindow(0&, WinText) Then Exit Do
  792.     x% = DoEvents()
  793.    Loop
  794.  
  795.  wnd% = GetActiveWindow()
  796.  Call GetWindowRect(wnd%, lpDlgRect)
  797.  wdth% = lpDlgRect.Right - lpDlgRect.Left
  798.  hght% = lpDlgRect.Bottom - lpDlgRect.Top
  799.  Call GetWindowRect(GetDesktopWindow(), lpDskRect)
  800.  Scrwdth% = lpDskRect.Right - lpDskRect.Left
  801.  Scrhght% = lpDskRect.Bottom - lpDskRect.Top
  802.  x% = (Scrwdth% - wdth%) / 2
  803.  Y% = (Scrhght% - hght%) / 2
  804.  Call SetWindowPos(wnd%, 0, x%, Y%, 0, 0, SWP_NOZORDER Or SWP_NOSIZE) 
  805. End Sub
  806.  
  807. Sub FMFormat (F As Form)
  808.  
  809.     FMhWnd = FindWindow("WFS_Frame", 0&)
  810.  
  811.     If FMhWnd = 0 Then
  812.     i% = WinExec("Winfile", 0)
  813.     FMhWnd = FindWindow("WFS_Frame", 0&)
  814.        If FMhWnd = 0 Then
  815.            MsgBox "FileMan ain't home"
  816.            Exit Sub
  817.        End If
  818.     wFlag = 1
  819.     End If
  820.  
  821.     i% = LockWindowUpdate(GetDesktopWindow())
  822.  
  823.     i% = PostMessage(FMhWnd, WM_COMMAND, &HCB, 0)
  824.  
  825.     Call CenterDialog("Format Disk")
  826.  
  827.     i% = LockWindowUpdate(0)
  828.  
  829.     wnd% = GetActiveWindow()
  830.  
  831.     While IsWindow(wnd%)
  832.     x = DoEvents()
  833.     Wend
  834.  
  835.     x = DoEvents()
  836.  
  837.     If wFlag Then
  838.     wFlag = 0
  839.     i% = PostMessage(FMhWnd, WM_CLOSE, 0, 0)
  840.     End If
  841.  
  842.     i% = SetActiveWindow(F.hWnd)
  843.  
  844. End Sub
  845.  
  846.  
  847.  
  848.  
  849. [Stop]
  850. [30]
  851. This routine allows you the dynamically remove the title bar from a VB form.
  852.  
  853.  
  854. [Code]
  855. 'Declares for Remove Title Bar
  856.  
  857. DefInt A-Z
  858. Option Explicit
  859.  
  860. Declare Function GetWindowWord% Lib "User" (ByVal hWnd%, ByVal nIndex%)
  861. Declare Function SetWindowWord% Lib "User" (ByVal hWnd%, ByVal nIndex%, 
  862. ByVal w
  863. NewWord%)
  864. Declare Function GetWindowLong& Lib "User" (ByVal hWnd%, ByVal nIndex%)
  865. Declare Function SetWindowLong& Lib "User" (ByVal hWnd%, ByVal nIndex%, ByVal 
  866. d
  867. wNewLong&)
  868.  
  869. Const GWW_ID = (-12)
  870. Const GWL_STYLE = (-16)
  871.  
  872. Const WS_DLGFRAME = &H400000
  873. Const WS_SYSMENU = &H80000
  874. Const WS_MINIMIZEBOX = &H20000
  875. Const WS_MAXIMIZEBOX = &H10000
  876.  
  877.  
  878. Sub TitleBar (frm As Form, ShowTitle)
  879.    Static Oldhmenu, SavedStyle&
  880.  
  881.    Dim NewStyle&, t&
  882.  
  883.    If ShowTitle Then
  884.       'get the current style attributes
  885.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  886.       
  887.       'set only the attributes that were removed earlier
  888.       NewStyle& = NewStyle& Or SavedStyle&
  889.       
  890.       're-establish the menu
  891.       If Oldhmenu <> 0 Then
  892.          t& = SetWindowWord%(frm.hWnd, GWW_ID, Oldhmenu)
  893.       End If
  894.       
  895.       'set the new style
  896.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  897.       
  898.       'force VB to update the form
  899.       frm.Left = frm.Left
  900.       frm.Refresh
  901.    Else
  902.       'get the current style attributes
  903.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  904.  
  905.       'determine whether the form has a dialog frame, a ControlBox,
  906.       'a minimize button, or a maximize button and save this info.
  907.       'for later use
  908.       SavedStyle& = 0
  909.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_DLGFRAME)
  910.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_SYSMENU)
  911.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MINIMIZEBOX)
  912.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MAXIMIZEBOX)
  913.  
  914.       'remove the attributes for a dialog frame, a ControlBox, a minimize
  915.       'button and a maximize button
  916.       NewStyle& = NewStyle& And Not WS_DLGFRAME
  917.       NewStyle& = NewStyle& And Not WS_SYSMENU
  918.       NewStyle& = NewStyle& And Not WS_MINIMIZEBOX
  919.       NewStyle& = NewStyle& And Not WS_MAXIMIZEBOX
  920.  
  921.       'is there a menu associated with this form?
  922.       Oldhmenu = GetWindowWord%(frm.hWnd, GWW_ID)
  923.       If Oldhmenu <> 0 Then
  924.          'yes-zero it the menu handle
  925.          t& = SetWindowWord%(frm.hWnd, GWW_ID, 0)
  926.       End If
  927.    
  928.       'set the new style
  929.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  930.  
  931.       'force VB to update the form and get rid of the title bar
  932.       frm.Left = frm.Left
  933.       frm.Refresh
  934.    End If
  935. End Sub
  936.  
  937. ' Syntax:
  938. '    TitleBar Form1, False        This will remove the title bar
  939. '    TitleBar Form1, True         This will restore the title bar
  940.  
  941. Sub TitleBar (frm As Form, ShowTitle)
  942.    Static Oldhmenu, SavedStyle&
  943.  
  944.    Dim NewStyle&, t&
  945.  
  946.    If ShowTitle Then
  947.       'get the current style attributes
  948.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  949.       
  950.       'set only the attributes that were removed earlier
  951.       NewStyle& = NewStyle& Or SavedStyle&
  952.       
  953.       're-establish the menu
  954.       If Oldhmenu <> 0 Then
  955.          t& = SetWindowWord%(frm.hWnd, GWW_ID, Oldhmenu)
  956.       End If
  957.       
  958.       'set the new style
  959.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  960.       
  961.       'force VB to update the form
  962.       frm.Left = frm.Left
  963.       frm.Refresh
  964.    Else
  965.       'get the current style attributes
  966.       NewStyle& = GetWindowLong&(frm.hWnd, GWL_STYLE)
  967.  
  968.       'determine whether the form has a dialog frame, a ControlBox,
  969.       'a minimize button, or a maximize button and save this info.
  970.       'for later use
  971.       SavedStyle& = 0
  972.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_DLGFRAME)
  973.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_SYSMENU)
  974.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MINIMIZEBOX)
  975.       SavedStyle& = SavedStyle& Or (NewStyle& And WS_MAXIMIZEBOX)
  976.  
  977.       'remove the attributes for a dialog frame, a ControlBox, a minimize
  978.       'button and a maximize button
  979.       NewStyle& = NewStyle& And Not WS_DLGFRAME
  980.       NewStyle& = NewStyle& And Not WS_SYSMENU
  981.       NewStyle& = NewStyle& And Not WS_MINIMIZEBOX
  982.       NewStyle& = NewStyle& And Not WS_MAXIMIZEBOX
  983.  
  984.       'is there a menu associated with this form?
  985.       Oldhmenu = GetWindowWord%(frm.hWnd, GWW_ID)
  986.       If Oldhmenu <> 0 Then
  987.          'yes-zero it the menu handle
  988.          t& = SetWindowWord%(frm.hWnd, GWW_ID, 0)
  989.       End If
  990.    
  991.       'set the new style
  992.       t& = SetWindowLong&(frm.hWnd, GWL_STYLE, NewStyle&)
  993.  
  994.       'force VB to update the form and get rid of the title bar
  995.       frm.Left = frm.Left
  996.       frm.Refresh
  997.    End If
  998. End Sub
  999.  
  1000.  
  1001. [Stop]
  1002. [31]
  1003. Convert characters to uppercase/lowercase in an edit box.
  1004. [Code]
  1005.  
  1006. 'for simple combo box, - no drop down
  1007.    Dim hwndListbox As Integer
  1008.    Dim childhWnd As Integer
  1009.  
  1010.    hwndListbox = GetWindow(cbo1.hWnd, GW_CHILD)
  1011.    childhWnd = GetWindow(hwndListbox, GW_HWNDNEXT)
  1012.  
  1013.    lStyle = GetWindowLong(childhWnd, GWL_STYLE)
  1014.    lStyle = lStyle Or ES_UPPERCASE
  1015.    lRes = SetWindowLong(childhWnd, GWL_STYLE, lStyle)
  1016.  
  1017. 'for drop down combo
  1018.    childhWnd = GetWindow(cbo1.hWnd, gw_child)
  1019.  
  1020.    lStyle = GetWindowLong(childhWnd, GWL_STYLE)
  1021.    lStyle = lStyle Or ES_UPPERCASE
  1022.    lRes = SetWindowLong(childhWnd, GWL_STYLE, lStyle)
  1023.  
  1024. 'plain old simple text box
  1025.    lStyle = GetWindowLong(Txt1.hWnd, GWL_STYLE)
  1026.    lStyle = lStyle Or ES_UPPERCASE
  1027.    lRes = SetWindowLong(Txt1.hWnd, GWL_STYLE, lStyle)
  1028.  
  1029. [Stop]
  1030. [32]
  1031. How to make a textbox read only and how to prevent  the user from changing the text. 
  1032. [Code]
  1033. 'Declares for Read Only Text Box
  1034.  
  1035. Global Const WM_USER = &H400
  1036. Global Const EM_SETREADONLY = (WM_USER + 31)
  1037.  
  1038. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  1039.  
  1040.  
  1041.  
  1042.  
  1043. SendMessage(Text1.hWnd, EM_SETREADONLY, 1, 0)
  1044. [Stop]
  1045. [33]
  1046. To create a tool box for an application, simply set up a form as a parent and another form as a the toolbox/floating dialog whatever.  If you try tbox.show 1 i.e. modal you'll find the form will show but you will be unable to do anything with it. Secondly you absolutely *MUST* unload the child form i.e. 
  1047. tbox BEFORE unloading the main form otherwise your program will crash.
  1048.  
  1049. [Code]
  1050. 'Declares for Tool Box
  1051.  
  1052. 'In a suitable declarations section declare the API function as follows:
  1053.  
  1054. Declare Function SetParent% Lib "User" (ByVal hWndChild%, ByVal hWndNewParent%)
  1055.  
  1056.  
  1057.  
  1058.  
  1059. Sub ShowTbox_Click () 
  1060. Dim ret As Integer 
  1061. If doshow = False Then 'toolbox not visible 
  1062.    ret = SetParent(tbox.hWnd, parent.hWnd) 'this makes the toolbox float 
  1063.    tbox.Left = 0 'sets position to top left corner of parent 
  1064.    tbox.Top = 0 
  1065.    tbox.Show 'makes toolbox visible 
  1066.    'try tbox.show 1 i.e. modal to see what happens 
  1067.    doshow = True 
  1068.    Showtbox.Caption = "&Hide Toolbox" 
  1069.       Else 
  1070.          tbox.Hide 
  1071.      doshow = False 
  1072.      Showtbox.Caption = "&Show Toolbox" 
  1073. End If 
  1074. End Sub
  1075.  
  1076. [Stop]
  1077. [34]
  1078. Listed below is a subroutine that will quit windows in three different ways if needed.  Passing 1 to it will reboot the computer, passing 2 will restart Windows, and passing 3 will exit Windows and return to DOS.
  1079.  
  1080. [Code]
  1081. 'Declares for Restart/Exit Windows
  1082.  
  1083. Declare Function ExitWindows Lib "User" (ByVal RestartCode As Long,ByVal 
  1084. DOSReturnCode As Integer) As Integer
  1085.  
  1086.  
  1087.  
  1088.  
  1089. 'Add this subroutine to a module:
  1090.  
  1091. Sub ExitWin (ByVal nExitOption As Integer) Dim n As Integer
  1092.  
  1093. n = MsgBox("Do you really want to exit Windows?", 36, "Exiting")
  1094.  
  1095.     If n = 7 Then Exit Sub 'User chose NO
  1096.  
  1097.     Select Case nExitOption
  1098.         Case 1
  1099.             n = ExitWindows(67, 0) 'reboot the computer
  1100.         Case 2
  1101.             n = ExitWindows(66, 0) 'restart Windows
  1102.         Case 3
  1103.             n = ExitWindows(0, 0) 'exit Windows
  1104.     End Select
  1105.  
  1106. End Sub
  1107.  
  1108. [Stop]
  1109. [35]
  1110. How do you write a code that checks if the user chose Yes instead of No in a msgbox? Or Yes instead of Cancel?
  1111. [Code]
  1112. Dim Msg
  1113. Msg = "Pick Yes or No"            'Here's a message
  1114. If MsgBox(Msg$, 4 + 32 + 256) <> 6 Then      'Msgbox with a question mark                
  1115.                 'andYES/ NO buttons.
  1116.     Msgbox "You chose No"
  1117. Else
  1118.     Msgbox "You chose Yes"
  1119. End If
  1120.  
  1121.  
  1122. 'This is what it means:
  1123. 'IF MsgBox(Msg.....) <> 6 Then
  1124. 'If the user chose anything besides Yes (Yes means 6) then
  1125. '.... do whatever needs to be done.
  1126. 'End If
  1127.  
  1128.  
  1129.  
  1130.  
  1131. [Stop]
  1132. [36]
  1133. Set the Timer's Interval to 60,000 put the following into the Timer_Timer event. This code will trigger code in 5 minutes. Great for an auto save routine!
  1134.  
  1135.  
  1136. [Code]
  1137. Static Counter As Integer
  1138.   Counter% = Counter% + 1
  1139.   
  1140.   If Counter% = 5 Then      
  1141.      Counter% = 0        'insert this line if you want the counter to reset
  1142. itself when it reaches 5 mins
  1143.      [YOUR CODE GOES HERE]
  1144.   End If
  1145.  
  1146.  
  1147.  
  1148. [Stop]
  1149. [37]
  1150. How to make a backgorund of a form have a gradiated style of backgorund.
  1151.  
  1152. Special thanks to:  JwpcEMail@aol.com
  1153. [Code]
  1154. 'Declares for Gradient Background Color
  1155. Type RECT
  1156.     Left As Integer
  1157.     Top As Integer
  1158.     Right As Integer
  1159.     Bottom As Integer
  1160. End Type
  1161.  
  1162. '  API Functions used to create solid brush and draw brush on form
  1163. Declare Function CreateSolidBrush Lib "GDI" (ByVal crColor As Long) As Integer
  1164. Declare Function FillRect Lib "User" (ByVal hDC As Integer, lpRect As RECT, ByVal hBrush As Integer) As Integer
  1165. Declare Function DeleteObject Lib "GDI" (ByVal hObject As Integer) As Integer
  1166.  
  1167. Dim hBrush%
  1168.  
  1169.  
  1170.  
  1171. 'Place the follwing two routines into the main form
  1172.  
  1173. Sub Form_Paint ()
  1174. fadeform Me
  1175. End Sub
  1176.  
  1177. Sub Form_Resize ()
  1178. fadeform Me
  1179. End Sub
  1180.  
  1181. 'Place the following code in a the general declarations of
  1182. 'a .bas file called: Fade.bas
  1183.  
  1184. Sub fadeform (TheForm As Form)
  1185.     Dim FormHeight%, red%, StepInterval%, X%, RetVal%, OldMode%
  1186.     Dim FillArea As RECT
  1187.     OldMode = TheForm.ScaleMode
  1188.     TheForm.ScaleMode = 3  'Pixel
  1189.     FormHeight = TheForm.ScaleHeight
  1190. ' Divide the form into 63 regions
  1191.     StepInterval = FormHeight \ 63
  1192.     red = 255
  1193.     FillArea.Left = 0
  1194.     FillArea.Right = TheForm.ScaleWidth
  1195.     FillArea.Top = 0
  1196.     FillArea.Bottom = StepInterval
  1197.     For X = 1 To 63
  1198.         hBrush% = CreateSolidBrush(RGB(0, 0, red))
  1199.         RetVal% = FillRect(TheForm.hDC, FillArea, hBrush)
  1200.         RetVal% = DeleteObject(hBrush)
  1201.         red = red - 4
  1202.         FillArea.Top = FillArea.Bottom
  1203.         FillArea.Bottom = FillArea.Bottom + StepInterval
  1204.     Next
  1205. ' Fill the remainder of the form with black
  1206.     FillArea.Bottom = FillArea.Bottom + 63
  1207.     hBrush% = CreateSolidBrush(RGB(0, 0, 0))
  1208.     RetVal% = FillRect(TheForm.hDC, FillArea, hBrush)
  1209.     RetVal% = DeleteObject(hBrush)
  1210.     TheForm.ScaleMode = OldMode
  1211. End Sub
  1212.  
  1213.  
  1214.  
  1215.  
  1216. [Stop]
  1217.