home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / iconed1a / viewicon.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-09-24  |  40.4 KB  |  1,037 lines

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