home *** CD-ROM | disk | FTP | other *** search
- REM Description: Manage 'List Files of Type' entries
- REM Filename: lstfiles.wmc
- REM Created by: Steve Wylie - 11/08/93
-
- DECLARE FUNCTION GetWindowsDirectory LIB "kernel" (lpSysPath AS STRING, nSize As WORD) As WORD
-
- CONST Section$ = "FileNames"
- CONST IniFile$ = "wsw.ini"
- CONST MaxEntries% = 64
-
- DIM entries$(MaxEntries%)
-
- REM Because we need to get all of the INI file entries in the [FileNames] section,
- REM we have to read the WSW.INI file directly, instead of using the GetPrivateProfileString
- REM statement. So we have to get the path to the ini file in order to read it.
- size% = w2i(GetWindowsDirectory(winPath$, i2w(150)))
- if (right$(winPath$, 1) <> "\") THEN winPath$ = winPath$ + "\"
-
- fileName$ = winpath$+IniFile$
- sectionName$ = "[" + Section$ + "]"
-
- REM Now read the file until we get to the right section.
- OPEN fileName$ FOR INPUT AS #1
- DO
- LINE INPUT #1, line$
- LOOP UNTIL EOF(#1) OR INSTR(line$, sectionName$) > 0
-
- IF NOT EOF(#1) THEN
- entry% = 1
- DO
- LINE INPUT #1, tempStr$
- tempStr$ = ltrim$(rtrim$(tempStr$))
- IF (tempStr$ <> "") AND (INSTR(tempStr$, "[") = 0) AND (left$(tempStr$,1) <> ";") AND (right$(tempStr$,1) <> "=") THEN
- entries$(entry%) = tempStr$
- entry% = entry% + 1
- ENDIF
- LOOP UNTIL (INSTR(tempStr$, "[") > 0) OR (EOF(#1)) OR (entry% = MaxEntries%)
- ENDIF
-
- REM We're done with the file, so we can close it.
- CLOSE #1
-
- index% = 1
-
- BEGIN DIALOG Dialog1 194, 126, "Manage List Files of Type Entries"
- TEXT 4, 4, 140, 16, "Choose an &Entry from the list and then choose an action:"
- LISTBOX 4, 22, 140, 100, entries$, index%
- PUSHBUTTON 150, 4, 40, 14, "&Close", 2
- PUSHBUTTON 150, 20, 40, 14, "&Add New", 3
- PUSHBUTTON 150, 36, 40, 14, "&Modify", 4
- PUSHBUTTON 150, 52, 40, 14, "&Delete", 5
- END DIALOG
-
- start:
-
- IF entry% > 1 THEN
- ret% = Dialog(Dialog1)
- IF ret% = 2 THEN STOP
- IF ret% = 1 THEN ret% = 4 'On double-click, choose Modify
- ELSE
- ' If there are no entries, then we have to add a new one.
- ret% = 3
- ENDIF
-
- ' Define the title for the second dialog
- title$ = "Add List Files of Type Entry"
- IF ret% = 4 THEN title$ = "Modify List Files of Type Entry"
-
- BEGIN DIALOG Dialog2 204, 108, title$
- TEXT 4, 4, 150, 8, "&Entry:"
- TEXTBOX 4, 14, 150, 12, entryText$
- TEXT 4, 28, 150, 8, "Example: Documents"
- TEXT 4, 42, 150, 8, "&File Specification:"
- TEXTBOX 4, 52, 150, 12, fileSpec$
- TEXT 4, 66, 150, 8, "Example: *.doc"
- TEXT 4, 80, 150, 24, "You can specify more than one file specification, separated by semicolons. Example: *.doc;*.txt"
- OKBUTTON 160, 4, 40, 14
- CANCELBUTTON 160, 20, 40, 14
- END DIALOG
-
- SELECT CASE ret%
-
- CASE 3
- REM Add new entry
- ret2% = Dialog(Dialog2)
- ' If user presses Cancel and no entries are in the ini file, then just stop.
- IF ret2% = 2 AND entry% = 1 THEN STOP
- IF ret2% = 1 AND entryText$ <> "" THEN
- REM Create the new entry in the ini file
- WritePrivateProfileString Section$, entryText$, fileSpec$, IniFile$
- REM And add it to the listbox
- entries$(entry%) = entryText$ + "=" + fileSpec$
- index% = entry%
- entry% = entry% + 1
- ENDIF
- entryText$ = ""
- fileSpec$ = ""
-
- CASE 4
- REM Modify selected entry
- tempStr$ = entries$(index%)
- equal% = INSTR(tempStr$, "=")
- entryText$ = left$(tempStr$, equal%-1)
- oldEntry$ = entryText$
- fileSpec$ = mid$(tempstr$, equal%+1, len(tempStr$))
- ret2% = Dialog(Dialog2)
- if ret2% = 1 AND entryText$ <> "" THEN
- REM Remove the old entry, in case the entry name was changed.
- WritePrivateProfileString Section$, oldEntry$, chr$(0), IniFile$
- WritePrivateProfileString Section$, entryText$, fileSpec$, IniFile$
- entries$(index%) = entryText$ + "=" + fileSpec$
- ENDIF
- entryText$ = ""
- fileSpec$ = ""
-
- CASE 5
- REM Delete selected entry
- title$ = "Delete Entry"
- tempStr$ = entries$(index%)
- equal% = INSTR(tempStr$, "=")
- entryText$ = left$(tempStr$, equal%-1)
- fileSpec$ = mid$(tempstr$, equal%+1, len(tempStr$))
- ret% = MessageBox(entryText$ + chr$(13) + chr$(13) + "Are you sure you want to delete this entry?", "Delete Entry?", 33)
- IF ret% = 1 THEN
- REM Remove the deleted entry
- IF entryText$ <> "" THEN
- WritePrivateProfileString Section$, entryText$, chr$(0), IniFile$
- ENDIF
-
- REM Remove the deleted entry from the listbox also, and shuffle the other entries up.
- FOR i% = index% to (MaxEntries% - 1)
- entries$(index%) = entries$(index%+1)
- NEXT i%
- entries$(MaxEntries%) = ""
- REM Decrease the number of entries
- entry% = entry% - 1
- ENDIF
-
- END SELECT
-
- GoTo start
- ***** WARNING *****
- This is a WSWin macro file.
- Subsequent data is binary information and should not be modified.