home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l407 / 5.ddi / VIEWICON.FR_ / VIEWICON.bin (.txt)
Encoding:
Visual Basic Form  |  1993-04-28  |  36.2 KB  |  920 lines

  1. VERSION 2.00
  2. Begin Form Viewer 
  3.    Caption         =   "IconWorks Viewer"
  4.    ClipControls    =   0   'False
  5.    FontBold        =   0   'False
  6.    FontItalic      =   0   'False
  7.    FontName        =   "Courier"
  8.    FontSize        =   9.75
  9.    FontStrikethru  =   0   'False
  10.    FontTransparent =   0   'False
  11.    FontUnderline   =   0   'False
  12.    ForeColor       =   &H00000000&
  13.    Height          =   4935
  14.    Icon            =   VIEWICON.FRX:0000
  15.    Left            =   1395
  16.    LinkMode        =   1  'Source
  17.    LinkTopic       =   "Form1"
  18.    ScaleHeight     =   283
  19.    ScaleMode       =   3  'Pixel
  20.    ScaleWidth      =   393
  21.    Tag             =   "IconWrks Viewer"
  22.    Top             =   1245
  23.    Width           =   6015
  24.    Begin PictureBox Pic_SelectedIconLabel 
  25.       BackColor       =   &H00FFFFFF&
  26.       BorderStyle     =   0  'None
  27.       FontBold        =   0   'False
  28.       FontItalic      =   0   'False
  29.       FontName        =   "MS Sans Serif"
  30.       FontSize        =   13.5
  31.       FontStrikethru  =   0   'False
  32.       FontTransparent =   0   'False
  33.       FontUnderline   =   0   'False
  34.       ForeColor       =   &H000000FF&
  35.       Height          =   525
  36.       Left            =   15
  37.       ScaleHeight     =   35
  38.       ScaleMode       =   3  'Pixel
  39.       ScaleWidth      =   236
  40.       TabIndex        =   19
  41.       Top             =   0
  42.       Width           =   3540
  43.       Begin PictureBox Pic_IconsBitmap 
  44.          AutoRedraw      =   -1  'True
  45.          BackColor       =   &H0000FF00&
  46.          BorderStyle     =   0  'None
  47.          FontBold        =   -1  'True
  48.          FontItalic      =   0   'False
  49.          FontName        =   "System"
  50.          FontSize        =   9.75
  51.          FontStrikethru  =   0   'False
  52.          FontUnderline   =   0   'False
  53.          Height          =   510
  54.          Left            =   0
  55.          ScaleHeight     =   34
  56.          ScaleMode       =   3  'Pixel
  57.          ScaleWidth      =   34
  58.          TabIndex        =   0
  59.          Top             =   0
  60.          Visible         =   0   'False
  61.          Width           =   510
  62.       End
  63.       Begin PictureBox Pic_SelectedIcon 
  64.          BackColor       =   &H000000FF&
  65.          BorderStyle     =   0  'None
  66.          FontBold        =   -1  'True
  67.          FontItalic      =   0   'False
  68.          FontName        =   "System"
  69.          FontSize        =   9.75
  70.          FontStrikethru  =   0   'False
  71.          FontUnderline   =   0   'False
  72.          Height          =   480
  73.          Left            =   3045
  74.          ScaleHeight     =   32
  75.          ScaleMode       =   3  'Pixel
  76.          ScaleWidth      =   32
  77.          TabIndex        =   9
  78.          Top             =   30
  79.          Width           =   480
  80.       End
  81.    End
  82.    Begin PictureBox Pic_VerticalLine 
  83.       BackColor       =   &H00000000&
  84.       BorderStyle     =   0  'None
  85.       Enabled         =   0   'False
  86.       FontBold        =   -1  'True
  87.       FontItalic      =   0   'False
  88.       FontName        =   "System"
  89.       FontSize        =   9.75
  90.       FontStrikethru  =   0   'False
  91.       FontUnderline   =   0   'False
  92.       Height          =   4245
  93.       Left            =   3555
  94.       ScaleHeight     =   4245
  95.       ScaleWidth      =   15
  96.       TabIndex        =   10
  97.       Top             =   0
  98.       Width           =   15
  99.    End
  100.    Begin PictureBox Pic_AllIcons 
  101.       BackColor       =   &H00FFFFFF&
  102.       BorderStyle     =   0  'None
  103.       FontBold        =   -1  'True
  104.       FontItalic      =   0   'False
  105.       FontName        =   "System"
  106.       FontSize        =   9.75
  107.       FontStrikethru  =   0   'False
  108.       FontUnderline   =   0   'False
  109.       Height          =   4245
  110.       Left            =   3570
  111.       MousePointer    =   10  'Up Arrow
  112.       ScaleHeight     =   283
  113.       ScaleMode       =   3  'Pixel
  114.       ScaleWidth      =   138
  115.       TabIndex        =   11
  116.       TabStop         =   0   'False
  117.       Top             =   0
  118.       Visible         =   0   'False
  119.       Width           =   2070
  120.    End
  121.    Begin VScrollBar Scrl_AllIcons 
  122.       Height          =   4275
  123.       Left            =   5640
  124.       TabIndex        =   12
  125.       Top             =   -15
  126.       Visible         =   0   'False
  127.       Width           =   270
  128.    End
  129.    Begin TextBox Txt_FileName 
  130.       Height          =   330
  131.       Left            =   795
  132.       TabIndex        =   1
  133.       Top             =   525
  134.       Width           =   2775
  135.    End
  136.    Begin PictureBox Pic_IconCount 
  137.       BackColor       =   &H00FF0000&
  138.       BorderStyle     =   0  'None
  139.       FontBold        =   0   'False
  140.       FontItalic      =   0   'False
  141.       FontName        =   "MS Sans Serif"
  142.       FontSize        =   8.25
  143.       FontStrikethru  =   0   'False
  144.       FontTransparent =   0   'False
  145.       FontUnderline   =   0   'False
  146.       ForeColor       =   &H00FFFFFF&
  147.       Height          =   210
  148.       Left            =   1365
  149.       ScaleHeight     =   210
  150.       ScaleWidth      =   420
  151.       TabIndex        =   13
  152.       Top             =   1335
  153.       Visible         =   0   'False
  154.       Width           =   420
  155.    End
  156.    Begin DirListBox Dir_DirectoryList 
  157.       Height          =   2175
  158.       Left            =   -15
  159.       TabIndex        =   3
  160.       Top             =   1560
  161.       Width           =   1800
  162.    End
  163.    Begin FileListBox File_FileList 
  164.       Height          =   2175
  165.       Left            =   1770
  166.       Pattern         =   "*.ico"
  167.       TabIndex        =   5
  168.       Top             =   1560
  169.       Width           =   1800
  170.    End
  171.    Begin DriveListBox Drv_DriveList 
  172.       Height          =   1530
  173.       Left            =   -15
  174.       TabIndex        =   7
  175.       Top             =   3945
  176.       Width           =   3585
  177.    End
  178.    Begin Line line_HorizontalLine 
  179.       X1              =   0
  180.       X2              =   235
  181.       Y1              =   35
  182.       Y2              =   35
  183.    End
  184.    Begin Label Lbl_File 
  185.       Caption         =   "Fi&le:"
  186.       Height          =   210
  187.       Left            =   0
  188.       TabIndex        =   8
  189.       Top             =   585
  190.       Width           =   795
  191.    End
  192.    Begin Label Lbl_Directory 
  193.       Caption         =   "Directory:"
  194.       Height          =   210
  195.       Left            =   0
  196.       TabIndex        =   14
  197.       Top             =   870
  198.       Width           =   1380
  199.    End
  200.    Begin Label Lbl_CurrentDirectory 
  201.       Alignment       =   2  'Center
  202.       BorderStyle     =   1  'Fixed Single
  203.       Height          =   240
  204.       Left            =   -15
  205.       TabIndex        =   15
  206.       Top             =   1080
  207.       Width           =   3585
  208.    End
  209.    Begin Label Lbl_Directories 
  210.       Caption         =   "&Directories:"
  211.       Height          =   210
  212.       Left            =   0
  213.       TabIndex        =   2
  214.       Top             =   1335
  215.       Width           =   1365
  216.    End
  217.    Begin Label Lbl_Icons 
  218.       Alignment       =   2  'Center
  219.       Caption         =   "&Icons"
  220.       Height          =   210
  221.       Left            =   1785
  222.       TabIndex        =   4
  223.       Top             =   1335
  224.       Width           =   1755
  225.    End
  226.    Begin Label Lbl_Drives 
  227.       Caption         =   "Dri&ves:"
  228.       Height          =   210
  229.       Left            =   0
  230.       TabIndex        =   6
  231.       Top             =   3735
  232.       Width           =   1365
  233.    End
  234.    Begin Menu Menu_File 
  235.       Caption         =   "&File"
  236.       Begin Menu Menu_FileSelection 
  237.          Caption         =   "&Open"
  238.          Index           =   1
  239.       End
  240.       Begin Menu Menu_FileSelection 
  241.          Caption         =   "-"
  242.          Index           =   2
  243.       End
  244.       Begin Menu Menu_FileSelection 
  245.          Caption         =   "E&xit"
  246.          Index           =   5
  247.       End
  248.    End
  249.    Begin Menu Menu_Edit 
  250.       Caption         =   "&Edit"
  251.       Begin Menu Menu_EditCopy 
  252.          Caption         =   "&Copy"
  253.       End
  254.    End
  255.    Begin Menu Menu_Options 
  256.       Caption         =   "&Options"
  257.       Begin Menu Menu_OptionsSelection 
  258.          Caption         =   "&Editor..."
  259.          Index           =   0
  260.          Shortcut        =   {F7}
  261.       End
  262.       Begin Menu Menu_OptionsSelection 
  263.          Caption         =   "&Show all Icons"
  264.          Index           =   1
  265.          Shortcut        =   ^V
  266.       End
  267.       Begin Menu Menu_OptionsSelection 
  268.          Caption         =   "-"
  269.          Index           =   2
  270.       End
  271.       Begin Menu Menu_OptionsSelection 
  272.          Caption         =   "Show all icons on &DIR change"
  273.          Index           =   3
  274.       End
  275.    End
  276.    Begin Menu Menu_Help 
  277.       Caption         =   "&Help"
  278.       Begin Menu Menu_HelpSelection 
  279.          Caption         =   "&Index"
  280.          Index           =   1
  281.          Shortcut        =   {F1}
  282.       End
  283.       Begin Menu Menu_HelpSelection 
  284.          Caption         =   "&Keyboard"
  285.          Index           =   2
  286.       End
  287.       Begin Menu Menu_HelpSelection 
  288.          Caption         =   "&Commands"
  289.          Index           =   3
  290.       End
  291.       Begin Menu Menu_HelpSelection 
  292.          Caption         =   "&Using Help"
  293.          Index           =   4
  294.       End
  295.       Begin Menu Menu_HelpSelection 
  296.          Caption         =   "-"
  297.          Index           =   5
  298.       End
  299.       Begin Menu Menu_HelpSelection 
  300.          Caption         =   "&About..."
  301.          Index           =   6
  302.       End
  303.    End
  304. DefInt A-Z
  305. Dim Badicon
  306. Sub Adjust_All_Controls ()
  307.     ' Save the visibility state of the Icon viewing window, since
  308.     ' we resize it whether it is visible or not.
  309.     '
  310.     AllIconsVisible = Pic_AllIcons.Visible
  311.     ' Hide all controls that can be resized, while the actual resizing is
  312.     ' being done.  This prevents uneccessary screen updates.
  313.     '
  314.     Pic_AllIcons.Visible = False
  315.     Scrl_AllIcons.Visible = False
  316.     File_FileList.Visible = False
  317.     Dir_DirectoryList.Visible = False
  318.     ' Calculate number of icon rows and columns for the new Window size,
  319.     ' and the maximum number of icons that can be displayed at once
  320.     ' within the new window size.
  321.     '
  322.     IconRows = ScaleHeight \ ICON_CELL
  323.     IconColumns = (ScaleWidth - Pic_AllIcons.Left) \ ICON_CELL
  324.     MaxIcons = IconColumns * IconRows
  325.     ' Set new width for the icon viewing area
  326.     '
  327.     NewAllIconsWidth = ScaleWidth - Pic_AllIcons.Left + 1
  328.     ' Check if there are more icons than can be displayed at once in the viewing window
  329.     '
  330.     If File_FileList.ListCount > MaxIcons Then
  331.         '
  332.         ' All the icons cannot be displayed at once, so the viewing area must be
  333.         ' reset, the Viewing area Scrollbar must be reset, and the number of icon
  334.         ' columns must be reset since the scrollbar now takes up part of the viewing area.
  335.         '
  336.         Scrl_AllIcons.Left = ScaleWidth - Scrl_AllIcons.Width + 1
  337.         NewAllIconsWidth = Scrl_AllIcons.Left - Pic_AllIcons.Left
  338.         IconColumns = NewAllIconsWidth \ ICON_CELL
  339.         MaxIcons = IconColumns * IconRows
  340.     End If
  341.       
  342.     ' Resize and Repostion affected controls
  343.     '
  344.     Pic_AllIcons.Move Pic_AllIcons.Left, Pic_AllIcons.Top, NewAllIconsWidth, ScaleHeight
  345.     Scrl_AllIcons.Height = ScaleHeight + 2
  346.     Pic_VerticalLine.Height = ScaleHeight
  347.     Drv_DriveList.Top = ScaleHeight - Drv_DriveList.Height + 1
  348.     Lbl_Drives.Top = Drv_DriveList.Top - Lbl_Drives.Height
  349.     File_FileList.Height = Lbl_Drives.Top - Dir_DirectoryList.Top - 1
  350.     Dir_DirectoryList.Height = File_FileList.Height
  351.     ' Redisplay controls hidden before resizing and reposition was done
  352.     '
  353.     Pic_AllIcons.Visible = AllIconsVisible
  354.     File_FileList.Visible = True
  355.     Dir_DirectoryList.Visible = True
  356. End Sub
  357. Sub Dir_DirectoryList_Change ()
  358.     ' A new directory has been selected, so Set current directory
  359.     ' to the newly selected directory
  360.     '
  361.     ChDir Dir_DirectoryList.Path
  362.     ' Display the newly selected directory
  363.     '
  364.     Lbl_CurrentDirectory.Caption = Dir_DirectoryList.Path
  365.     ' Inform the File ListBox of the PathChange.
  366.     '
  367.     File_FileList.Path = Dir_DirectoryList.Path
  368.     ' Display new filespec in FileName TextBox
  369.     '
  370.     UpDate_FileSpec Viewer
  371. End Sub
  372. Sub Dir_DirectoryList_Click ()
  373.     ' The actual directory has not changed since the Directory ListBox was
  374.     ' only single clicked , so all we need to do is display the new file
  375.     ' spec for the selected directory in the FileName TextBox.
  376.     '
  377.     UpDate_FileSpec Viewer
  378.     VLastChanged = DIR_CHANGED
  379. End Sub
  380. Sub Dir_DirectoryList_KeyPress (KeyAscii As Integer)
  381.     ' Pressing Enter when the Directory ListBox has the Focus should
  382.     ' react just as if the Directory ListBox was double clicked, so all we
  383.     ' need to do is set the Path property of the Directory control to the
  384.     ' selected directory.
  385.     '
  386.     If KeyAscii = 13 Then Dir_DirectoryList.Path = Dir_DirectoryList.List(Dir_DirectoryList.ListIndex)
  387. End Sub
  388. Sub Drv_DriveList_Change ()
  389.     ' Selecting a drive from a Drive control does not generate an error
  390.     ' if the selected drive is not ready, so we verify that the drive is
  391.     ' in fact ready before we accept the drive.
  392.     '
  393.     Validate_And_Change_Drives Viewer
  394. End Sub
  395. Sub File_FileList_Click ()
  396.     If File_FileList.ListIndex >= 0 Then
  397.         ' When a file is selected from the File Listbox with single click
  398.         ' from the mouse, this routine displays the selected icon just above
  399.         ' the file listbox if it is a valid Icon file.
  400.         '
  401.         Txt_FileName.Text = File_FileList.FileName
  402.         Badicon = Not Valid_Icon((File_FileList.FileName), True)
  403.         If Not Badicon Then
  404.             '
  405.             ' File is valid Icon file
  406.             '
  407.             Menu_EditCopy.Enabled = True
  408.             VLastChanged = FILE_CHANGED
  409.         End If
  410.     End If
  411. End Sub
  412. Sub File_FileList_DblClick ()
  413.     ' Double Clicking a file within the File ListBox signals that an
  414.     ' existing file has been selected, so attempt to open the file.
  415.     '
  416.     If Not Badicon Then
  417.         VLastChanged = FILE_CHANGED
  418.         Open_Selected_Icon
  419.     End If
  420. End Sub
  421. Sub File_FileList_KeyPress (KeyAscii As Integer)
  422.     ' Pressing Enter when the File ListBox has the Focus should react
  423.     ' just as if the File ListBox was Double Clicked, so all we need
  424.     ' to do is attempt to open the selected file.
  425.     '
  426.     VLastChanged = FILE_CHANGED
  427.     If KeyAscii = 13 Then Open_Selected_Icon
  428. End Sub
  429. Sub File_FileList_PathChange ()
  430.     ShowingAllIcons = False
  431.     If (File_FileList.ListCount > 0) And Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked Then
  432.         '
  433.         ' There are icons in the new directory and the user has selected
  434.         ' to automatically display all icons when the directory is changed,
  435.         ' so we simulate selecting the menu item which displays all the icons.
  436.         '
  437.         Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  438.     Else
  439.         ' There are no icons in the current directory, or the user does
  440.         ' not want to automatically display all icons when the directory
  441.         ' changes, so we need to get rid of all displayed icons.
  442.         '
  443.         Scrl_AllIcons.Visible = False
  444.         Pic_AllIcons.Visible = False
  445.         Pic_Selectedicon.Picture = LoadPicture()
  446.     End If
  447.     ' The menu item to show all icons, is enabled if the current directory
  448.     ' contains icons, and disabled if it does not.
  449.     '
  450.     Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled = File_FileList.ListCount > 0
  451.     ' Display the number of icons in the current directory
  452.     '
  453.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  454. End Sub
  455. Sub Form_Load ()
  456.     Pic_IconsBitmap.Move 0, 0, 34, 34
  457.     Pic_Selectedicon.Move Pic_Selectedicon.Left, Pic_Selectedicon.Top, 32, 32
  458.     Pic_Selectedicon.BackColor = WHITE
  459.     Pic_IconsBitmap.BackColor = WHITE
  460.     ' Inform rest of Iconworks that the Viewer is loaded.  Viewer.Visible could
  461.     ' be tested but accessing the visible property would cause the Viewer to be
  462.     ' loaded if not already loaded.
  463.     '
  464.     ViewerLoaded = True
  465.     Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked = -GetPrivateProfileInt(APP_NAME, KEY_SHOW_ICONS, 0, INI_FILENAME)
  466.     ' Position Viewer at 0,0, and set Width and Height to 2/3's that of the Screen.
  467.     '
  468.     Move 0, 0, Screen.Width * .66, Screen.Height * .66
  469.     ' Calculate the Minimum width and Height for the Viewer.  This is done, so
  470.     ' the smallest window allowed will still allow easy access to all controls.
  471.     '
  472.     MinViewerWidth = (Pic_VerticalLine.Left + Scrl_AllIcons.Width + ICON_CELL + 2) * 15 + (Width - ScaleWidth * 15)
  473.     MinViewerHeight = ICON_CELL * 6 * 15 + (Height - ScaleHeight * 15)
  474.     ' Enable the "Show all icons' menu option only if the current directory
  475.     ' contains icons
  476.     '
  477.     Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled = File_FileList.ListCount > 0
  478.     ' Display the number of icons in the current directory, display the
  479.     ' current directory, and set the current file name to the default
  480.     ' file spec of "*.ICO", which was set at design time into the File
  481.     ' ListBox.
  482.     '
  483.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  484.     Lbl_CurrentDirectory.Caption = Dir_DirectoryList.Path
  485.     Txt_FileName.Text = File_FileList.Pattern
  486.     VLastChanged = DIR_CHANGED
  487.     ' The Alt+F4 accelerator for Exit, cannot be assigned using the Menu
  488.     ' design Window, so we need to put the accelerator into the caption.
  489.     ' Alt+F4 is actually the System menus Close option.
  490.     '
  491.     Menu_FileSelection(MID_EXIT).Caption = "E&xit" + A_TAB + "Alt+F4"
  492.                                         
  493.     Show
  494.     Refresh
  495.     If Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked And (File_FileList.ListCount <> 0) Then Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  496. End Sub
  497. Sub Form_Resize ()
  498.     ' The Form has been resized, so we need to resize and possible reposition
  499.     ' some of the controls on the form, however, we do not want to do anything
  500.     ' if the form is minimized.
  501.     '
  502.     If WindowState <> MINIMIZED Then
  503.         '
  504.         ' Check if new size is less than the minimum Viewer size.
  505.         '
  506.         If (Width < MinViewerWidth) Or (Height < MinViewerHeight) Then
  507.             '
  508.             ' The form is smaller than the minimum size, either in width or
  509.             ' height, so reset the width and/or height to the minimum values.
  510.             '
  511.             If Width < MinViewerWidth Then NewWidth = MinViewerWidth Else NewWidth = Width
  512.             If Height < MinViewerHeight Then NewHeight = MinViewerHeight Else NewHeight = Height
  513.             Move Left, Top, NewWidth, NewHeight
  514.         Else
  515.             ' The form is greater than the minimum width and height values
  516.             ' so adjust any controls that need resizing or repositioning.
  517.             '
  518.             Adjust_All_Controls
  519.             Scrl_AllIcons.Value = 0
  520.             If (File_FileList.ListCount > MaxIcons) And ShowingAllIcons Then
  521.                 '
  522.                 ' There are more icons that can be displayed at once within
  523.                 ' the current new size of the Form, so we need to calculate
  524.                 ' new Max and LargeChange values for the scrollbar.
  525.                 '
  526.                 Diff = File_FileList.ListCount - MaxIcons
  527.                 Scrl_AllIcons.Max = Diff \ IconColumns
  528.                 If (Diff Mod IconColumns) Then Scrl_AllIcons.Max = Scrl_AllIcons.Max + 1
  529.                 Scrl_AllIcons.LargeChange = IconRows
  530.                 Scrl_AllIcons.Visible = True' And (File_FileList.ListCount > MaxIcons)
  531.             End If
  532.         End If
  533.     End If
  534. End Sub
  535. Sub Form_Unload (Cancel As Integer)
  536.     ' Let the rest of IconWorks know that the Viewer is no longer loaded.
  537.     '
  538.     ViewerLoaded = False
  539.     ShowingAllIcons = False
  540.     R = WinHelp(hwnd, dummy$, HELP_QUIT, 0)
  541.     R = WritePrivateProfileString(APP_NAME, KEY_SHOW_ICONS, Format$(Abs(Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked)), INI_FILENAME)
  542.     ' If the Viewer was started up first then we treat it as the main Form.
  543.     ' So, if the Editor is loaded, we should as the user if the Editor should
  544.     ' also be terminated.
  545.     '
  546.     If (MainForm = ICONWORKS_VIEWER) And (EditorLoaded) Then
  547.         '
  548.         ' Viewer was started first and the Editor is loaded so ask the user
  549.         ' if the Editor should also be terminated.
  550.         '
  551.         Text = "Terminate Editor Also?"
  552.         If MsgBox(Text, 36, "IconWorks") = MBYES Then Unload Editor
  553.         MainForm = ICONWORKS_EDITOR
  554.     End If
  555. End Sub
  556. ' When a request is made to display all the icons in the current directory
  557. ' this routine is called to perform the task.
  558. Sub Load_All_Icons ()
  559.     If CurDir$ <> File_FileList.Path Then ChDir File_FileList.Path
  560.     ' Refresh the File listbox to pick up any files that might have been
  561.     ' added to the current directory since this directory was selected.
  562.     '
  563.     File_FileList.Refresh
  564.     ' Determine if the scrollbar is needed.  If there are more icons in the
  565.     ' current directory than can be displayed at once, the scrollbar must
  566.     ' be active to allow viewing of all the icons.
  567.     '
  568.     Scrl_AllIcons.Visible = File_FileList.ListCount > MaxIcons
  569.     Scrl_AllIcons.Value = 0
  570.     ' Display the Icon Viewing window
  571.     '
  572.     Pic_AllIcons.Visible = True
  573.      
  574.     ' When all the icons are displayed, a single bitmap is created and maintained
  575.     ' in memory.  This bitmap contains the images of all the icons in the current
  576.     ' directory.  This bitmap is used to update the Viewing Window when the window
  577.     ' is scrolled or when the Form is resized.  The bitmap is made of the image
  578.     ' of each icon concatenated into one long bitmap.  This makes for a very fast
  579.     ' screen update when the icons need to be redisplayed.  The icons do not have
  580.     ' to be reloaded each time, but simply copied from this bitmap to the viewing
  581.     ' window.
  582.     '
  583.     Pic_IconsBitmap.Width = File_FileList.ListCount * ICON_CELL
  584.     Pic_IconsBitmap.Cls
  585.     ' To build the memory Icon Bitmap above, each icon must be loaded at least
  586.     ' once so as to obtain its image and add it to the memory bitmap.  The
  587.     ' Pic_SelectedIcon picture contol is used for this purpose, but to prevent
  588.     ' uneccessary flashing of this picture control as each icon is loaded,
  589.     ' it is hidden while this is going on.  And since it is hidden while this
  590.     ' is occuring, AutoRedraw must be set to TRUE to allow copying of the image
  591.     ' while it is hidden.  The image is copied using the Windows API routine
  592.     ' BitBlt().
  593.     '
  594.     Pic_Selectedicon.Visible = False
  595.     Pic_Selectedicon.AutoRedraw = True
  596.     ' So something is visibly happening while the icons are being loaded and the
  597.     ' bitmap is being created, the File Listbox label's color is changed, and
  598.     ' the Lbl_IconCount is made visible.  These labels count and display the number
  599.     ' of icons loaded as they are being loaded.
  600.     '
  601.     Lbl_Icons.Caption = "Icons Loaded"
  602.     Lbl_Icons.ForeColor = WHITE
  603.     Lbl_Icons.BackColor = RED
  604.     Lbl_Icons.Refresh
  605.     Pic_IconCount.Visible = True
  606.     ' Attempt to load all files listed in the File ListBox.  If valid Icon files
  607.     ' add image to memory bitmap.
  608.     '
  609.     Screen.MousePointer = HOURGLASS
  610.     For X = 0 To File_FileList.ListCount - 1
  611.         '
  612.         ' Display current count of Icons loaded
  613.         '
  614.         Pic_IconCount.CurrentX = 0
  615.         Pic_IconCount.Print X + 1; "  ";
  616.         If Valid_Icon((File_FileList.List(X)), False) Then
  617.             '
  618.             ' The file was a valid Icon file, so add its image to the memory Bitamp
  619.             '
  620.             R = BitBlt(Pic_IconsBitmap.hDC, 2 + X * ICON_CELL, 0, 32, 32, Pic_Selectedicon.hDC, 0, 0, SRCCOPY)
  621.         Else
  622.             ' The file was not a valid Icon file, so display a BLACK square where the icons
  623.             ' image would have been placed within the Memory bitmap.
  624.             '
  625.             R = BitBlt(Pic_IconsBitmap.hDC, 2 + X * ICON_CELL, 0, 32, 32, 0, 0, 0, BLACKNESS)
  626.         End If
  627.     Next X
  628.     Screen.MousePointer = DEFAULT
  629.     ' Re-Display the SelectedIcon picture and disable its AutoRedraw since
  630.     ' it is no longer needed.
  631.     '
  632.     Pic_Selectedicon.Visible = True
  633.     Pic_Selectedicon.AutoRedraw = False
  634.     ' Reset the File list Labels to normal, and display the total number of Icons loaded.
  635.     '
  636.     Lbl_Icons.ForeColor = WINDOW_TEXT
  637.     Lbl_Icons.BackColor = WINDOW_BACKGROUND
  638.     Lbl_Icons.Caption = Format$(File_FileList.ListCount) + " &Icons"
  639.     ' Hide the IconCount label since it is not needed except while loading icons.
  640.     '
  641.     Pic_IconCount.Visible = False
  642. End Sub
  643. Sub Menu_EditCopy_Click ()
  644.     ' Can't place an actual Icon into the System clipboard, so place
  645.     ' a bitmap of its image, in response to a copy command.
  646.     '
  647.     Clipboard.Clear
  648.     Clipboard.SetData Pic_Selectedicon.Image
  649. End Sub
  650. Sub Menu_File_Click ()
  651.     ' Before displaying the file menu, enable or disable the File.Open
  652.     ' command, based on whether or not an Icon is currently selected.
  653.     '
  654.     Menu_FileSelection(MID_OPEN).Enabled = File_FileList.ListIndex >= 0
  655. End Sub
  656. Sub Menu_FileSelection_Click (Index As Integer)
  657.     ' One of the 2 File menu items were selected, so determine which one
  658.     ' and perform the corresponding task.
  659.     '
  660.     Select Case Index
  661.         
  662.         Case MID_OPEN
  663.             Open_Selected_Icon
  664.             
  665.         Case MID_EXIT
  666.             Unload Viewer
  667.     End Select
  668. End Sub
  669. Sub Menu_HelpSelection_Click (Index As Integer)
  670.     If Index < MID_ABOUT Then
  671.         '
  672.         ' Determine what help topic to display.  The *Index* and *Using Help*
  673.         ' items are the same for both the Viewer and the Editor, but the
  674.         ' items: Keyboard and Commands are different and have
  675.         ' different Help topic ID's, so we add 3 to the Menu item which
  676.         ' will then make the Index correspond to the correct Help topic.
  677.         '
  678.         If (Index >= MID_KEYBOARD) And (Index <= MID_COMMANDS) Then Index = Index + 3
  679.         Get_Help Index
  680.     Else
  681.         ' Display the IconWorks About box
  682.         '
  683.         AboutBox.Show MODAL
  684.     End If
  685. End Sub
  686. Sub Menu_OptionsSelection_Click (Index As Integer)
  687.     ' One of the 3 Options menu items were selected, so determine which one
  688.     ' and perform the corresponding task.
  689.     '
  690.     Select Case Index
  691.         
  692.         Case MID_EDITOR
  693.             ' Invoke the Editor, but do not open the selected Icon
  694.             '
  695.             Editor.Show MODELESS
  696.         Case MID_SHOW_ALL_ICONS
  697.             ' Check for too man Icons to display.  maximum of 963.
  698.             '
  699.             If File_FileList.ListCount > 900 Then
  700.                 MsgBox "Can display upto a maximum of 900 icons", 16, "Too many Icons"
  701.             Else
  702.                 '
  703.                 ' Let the rest of the Viewer know that all the Icons are currently
  704.                 ' begin displayed.
  705.                 '
  706.                 Temp = ShowingAllIcons
  707.                 ShowingAllIcons = True
  708.                 ' Before showing all the icons, the values for the scrollbar must
  709.                 ' be re-calculated based on the number of icons in the current
  710.                 ' directory.  Since this is done when the form is resized, we can
  711.                 ' accomplish this by calling the Form_Resize event to do this for us.
  712.                 '
  713.                 If Not Temp Then Form_Resize
  714.                  
  715.                 ' We disable the Edit.Copy menu Item, since after all icons are
  716.                 ' displayed, no one icon will be selected yet.
  717.                 '
  718.                 Menu_EditCopy.Enabled = False
  719.                 ' Load all the icons and then display them
  720.                 '
  721.                 Load_All_Icons
  722.                 Update_Displayed_Icons
  723.             End If
  724.         Case MID_SHOW_ON_DIR_CHANGE
  725.             '
  726.             ' Toggle the Checked property of the *Show all icons* options.
  727.             '
  728.             Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked = Not Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked
  729.             If Menu_OptionsSelection(MID_SHOW_ON_DIR_CHANGE).Checked And Menu_OptionsSelection(MID_SHOW_ALL_ICONS).Enabled Then Menu_OptionsSelection_Click MID_SHOW_ALL_ICONS
  730.     End Select
  731. End Sub
  732. Sub Open_Selected_Icon ()
  733. Dim OldPattern As String
  734.     If VLastChanged = DIR_CHANGED Then
  735.         '
  736.         ' The directory was the last control accessed, so we need only
  737.         ' set its Path to is currently selected item, which will generate
  738.         ' a Change event for the Directory control, which will take care
  739.         ' of updating the other related controls
  740.         '
  741.         Dir_DirectoryList.Path = Dir_DirectoryList.List(Dir_DirectoryList.ListIndex)
  742.     Else
  743.         ' The FileName TextBox or the File ListBox was last accessed.
  744.         '
  745.         ValidName = True
  746.         ' Validate the filename only if the FileName TextBox was the last
  747.         ' control accessed.  We do not need to Validate the Filename if the
  748.         ' File ListBox was last accessed since if the FileName is listed,
  749.         ' then the File exists.
  750.         '
  751.         If VLastChanged = FILENAME_CHANGED Then ValidName = Validate_FileSpec(Viewer, True)
  752.       
  753.         ' The FileName entered into the FileName TextBox many have contained
  754.         ' a new drive and path, so in case it did, we need to inform the
  755.         ' Drive and Directory controls of this change.
  756.         '
  757.         ChDir File_FileList.Path
  758.         Drv_DriveList.Drive = Left$(File_FileList.Path, 2)
  759.         Dir_DirectoryList.Path = File_FileList.Path
  760.         If ValidName Then
  761.             If Valid_Icon((Txt_FileName.Text), True) Then
  762.                 '
  763.                 ' A file has been selected so invoke the Editor, and load the
  764.                 ' icon into the editor.
  765.                 '
  766.                 Editor.Show MODELESS
  767.                 Load_An_Icon
  768.             End If
  769.         End If
  770.     End If
  771. End Sub
  772. Sub Pic_AllIcons_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  773.     ' Selections are made only with the Left mouse button.
  774.     '
  775.     If Button = LEFT_BUTTON Then
  776.         '
  777.         ' We need to determine if an icon was has actually been selected
  778.         ' by the MouseDown event, since an Icon does not exist at every
  779.         ' location within the Viewing area (Pic_AllIcons).  So, we
  780.         ' need to calculate the icon position selected based on the
  781.         ' mouse coordinates and then check if an Icon exists at that location.
  782.         ' Calculate the column of the selected Icon position.
  783.         '
  784.         XIcon = X \ ICON_CELL
  785.         
  786.         ' Determine if any icons exist in that column.
  787.         '
  788.         If XIcon < IconColumns Then
  789.             '
  790.             ' A valid Column has been selected, so we now need to calculate
  791.             ' the selected Row position.  The Scrollbar's value must be
  792.             ' considered when calculating the Row.
  793.             '
  794.             YIcon = Y \ ICON_CELL + Scrl_AllIcons.Value
  795.             ' Using the Column and Row selected, calculate the actual
  796.             ' Icon position selected.
  797.             '
  798.             SelectedIcon = (YIcon * IconColumns) + XIcon
  799.             ' Determine if an Icon exists at the selected location
  800.             '
  801.             If SelectedIcon < File_FileList.ListCount Then
  802.                 '
  803.                 ' An icon has been selected, so select the Icon in the File ListBox
  804.                 '
  805.                 File_FileList.ListIndex = -1
  806.                 File_FileList.ListIndex = SelectedIcon
  807.                 ' If icon is a valid Win 3.0 icon, begin dragging.
  808.                 '
  809.                 If Not Badicon Then
  810.                     Pic_AllIcons.DragIcon = Pic_Selectedicon.DragIcon
  811.                     Pic_AllIcons.Drag
  812.                 End If
  813.             End If
  814.         End If
  815.     End If
  816. End Sub
  817. Sub Pic_AllIcons_Paint ()
  818.     ' A portion of the viewing area needs to be updated, so if we
  819.     ' are currently displaying any icons, Update the viewing area.
  820.     '
  821.     If ShowingAllIcons And (File_FileList.ListCount > 0) Then Update_Displayed_Icons
  822. End Sub
  823. Sub Pic_SelectedIcon_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  824.     If (Button = LEFT_BUTTON) And (File_FileList.ListIndex >= 0) Then
  825.         '
  826.         ' Set the DragIcon to the Selected Icon so we see the actual icon
  827.         ' when dragging, instead of an inverted Frame of the picture control,
  828.         ' and begin dragging the icon.
  829.         '
  830.         'Pic_SelectedIcon.DragIcon = Pic_SelectedIcon.Picture
  831.         Pic_Selectedicon.Drag
  832.     End If
  833. End Sub
  834. Sub Pic_SelectedIconLabel_Paint ()
  835.     Text = "Selected Icon:"
  836.     Pic_SelectedIconLabel.CurrentX = (Pic_SelectedIconLabel.ScaleWidth - Pic_SelectedIconLabel.TextWidth(Text)) \ 2
  837.     Pic_SelectedIconLabel.CurrentY = (Pic_SelectedIconLabel.ScaleHeight - Pic_SelectedIconLabel.TextHeight(Text)) \ 2
  838.     Pic_SelectedIconLabel.Print Text
  839. End Sub
  840. Sub Scrl_AllIcons_Change ()
  841.     ' The Scrollbar was scrolled, so we need to scroll the displayed
  842.     ' icons within the viewing window.  The Update_Displayed_Icons
  843.     ' procedure displays the Icons based on the Value of the scrollbar
  844.     ' if the scrollbar is currently visible.
  845.     '
  846.     Update_Displayed_Icons
  847. End Sub
  848. Sub Txt_FileName_Change ()
  849.     VLastChanged = FILENAME_CHANGED
  850. End Sub
  851. Sub Txt_FileName_KeyPress (KeyAscii As Integer)
  852.     If KeyAscii = 13 Then
  853.         '
  854.         ' Enter was pressed, so cancel the KeyStroke to prevent a Beep,
  855.         ' and attempt to open the selected file as an Icon.
  856.         '
  857.         KeyAscii = 0
  858.         Open_Selected_Icon
  859.     End If
  860. End Sub
  861. Sub Update_Displayed_Icons ()
  862.     ' When the form is resized, the scrollbar is scrolled, or anything causing the
  863.     ' currently displayed icons to be updated, this routine is called to display
  864.     ' or redisplay the icons in the viewing window.
  865.     '
  866.     ' Clear the viewing window to White.  The .Cls method could be used, but
  867.     ' it causes excessive flashing, so the .Line method is used instead to
  868.     ' draw a filled white box inside the viewing window, which accomplishes
  869.     ' the same thing but a little more efficiently.
  870.     '
  871.     Pic_AllIcons.Line (0, (IconRows - 1) * ICON_CELL)-(Pic_AllIcons.Width, Pic_AllIcons.Height), WHITE, BF
  872.     ' Calculate the number of icon rows that need to be displayed.  It could
  873.     ' be all the rows or only a few if all the icons can fit in the current size
  874.     ' of the viewing window.
  875.     '
  876.     NumIconRows = IconRows
  877.     If MaxIcons > File_FileList.ListCount Then NumIconRows = File_FileList.ListCount \ IconColumns
  878.     ' Determine what icon should be the first icon displayed (Upper left hand
  879.     ' corner of viewing window) based on the current value of the Scrollbar.
  880.     '
  881.     FirstIcon = Scrl_AllIcons.Value * IconColumns
  882.     ' An entire row of Icons is displayed at once which is copied from the memory
  883.     ' bitmap of the icon images.  So we need to calculate the width in pixels
  884.     ' of the current with of a row of Icons, since this can change whenever the
  885.     ' form is resized.
  886.     '
  887.     PixelWidth = IconColumns * ICON_CELL
  888.     XSrc = FirstIcon * ICON_CELL
  889.     Y = 1
  890.     ' Copy icons from the memory Bitmap one row at a time to the viewing window
  891.     '
  892.     For row = 0 To NumIconRows
  893.         R = BitBlt(Pic_AllIcons.hDC, 0, Y, PixelWidth, ICON_CELL, Pic_IconsBitmap.hDC, XSrc, 0, SRCCOPY)
  894.         XSrc = XSrc + PixelWidth
  895.         Y = Y + ICON_CELL
  896.     Next row
  897. End Sub
  898. Function Valid_Icon (FileName As String, Prompt)
  899.     On Error Resume Next
  900.     ' Set Err to no Error (FALSE) and attempt to load the selected file
  901.     '
  902.     Err = False
  903.     Pic_Selectedicon.DragIcon = LoadPicture(FileName)
  904.     If Err And Prompt Then
  905.         '
  906.         ' The file is not a valid Icon file
  907.         '
  908.         Beep
  909.         X = MsgBox(FileName + " is not a valid Win 3.0 .ICO file", 16, "Bad File")
  910.         Pic_Selectedicon.Picture = LoadPicture()
  911.         Menu_EditCopy.Enabled = False
  912.         Txt_FileName.Text = File_FileList.Pattern
  913.         VLastChanged = DIR_CHANGED
  914.     ElseIf Not Err Then
  915.         Pic_Selectedicon.Picture = Pic_Selectedicon.DragIcon
  916.     End If
  917.     Valid_Icon = (Err = 0)
  918.     On Error GoTo 0
  919. End Function
  920.