Author Topic: Problem With Wiki Example  (Read 6492 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Problem With Wiki Example
« on: August 22, 2019, 06:55:44 pm »
Has anyone used the File Open and Save Dialog from the Windows Libraries Wiki Page? I've been trying to use it with my Mini MP3 Player but it wouldn't work. So just now I tried it all by itself and it still wouldn't work, the C++ Compilation Failed it says. I looked at the log and it says this:
In file included from qbx.cpp:2171:
..\\temp\\main.txt: In function 'void QBMAIN(void*)':
..\\temp\\main.txt:7:125: error: cast from 'HWND' {aka 'HWND__*'} to 'int' loses precision [-fpermissive]
 *__LONG_HWND=(  int32  )FindWindow(NULL,(char*)(qbs_add(qbs_new_txt_len("Open and Save Dialog demo",25),func_chr( 0 )))->chr);
                                                                                                                             ^
compilation terminated due to -Wfatal-errors.

Here is the example from the Wiki Page if anyone wants to check it out. It's from here: http://www.qb64.org/wiki/Windows_Libraries
I have Windows 10 if that makes any difference.

Code: QB64: [Select]
  1. ' Dialog flag constants (use + or OR to use more than 1 flag value)
  2. CONST OFN_ALLOWMULTISELECT = &H200& '  Allows the user to select more than one file, not recommended!
  3. CONST OFN_CREATEPROMPT = &H2000& '     Prompts if a file not found should be created(GetOpenFileName only).
  4. CONST OFN_EXTENSIONDIFFERENT = &H400& 'Allows user to specify file extension other than default extension.
  5. CONST OFN_FILEMUSTEXIST = &H1000& '    Chechs File name exists(GetOpenFileName only).
  6. CONST OFN_HIDEREADONLY = &H4& '        Hides read-only checkbox(GetOpenFileName only)
  7. CONST OFN_NOCHANGEDIR = &H8& '         Restores the current directory to original value if user changed
  8. CONST OFN_NODEREFERENCELINKS = &H100000& 'Returns path and file name of selected shortcut(.LNK) file instead of file referenced.
  9. CONST OFN_NONETWORKBUTTON = &H20000& ' Hides and disables the Network button.
  10. CONST OFN_NOREADONLYRETURN = &H8000& ' Prevents selection of read-only files, or files in read-only subdirectory.
  11. CONST OFN_NOVALIDATE = &H100& '        Allows invalid file name characters.
  12. CONST OFN_OVERWRITEPROMPT = &H2& '     Prompts if file already exists(GetSaveFileName only)
  13. CONST OFN_PATHMUSTEXIST = &H800& '     Checks Path name exists (set with OFN_FILEMUSTEXIST).
  14. CONST OFN_READONLY = &H1& '            Checks read-only checkbox. Returns if checkbox is checked
  15. CONST OFN_SHAREAWARE = &H4000& '       Ignores sharing violations in networking
  16. CONST OFN_SHOWHELP = &H10& '           Shows the help button (useless!)
  17. '--------------------------------------------------------------------------------------------
  18.  
  19. DEFINT A-Z
  20. TYPE FILEDIALOGTYPE
  21.     lStructSize AS LONG '        For the DLL call
  22.     hwndOwner AS LONG '          Dialog will hide behind window when not set correctly
  23.     hInstance AS LONG '          Handle to a module that contains a dialog box template.
  24.     lpstrFilter AS _OFFSET '     Pointer of the string of file filters
  25.     lpstrCustFilter AS _OFFSET
  26.     nMaxCustFilter AS LONG
  27.     nFilterIndex AS LONG '       One based starting filter index to use when dialog is called
  28.     lpstrFile AS _OFFSET '       String full of 0's for the selected file name
  29.     nMaxFile AS LONG '           Maximum length of the string stuffed with 0's minus 1
  30.     lpstrFileTitle AS _OFFSET '  Same as lpstrFile
  31.     nMaxFileTitle AS LONG '      Same as nMaxFile
  32.     lpstrInitialDir AS _OFFSET ' Starting directory
  33.     lpstrTitle AS _OFFSET '      Dialog title
  34.     flags AS LONG '              Dialog flags
  35.     nFileOffset AS INTEGER '     Zero-based offset from path beginning to file name string pointed to by lpstrFile
  36.     nFileExtension AS INTEGER '  Zero-based offset from path beginning to file extension string pointed to by lpstrFile.
  37.     lpstrDefExt AS _OFFSET '     Default/selected file extension
  38.     lCustData AS LONG
  39.     lpfnHook AS LONG
  40.     lpTemplateName AS _OFFSET
  41.  
  42. DECLARE DYNAMIC LIBRARY "comdlg32" ' Library declarations using _OFFSET types
  43.     FUNCTION GetOpenFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Open file dialog
  44.     FUNCTION GetSaveFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Save file dialog
  45.  
  46.     FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
  47.  
  48. _TITLE "FileOpen Common Dialog demo" 'set Title of program
  49. hWnd& = FindWindow(0, "Open and Save Dialog demo" + CHR$(0)) 'get window handle using _TITLE string
  50.  
  51. ' Do the Open File dialog call!
  52. Filter$ = "Batch files (*.bat)|*.BAT|JPEG images (*.jpg)|*.JPG|All files (*.*)|*.*"
  53. Flags& = OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY '    add flag constants here
  54. OFile$ = GetOpenFileName$("YEAH! Common Dialogs in QB64!!!", ".\", Filter$, 1, Flags&, hWnd&)
  55.  
  56. IF OFile$ = "" THEN ' Display Open dialog results
  57.     PRINT "Shame on you! You didn't pick any file..."
  58.     PRINT "You picked this file: "
  59.     PRINT OFile$
  60.     IF (Flags& AND OFN_READONLY) THEN PRINT "Read-only checkbox checked." 'read-only value in return
  61.  
  62. _DELAY 5 ' Do the Save File dialog call!
  63. Filter$ = "Basic files (*.bas)|*.BAS|All files (*.*)|*.*"
  64. Flags& = OFN_OVERWRITEPROMPT + OFN_NOCHANGEDIR '   add flag constants here
  65. SFile$ = GetSaveFileName$("Save will not create a file!!!", ".\", Filter$, 1, Flags&, hWnd&)
  66.  
  67. IF SFile$ = "" THEN ' Display Save dialog results
  68.     PRINT "You didn't save the file..."
  69.     PRINT "You saved this file: "
  70.     PRINT SFile$
  71.  
  72. FUNCTION GetOpenFileName$ (Title$, InitialDir$, Filter$, FilterIndex, Flags&, hWnd&)
  73.     '  Title$      - The dialog title.
  74.     '  InitialDir$ - If this left blank, it will use the directory where the last opened file is
  75.     '  located. Specify ".\" if you want to always use the current directory.
  76.     '  Filter$     - File filters separated by pipes (|) in the same format as using VB6 common dialogs.
  77.     '  FilterIndex - The initial file filter to use. Will be altered by user during the call.
  78.     '  Flags&      - Dialog flags. Will be altered by the user during the call.
  79.     '  hWnd&       - Your program's window handle that should be aquired by the FindWindow function.
  80.     '
  81.     ' Returns: Blank when cancel is clicked otherwise, the file name selected by the user.
  82.     ' FilterIndex and Flags& will be changed depending on the user's selections.
  83.  
  84.     DIM OpenCall AS FILEDIALOGTYPE ' Needed for dialog call
  85.  
  86.     fFilter$ = Filter$
  87.     FOR R = 1 TO LEN(fFilter$) ' Replace the pipes with character zero
  88.         IF MID$(fFilter$, R, 1) = "|" THEN MID$(fFilter$, R, 1) = CHR$(0)
  89.     NEXT R
  90.     fFilter$ = fFilter$ + CHR$(0)
  91.  
  92.     lpstrFile$ = STRING$(2048, 0) ' For the returned file name
  93.     lpstrDefExt$ = STRING$(10, 0) ' Extension will not be added when this is not specified
  94.     OpenCall.lStructSize = LEN(OpenCall)
  95.     OpenCall.hwndOwner = hWnd&
  96.     OpenCall.lpstrFilter = _OFFSET(fFilter$)
  97.     OpenCall.nFilterIndex = FilterIndex
  98.     OpenCall.lpstrFile = _OFFSET(lpstrFile$)
  99.     OpenCall.nMaxFile = LEN(lpstrFile$) - 1
  100.     OpenCall.lpstrFileTitle = OpenCall.lpstrFile
  101.     OpenCall.nMaxFileTitle = OpenCall.nMaxFile
  102.     OpenCall.lpstrInitialDir = _OFFSET(InitialDir$)
  103.     OpenCall.lpstrTitle = _OFFSET(Title$)
  104.     OpenCall.lpstrDefExt = _OFFSET(lpstrDefExt$)
  105.     OpenCall.flags = Flags&
  106.  
  107.     Result = GetOpenFileNameA&(OpenCall) '            Do Open File dialog call!
  108.  
  109.     IF Result THEN ' Trim the remaining zeros
  110.         GetOpenFileName$ = LEFT$(lpstrFile$, INSTR(lpstrFile$, CHR$(0)) - 1)
  111.         Flags& = OpenCall.flags
  112.         FilterIndex = OpenCall.nFilterIndex
  113.     END IF
  114.  
  115.  
  116. FUNCTION GetSaveFileName$ (Title$, InitialDir$, Filter$, FilterIndex, Flags&, hWnd&)
  117.     '  Title$      - The dialog title.
  118.     '  InitialDir$ - If this left blank, it will use the directory where the last opened file is
  119.     '     located. Specify ".\" if you want to always use the current directory.
  120.     '  Filter$     - File filters separated by pipes (|) in the same format as VB6 common dialogs.
  121.     '  FilterIndex - The initial file filter to use. Will be altered by user during the call.
  122.     '  Flags&      - Dialog flags. Will be altered by the user during the call.
  123.     '  hWnd&       - Your program's window handle that should be aquired by the FindWindow function.
  124.  
  125.     ' Returns: Blank when cancel is clicked otherwise, the file name entered by the user.
  126.     ' FilterIndex and Flags& will be changed depending on the user's selections.
  127.  
  128.     DIM SaveCall AS FILEDIALOGTYPE ' Needed for dialog call
  129.  
  130.     fFilter$ = Filter$
  131.     FOR R = 1 TO LEN(fFilter$) ' Replace the pipes with zeros
  132.         IF MID$(fFilter$, R, 1) = "|" THEN MID$(fFilter$, R, 1) = CHR$(0)
  133.     NEXT R
  134.     fFilter$ = fFilter$ + CHR$(0)
  135.  
  136.     lpstrFile$ = STRING$(2048, 0) ' For the returned file name
  137.     lpstrDefExt$ = STRING$(10, 0) ' Extension will not be added when this is not specified
  138.     SaveCall.lStructSize = LEN(SaveCall)
  139.     SaveCall.hwndOwner = hWnd&
  140.     SaveCall.lpstrFilter = _OFFSET(fFilter$)
  141.     SaveCall.nFilterIndex = FilterIndex
  142.     SaveCall.lpstrFile = _OFFSET(lpstrFile$)
  143.     SaveCall.nMaxFile = LEN(lpstrFile$) - 1
  144.     SaveCall.lpstrFileTitle = SaveCall.lpstrFile
  145.     SaveCall.nMaxFileTitle = SaveCall.nMaxFile
  146.     SaveCall.lpstrInitialDir = _OFFSET(InitialDir$)
  147.     SaveCall.lpstrTitle = _OFFSET(Title$)
  148.     SaveCall.lpstrDefExt = _OFFSET(lpstrDefExt$)
  149.     SaveCall.flags = Flags&
  150.  
  151.     Result& = GetSaveFileNameA&(SaveCall) ' Do dialog call!
  152.  
  153.     IF Result& THEN ' Trim the remaining zeros
  154.         GetSaveFileName$ = LEFT$(lpstrFile$, INSTR(lpstrFile$, CHR$(0)) - 1)
  155.         Flags& = SaveCall.flags
  156.         FilterIndex = SaveCall.nFilterIndex
  157.     END IF
  158.  
  159.  





Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #1 on: August 22, 2019, 07:34:36 pm »
Hi Ken,

Never used it, too complicated. Are you trying to get a list of files in a directory to select from?

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Problem With Wiki Example
« Reply #2 on: August 22, 2019, 07:46:59 pm »
Yes, I found the string to use to get it from. Half of that code I don't need since it's for Saving. It just uses the TITLE command to find both windows (program and FILE window). I don't know probably 98% of all what is there, but I thought maybe someone has used it before. Would also be nice to know if I can use this, or another known code, to select a Windows Folder (just the folder) and not a file, to change folders.
« Last Edit: August 22, 2019, 07:48:03 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #3 on: August 22, 2019, 08:08:32 pm »
Anyone remember the DIR command line for just Folders / Directories?

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem With Wiki Example
« Reply #4 on: August 22, 2019, 08:40:25 pm »
I dunno what the heck is going on with the wiki example, but it's somehow gotten all goofy. It *used* to work, but I see several very obvious issues as to why it currently isn't:

_TITLE "FileOpen Common Dialog demo"                           'set Title of program
hWnd& = FindWindow(0, "Open and Save Dialog demo" + CHR$(0)) 'get window handle using _TITLE string

Get the window handle, using the _TITLE string...  Sounds lovely!

But WTH doesn't the string and the _TITLE text match???

To correct this issue, you need to make the two strings match:

_TITLE "FileOpen Common Dialog demo"                           'set Title of program
hWnd& = FindWindow(0, "FileOpen Common Dialog demo" + CHR$(0)) 'get window handle using _TITLE string



At this point, I believe, the example should compile and run for you -- as long as you're running it with the 32-bit version of QB64.

When the sample was added, all QB64 offered was a 32-bit version, so the code is only tailored for 32-bit versions of QB64. 

64-bit versions of QB64 aren't going to compile, at all, for this one line in particular:

DECLARE LIBRARY
    FUNCTION FindWindow& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
END DECLARE

You can't take a 64-bit OFFSET and store it in a 32-bit value!  The compiler simply *won't* allow it.  This is a 100% crash, even before compilation.  You can change it to the following, and get it to compile for you, at least:

DECLARE LIBRARY
    FUNCTION FindWindow&& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
END DECLARE



BUT, it still won't work as intended...  The next issue is probably:

DECLARE DYNAMIC LIBRARY "comdlg32" ' Library declarations using _OFFSET types
    FUNCTION GetOpenFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Open file dialog
    FUNCTION GetSaveFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Save file dialog
END DECLARE

It looks like we're trying to call a 32-bit windows library, when we probably need to actually call a 64-bit version.  I'd imagine the offsets are off, and the program simply is returning a fail code to us when we attempt to call those functions.  I'm not 100% certain this is the issue, as I quit digging at this point, but I've seen enough to make me say, "As the example currently exists, it's:  1) glitched with the _TITLE text and 2) only going to work for 32-bit QB64, without some serious tweaking/overhauling. 

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #5 on: August 22, 2019, 08:50:35 pm »
Tiny Navigator almost ready! :)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem With Wiki Example
« Reply #6 on: August 22, 2019, 09:03:02 pm »
Doing a little quick research on the issue, it seems the problem isn't with "comdlg32"; it's with how the file structure is packed between 32-bit and 64-bit versions.  The recommended solution is to compile with the -Zp switch with Visual Studio -- https://docs.microsoft.com/en-us/cpp/build/reference/zp-struct-member-alignment?view=vs-2019 -- but it does us absolutely zero good, as we compile with mingw...  There's probably a suitable switch which we can pop into the compile makeline, but I have no idea what it might be; now what else it might break if we tried to enable it by default...

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Problem With Wiki Example
« Reply #7 on: August 22, 2019, 09:03:17 pm »
Wow lots of problems, thank you SMcNeill, that's more than I needed. I run 64 bit and I did try your #1, keeping the TITLE and string the same earlier, but it still wouldn't work. Probably from being 64 bit. I'll just give up on this one.

B+, in my Mini MP3 Player you can change the directories by typing in any one you want, the DOS way using CHDIR, but I was just wondering if there was an easier Windows way using the Mouse. Oh well, thanks for your time guys.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #8 on: August 22, 2019, 09:12:51 pm »
Wow lots of problems, thank you SMcNeill, that's more than I needed. I run 64 bit and I did try your #1, keeping the TITLE and string the same earlier, but it still wouldn't work. Probably from being 64 bit. I'll just give up on this one.

B+, in my Mini MP3 Player you can change the directories by typing in any one you want, the DOS way using CHDIR, but I was just wondering if there was an easier Windows way using the Mouse. Oh well, thanks for your time guys.

Yes, for Windows you can, I am putting it together now, something I have been meaning to do for long time, thanks for reminder and sharing common need. I found the command line switch for directories only and the file output from pipe needed a little pruning, do you remember that ".." means go up in directories? ie CD ..
« Last Edit: August 22, 2019, 09:15:49 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Problem With Wiki Example
« Reply #9 on: August 22, 2019, 09:28:16 pm »
Give this little program a quick try:

Code: QB64: [Select]
  1.     FUNCTION FILE_load_dir& ALIAS load_dir (s AS STRING)
  2.     FUNCTION FILE_has_next_entry& ALIAS has_next_entry ()
  3.     SUB FILE_close_dir ALIAS close_dir ()
  4.     SUB FILE_get_next_entry ALIAS get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  5.     SUB FILE_get_current_dir ALIAS get_current_dir (s AS STRING)
  6.     FUNCTION FILE_current_dir_length& ALIAS current_dir_length ()
  7.  
  8. SCREEN _NEWIMAGE(1024, 720, 32)
  9.  
  10. a$ = SelectFile$("*.*", 100, 100)
  11. PRINT "You selected:"; a$
  12.  
  13.  
  14. FUNCTION SelectFile$ (search$, x AS INTEGER, y AS INTEGER)
  15.     'save some old values
  16.     LoadFile_DC = _DEFAULTCOLOR: LoadFile_BG = _BACKGROUNDCOLOR
  17.     LoadFile_s = _SOURCE: LoadFile_d = _DEST
  18.     f = _FONT: _FONT 16
  19.     'some variables
  20.  
  21.     LoadFile_BoxColor = &HFFAAAAFF
  22.     LoadFile_FolderColor = &HFFFFFF00
  23.     LoadFile_FileColor = &HFFFFFFFF
  24.     IF INSTR(_OS$, "[WINDOWS]") THEN LoadFile_Slash$ = "\" ELSE LoadFile_Slash$ = "/"
  25.     LoadFile_Dir$ = SPACE$(FILE_current_dir_length)
  26.     FILE_get_current_dir LoadFile_Dir$
  27.     LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_Slash$
  28.     'LoadFile_Dir$ = "." + LoadFile_Slash$
  29.     LoadFile_w = 639: LoadFile_h = 479
  30.     REDIM LoadFile_Label(0) AS STRING: LoadFile_Label(0) = "DIR"
  31.     REDIM LoadFile_DirList(-1 TO 9, -1 TO 9999) AS STRING
  32.     LoadFile_last = 1
  33.     FolderDeep = 1
  34.  
  35.     'some error checking
  36.     IF search$ = "" THEN EXIT SUB 'We can't search for nothing!
  37.  
  38.     'Copy background
  39.     PCOPY 0, 1
  40.     'set workscreen
  41.     LoadFile_ws = _NEWIMAGE(640, 480, 32)
  42.  
  43.     'Count our filetypes to display
  44.     LoadFile_TypeCount = 0
  45.     DO
  46.         LoadFile_TypeCount = LoadFile_TypeCount + 1
  47.         LoadFile_l = INSTR(LoadFile_l + 1, search$, ";") ' look for ; to denote more files
  48.         REDIM _PRESERVE LoadFile_Label(LoadFile_TypeCount) AS STRING
  49.         IF LoadFile_l > 0 THEN LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LoadFile_l - LoadFile_last - 1) ELSE LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LEN(search$) - LoadFile_last)
  50.         LoadFile_last = LoadFile_l + 1
  51.     LOOP UNTIL LoadFile_l = 0
  52.     LoadFile_l = 640 / (LoadFile_TypeCount + 1)
  53.     REDIM LoadFile_start(LoadFile_TypeCount), LoadFile_previous(LoadFile_TypeCount), LoadFile_more(LoadFile_TypeCount), LoadFile_Count(LoadFile_TypeCount)
  54.     FOR i = 0 TO LoadFile_TypeCount: LoadFile_start(i) = 1: NEXT
  55.  
  56.     _SOURCE LoadFile_ws: _DEST LoadFile_ws
  57.     DO
  58.         _LIMIT 30
  59.         FOR i = 0 TO LoadFile_TypeCount
  60.             LoadFile_Count(i) = 0
  61.             FOR j = 0 TO 9999
  62.                 LoadFile_DirList(i, j) = ""
  63.             NEXT
  64.         NEXT
  65.         'Generate our updated directory listings.
  66.  
  67.         IF FILE_load_dir&(LoadFile_Dir$ + CHR$(0)) THEN
  68.             DO
  69.                 LoadFile_length = FILE_has_next_entry 'Get length of next entry
  70.                 IF LoadFile_length > -1 THEN 'If we have a next entry
  71.                     LoadFile_nam$ = SPACE$(LoadFile_length) 'Set the size of our string
  72.                     FILE_get_next_entry LoadFile_nam$, LoadFile_flags, LoadFile_file_size 'Get the file's name, size, and 'flags'
  73.                     'Check if it's a file or a directory
  74.  
  75.                     IF _DIREXISTS(LoadFile_Dir$ + LoadFile_nam$) THEN
  76.                         IF LoadFile_nam$ <> "." THEN
  77.                             LoadFile_Count(0) = LoadFile_Count(0) + 1
  78.                             LoadFile_DirList(0, LoadFile_Count(0)) = LoadFile_nam$
  79.                         END IF
  80.                     ELSE 'We have a file
  81.                         FOR i = 1 TO LoadFile_TypeCount
  82.                             LoadFile_ext$ = RIGHT$(LoadFile_nam$, LEN(LoadFile_Label(i)))
  83.                             IF UCASE$(LoadFile_ext$) = UCASE$(LoadFile_Label(i)) THEN
  84.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  85.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LEFT$(LoadFile_nam$, LEN(LoadFile_nam$) - LEN(LoadFile_Label(i)))
  86.                                 EXIT FOR
  87.                             ELSEIF LoadFile_Label(i) = ".*" THEN
  88.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  89.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LoadFile_nam$
  90.                             END IF
  91.                         NEXT
  92.                     END IF
  93.                 END IF
  94.             LOOP UNTIL LoadFile_length = -1
  95.             FILE_close_dir
  96.         END IF
  97.  
  98.         updatelist:
  99.  
  100.  
  101.         CLS , &HFF005050 'Draw a nice display box
  102.         COLOR , 0
  103.         LINE (0, 0)-(LoadFile_w, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor, B
  104.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h + 6 - 2 * 16), LoadFile_BoxColor, B
  105.         LINE (0, 0)-(LoadFile_w, LoadFile_h), LoadFile_BoxColor, B
  106.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h - 1), LoadFile_BoxColor, B
  107.  
  108.         LINE (0, 16 + 3)-(LoadFile_w, 16 + 3), LoadFile_BoxColor
  109.         LINE (0, 16 + 4)-(LoadFile_w, 16 + 4), LoadFile_BoxColor
  110.         FOR i = 0 TO LoadFile_TypeCount
  111.             _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * LEN(LoadFile_Label(i))) / 2, 2), LoadFile_Label(i)
  112.             LINE (i * LoadFile_l, 0)-(i * LoadFile_l, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor
  113.         NEXT
  114.  
  115.         LINE (627, 2)-(637, 18), &HFFFF0000, BF
  116.         LINE (626, 2)-(637, 18), &HFF000000, B
  117.  
  118.         _PRINTSTRING (628, 2), "X"
  119.         IF selection > 0 THEN
  120.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp$ = LoadFile_DirList(row, selection)
  121.             IF LoadFile_DirList(row, selection) = "" THEN temp$ = ""
  122.             selection = 0
  123.         END IF
  124.         _PRINTSTRING (10, 28 * 16 + 7), LoadFile_Dir$
  125.         _PRINTSTRING (630 - LEN(temp$) * 8, 28 * 16 + 7), temp$
  126.         IF temp$ = "" THEN oldselection = 0
  127.         IF oldselection > 0 THEN LINE (row * LoadFile_l, (oldselection + 1) * 16 + 5)-((row + 1) * LoadFile_l, (oldselection + 2) * 16 + 5), &HAAAAA000, BF
  128.  
  129.         FOR i = 0 TO UBOUND(LoadFile_label)
  130.             IF i = 0 THEN COLOR LoadFile_FolderColor ELSE COLOR LoadFile_FileColor
  131.             counter = 0
  132.             FOR j = LoadFile_start(i) TO LoadFile_start(i) + 24
  133.                 counter = counter + 1
  134.                 IF LoadFile_DirList(i, j) = "" THEN EXIT FOR
  135.                 _PRINTSTRING (i * LoadFile_l + 5, (counter + 1) * 16 + 7), LEFT$(LoadFile_DirList(i, j), LoadFile_l / 8 - 2)
  136.             NEXT
  137.             IF j = LoadFile_start(i) + 25 THEN LoadFile_more(i) = -1 ELSE LoadFile_more(i) = 0
  138.             IF LoadFile_start(i) > 1 THEN LoadFile_previous(i) = -1 ELSE LoadFile_previous(i) = 0
  139.             IF LoadFile_more(i) THEN
  140.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), &HFFFF0000, BF
  141.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), BoxColor, B
  142.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 11) / 2, 27 * 16 + 5), "SCROLL DOWN"
  143.                 COLOR LoadFile_FileColor
  144.             END IF
  145.             IF LoadFile_previous(i) THEN
  146.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), &HFFFF0000, BF
  147.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), BoxColor, B
  148.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 9) / 2, 16 + 5), "SCROLL UP"
  149.                 COLOR LoadFile_FileColor
  150.             END IF
  151.         NEXT
  152.  
  153.         _PUTIMAGE (0 + x, 0 + y)-(640 + x, 480 + y), LoadFile_ws, 0
  154.         _DISPLAY
  155.  
  156.         change = 0
  157.         DO
  158.             _LIMIT 30
  159.             LoadFile_LMB = 0 'This sets the left mouse button as unacceptable.
  160.             a = _KEYHIT
  161.             SELECT CASE a
  162.                 CASE 8 'backspace
  163.                     temp$ = LEFT$(temp$, LEN(temp$) - 1)
  164.                     change = -1
  165.                 CASE 13 'enter
  166.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  167.                     temp$ = LoadFile_Dir$ + temp$
  168.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = temp$ 'Restore our old settings
  169.                     _FONT f
  170.                     EXIT SUB 'And leave
  171.                 CASE 27 'If ESC is pressed then...
  172.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  173.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = "" 'Restore our old settings
  174.                     _FONT f
  175.                     EXIT SUB 'And leave
  176.                 CASE 32 TO 126
  177.                     temp$ = temp$ + CHR$(a)
  178.                     change = -1
  179.             END SELECT
  180.             DO
  181.                 IF _MOUSEBUTTON(1) = 0 THEN LoadFile_LMB = -1 'Only by lifting the mouse, will we count it as down
  182.                 'Note: we ignore LoadFile_LMB for the scroll bars, so we can just hold it down and scroll happily forever and ever...
  183.                 'or until we get to the limit of our file list.
  184.                 'We only check LoadFile_LMB when actually trying to select an item from our list.   No more "OOP!  I held it too long and did something I didn't want to do!"
  185.                 'Now we click once to select, click again to accept that selection.
  186.             LOOP WHILE _MOUSEINPUT
  187.             MX = _MOUSEX: MY = _MOUSEY
  188.             IF _MOUSEBUTTON(2) OR (LoadFile_LMB AND MX > 626 + x AND MX < 638 + x AND MY > 1 + y AND MY < 19 + y AND _MOUSEBUTTON(1)) THEN
  189.                 'restore those old values, and just exit.  Right mouse is an escape
  190.                 COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = ""
  191.                 _FONT f
  192.                 EXIT SUB
  193.             END IF
  194.             IF _MOUSEBUTTON(1) THEN 'Without the mouse being down, we don't need to check squat!
  195.                 'Check the 2 roLoadFile_ws for a click in the proper Y position
  196.                 IF MY >= 16 + 5 + y AND MY <= 2 * 16 + 3 + y THEN 'We're on the top row
  197.                     FOR j = 0 TO UBOUND(LoadFile_label)
  198.                         IF LoadFile_previous(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  199.                             LoadFile_start(j) = LoadFile_start(j) - 1
  200.                             change = -1: selection = 0: click = 0: temp$ = ""
  201.                             EXIT FOR
  202.                         END IF
  203.                     NEXT
  204.                 ELSEIF MY >= 27 * 16 + 5 + y AND MY <= 28 * 16 + 3 + y THEN 'We're on the bottom row
  205.                     FOR j = 0 TO UBOUND(LoadFile_label)
  206.                         IF LoadFile_more(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  207.                             LoadFile_start(j) = LoadFile_start(j) + 1
  208.                             change = -1: selection = 0: click = 0: temp$ = ""
  209.                             EXIT FOR
  210.                         END IF
  211.                     NEXT
  212.                 ELSEIF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
  213.                     FOR j = 0 TO UBOUND(LoadFile_label)
  214.                         IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  215.                             row = j
  216.                             oldselection = INT((MY - y - 37) / 16) + 1
  217.                             selection = LoadFile_start(j) + oldselection - 1
  218.                             change = -1
  219.                             click = -1
  220.                             EXIT FOR
  221.                         END IF
  222.                     NEXT
  223.                 END IF
  224.             END IF
  225.  
  226.             _DISPLAY
  227.         LOOP UNTIL change
  228.         IF click THEN 'we clicked something besides a scroll bar
  229.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp1$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp1$ = LoadFile_DirList(row, selection)
  230.             IF temp$ = temp1$ THEN
  231.                 'We picked one!
  232.                 SELECT CASE LoadFile_Label(row)
  233.                     CASE "DIR"
  234.                         IF LoadFile_DirList(row, selection) <> ".." THEN
  235.                             LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_DirList(row, selection) + LoadFile_Slash$
  236.                         ELSE
  237.                             DO
  238.                                 LoadFile_Dir$ = LEFT$(LoadFile_Dir$, LEN(LoadFile_Dir$) - 1)
  239.                             LOOP UNTIL RIGHT$(LoadFile_Dir$, 1) = LoadFile_Slash$ OR LEN(LoadFile_Dir$) = 0
  240.                         END IF
  241.                         FOR i = 1 TO UBOUND(Loadfile_start)
  242.                             LoadFile_start(i) = 1
  243.                         NEXT
  244.                         selection = 0: temp$ = "": oldselection = 0
  245.                     CASE ".*": SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  246.                     CASE ELSE: SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  247.                 END SELECT
  248.             END IF
  249.             IF row > 0 THEN _DELAY .2: GOTO updatelist
  250.         ELSE
  251.             _DELAY .05
  252.             GOTO updatelist
  253.         END IF
  254.     LOOP
  255.     'restore those old values
  256.     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY
  257.     _FONT f
  258.  
  259. 'If you don't have a copy of direntry.h in your QB64 folder, then copy the following code into a new IDE window.
  260. 'Then remove the remarks.
  261. 'And save it as direntry.h
  262. 'direntry.h is required for this to work properly with the library files.
  263. 'I thought adding the code here would be a way to make certain that it'd be easy to recover the file
  264. 'in case something ever happened and it was accidently deleted off the drive for some reason.
  265.  
  266. '#include <dirent.h>
  267. '#include <sys/stat.h>
  268. '#include <unistd.h>
  269.  
  270. 'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;
  271.  
  272. 'DIR *pdir;
  273. 'struct dirent *next_entry;
  274. 'struct stat statbuf1;
  275.  
  276. 'char current_dir[FILENAME_MAX];
  277. '#ifdef QB64_WINDOWS
  278. '  #define GetCurrentDir _getcwd
  279. '#else
  280. '  #define GetCurrentDir getcwd
  281. '#endif
  282.  
  283. 'int load_dir (char * path) {
  284. '  struct dirent *pent;
  285. '  struct stat statbuf1;
  286. '//Open current directory
  287. 'pdir = opendir(path);
  288. 'if (!pdir) {
  289. 'return 0; //Didn't open
  290. '}
  291. 'return -1;
  292. '}
  293.  
  294. 'int has_next_entry () {
  295. '  next_entry = readdir(pdir);
  296. '  if (next_entry == NULL) return -1;
  297.  
  298. '  stat(next_entry->d_name, &statbuf1);
  299. '  return strlen(next_entry->d_name);
  300. '}
  301.  
  302. 'void get_next_entry (char * nam, int * flags, int * file_size) {
  303. '  strcpy(nam, next_entry->d_name);
  304. '  if (S_ISDIR(statbuf1.st_mode)) {
  305. '    *flags = IS_DIR_FLAG;
  306. '  } else {
  307. '    *flags = IS_FILE_FLAG;
  308. '  }
  309. '  *file_size = statbuf1.st_size;
  310. '  return ;
  311. '}
  312.  
  313. 'void close_dir () {
  314. '  closedir(pdir);
  315. '  pdir = NULL;
  316. '  return ;
  317. '}
  318.  
  319. 'int current_dir_length () {
  320. '  GetCurrentDir(current_dir, sizeof(current_dir));
  321. '  return strlen(current_dir);
  322. '}
  323.  
  324. 'void get_current_dir(char *dir) {
  325. '  memcpy(dir, current_dir, strlen(current_dir));
  326. '  return ;
  327. '}
  328.  

You'll need the direntry.h file in your QB64 folder when running it, so grab it from below, and see how it performs for you.  This little routine should work with all our operating systems -- Windows, Linux, and Mac -- and is something I tossed together ages ago and have shared countless times with folks.  You really won't find a much simpler file selection utility than one which tends to be:

a$ = SelectFile$("*.*", 100, 100)
PRINT "You selected:"; a$
* direntry.h (Filesize: 1.22 KB, Downloads: 169)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #10 on: August 22, 2019, 10:10:35 pm »
Kinda hastily put together but you can get around pretty nicely, do not try to go up into \users, Windows shuts down access.

Code: QB64: [Select]
  1. _TITLE "Tiny Navigator" 'B+ 2019-08-22
  2. SCREEN _NEWIMAGE(1200, 600, 32)
  3. _SCREENMOVE 100, 50
  4.  
  5. DIM nav$, mySelection&, done$
  6.     PRINT "Current Directory: " + _CWD$
  7.     REDIM myFiles(0) AS STRING
  8.     loadFA "*.*", myFiles()
  9.     mySelection& = getArrayItemNumber&(5, 5, 90, 30, myFiles())
  10.     CLS
  11.     IF mySelection& <> -1719 THEN
  12.         CHDIR myFiles(mySelection&)
  13.     ELSE
  14.         PRINT "No Directory selected."
  15.         INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  16.     END IF
  17.     _LIMIT 60
  18. LOOP UNTIL done$ <> ""
  19.  
  20. SUB loadFA (spec$, fa() AS STRING)
  21.     DIM Index%, fline$, d$
  22.     CONST TmpFile$ = "DIR$INF0.INF"
  23.     SHELL _HIDE "DIR /a:d >" + TmpFile$ 'get directories  but have to do a little pruning
  24.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  25.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  26.     OPEN TmpFile$ FOR INPUT AS #1
  27.     Index% = -1
  28.     DO WHILE NOT EOF(1)
  29.         LINE INPUT #1, fline$
  30.         IF INSTR(fline$, "<DIR>") THEN
  31.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  32.             Index% = Index% + 1
  33.             REDIM _PRESERVE fa(Index%)
  34.             fa(Index%) = d$
  35.         END IF
  36.     LOOP
  37.     CLOSE #1
  38.     KILL TmpFile$
  39.  
  40. FUNCTION rightOf$ (source$, of$)
  41.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  42.  
  43. 'attempting use this 4 things (2018-12-30)
  44. ' 1. expects HELP sub that uses message and message box but easy to comment out
  45. ' 2. expects to be in graphics mode
  46. ' 3. chages color of screen
  47. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  48. '
  49. ' Future Help Message Box for the function.
  50. ' "*** Mouse and Key Instructions ***"
  51. '
  52. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  53. ' "Press spacebar to select a highlighted item or just click it."
  54. ' "Use number(s) + enter to select an array item by it's index number,"
  55. ' "backspace will remove last number pressed, c will clear a number started."
  56. ' "Numbers started are shown in bottom right PgDn bar."
  57. ' "Enter will also select the highlighted item, if no number has been started."
  58. ' "Home starts you at lowest array index, End highlights then highest index."
  59. ' "Use PgUp and PgDn keys to flip through pages of array items."
  60. '
  61. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  62. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  63.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  64.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  65.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  66.  
  67.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  68.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  69.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  70.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  71.     DIM clrStr AS STRING, b AS STRING
  72.  
  73.     'save old settings to restore at end ofsub
  74.     curRow = CSRLIN
  75.     curCol = POS(0)
  76.     fg = _DEFAULTCOLOR
  77.     bg = _BACKGROUNDCOLOR
  78.     _KEYCLEAR
  79.  
  80.     maxWidth = boxWidth '       number of characters in box
  81.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  82.     lba = LBOUND(arr)
  83.     uba = UBOUND(arr)
  84.     page = 0
  85.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  86.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  87.  
  88.     GOSUB update '              show the beginning of the array items for selection
  89.  
  90.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  91.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  92.  
  93.     DO 'until get a selection or demand exit
  94.  
  95.         'handle the key stuff
  96.         kh& = _KEYHIT
  97.         IF kh& THEN
  98.             IF kh& > 0 AND kh& < 255 THEN
  99.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  100.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  101.  
  102.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  103.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  104.                     IF LEN(b$) THEN
  105.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  106.                             choice = VAL(b$): EXIT DO
  107.                         ELSE 'clear b$ to show some response to enter
  108.                             b$ = "": GOSUB update 'clear the value that doesn't work
  109.                         END IF
  110.                     ELSE
  111.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  112.                     END IF
  113.                 END IF
  114.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  115.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  116.                 IF kh& = 8 THEN 'backspace to edit number
  117.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  118.                 END IF
  119.             ELSE
  120.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  121.                     CASE 20736 'pg dn
  122.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  123.                     CASE 18688 'pg up
  124.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  125.                     CASE 18432 'up
  126.                         IF hlite - 1 < 0 THEN
  127.                             IF page > 0 THEN
  128.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  129.                             END IF
  130.                         ELSE
  131.                             hlite = hlite - 1: GOSUB update
  132.                         END IF
  133.                     CASE 20480 'down
  134.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  135.                             IF hlite + 1 > maxHeight - 1 THEN
  136.                                 page = page + 1: hlite = 0: GOSUB update
  137.                             ELSE
  138.                                 hlite = hlite + 1: GOSUB update
  139.                             END IF
  140.                         END IF
  141.                     CASE 18176 'home
  142.                         page = 0: hlite = 0: GOSUB update
  143.                     CASE 20224 ' end
  144.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  145.                 END SELECT
  146.             END IF
  147.         END IF
  148.  
  149.         'handle the mouse stuff
  150.         WHILE _MOUSEINPUT
  151.             IF _MOUSEWHEEL = -1 THEN 'up?
  152.                 IF hlite - 1 < 0 THEN
  153.                     IF page > 0 THEN
  154.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  155.                     END IF
  156.                 ELSE
  157.                     hlite = hlite - 1: GOSUB update
  158.                 END IF
  159.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  160.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  161.                     IF hlite + 1 > maxHeight - 1 THEN
  162.                         page = page + 1: hlite = 0: GOSUB update
  163.                     ELSE
  164.                         hlite = hlite + 1: GOSUB update
  165.                     END IF
  166.                 END IF
  167.             END IF
  168.         WEND
  169.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  170.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  171.             'clear mouse clicks
  172.             mb = _MOUSEBUTTON(1)
  173.             IF mb THEN 'clear it
  174.                 WHILE mb 'OK!
  175.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  176.                     _LIMIT 100
  177.                 WEND
  178.             END IF
  179.  
  180.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  181.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  182.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  183.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  184.                     EXIT DO 'escape plan for mouse click top right corner of display box
  185.                 ELSE 'PgUp bar clicked
  186.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  187.                 END IF
  188.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  189.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  190.             END IF
  191.         ELSE '   mouse over highlighting, only if mouse has moved!
  192.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  193.                 IF mx <> lastMX OR my <> lastMY THEN
  194.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  195.                         hlite = my - 1
  196.                         lastMX = mx: lastMY = my
  197.                         GOSUB update
  198.                     END IF
  199.                 END IF
  200.             END IF
  201.         END IF
  202.         _LIMIT 200
  203.     LOOP UNTIL choice >= lba AND choice <= uba
  204.     getArrayItemNumber& = choice
  205.     COLOR fg, bg
  206.     'clear key presses
  207.     _KEYCLEAR
  208.     LOCATE curRow, curCol
  209.     'clear mouse clicks
  210.     mb = _MOUSEBUTTON(1)
  211.     IF mb THEN 'clear it
  212.         WHILE mb 'OK!
  213.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  214.             _LIMIT 100
  215.         WEND
  216.     END IF
  217.     EXIT SUB
  218.  
  219.     'display of array sections and controls on screen
  220.     update:
  221.  
  222.     'fix hlite if it has dropped below last array item
  223.     WHILE hlite + page * maxHeight + lba > uba
  224.         hlite = hlite - 1
  225.     WEND
  226.  
  227.     'main display of array items at page * maxHeight (lines high)
  228.     FOR row = 0 TO maxHeight - 1
  229.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  230.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  231.         index = row + page * maxHeight + lba
  232.         IF index >= lba AND index <= uba THEN
  233.             LOCATE locateRow + row, locateColumn
  234.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  235.         END IF
  236.     NEXT
  237.  
  238.     'make page up and down bars to click, print PgUp / PgDn if available
  239.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  240.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  241.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  242.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  243.     IF page <> INT(uba / maxHeight) THEN
  244.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  245.     END IF
  246.     'make exit sign for mouse click
  247.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  248.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  249.     PRINT " X "
  250.  
  251.     'if a number selection has been started show it's build = b$
  252.     IF LEN(b$) THEN
  253.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  254.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  255.         PRINT b$;
  256.     END IF
  257.     _DISPLAY
  258.     _LIMIT 100
  259.     RETURN
  260.  
  261.  

EDIT: remove unused sub
EDIT2; add title
« Last Edit: August 22, 2019, 10:21:34 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Problem With Wiki Example
« Reply #11 on: August 22, 2019, 10:11:34 pm »
Thanks SMcNeill! It works mostly now... but there is there a limit of how many folders within folders it can go to? Because it won't pick up a folder within a folder within a folder, and that's where most of my songs are. lol Also, when it plays a song, the screen is black and doesn't go to the rest of my code like it's supposed to. Here is my entire program so far. I also put that file in my QB64 folder, thanks!

Code: QB64: [Select]
  1. 'This program was made on August 21, 2019 by Ken G. with some help by Petr from the QB64.org forum.
  2. 'This program will make a temporary file called MyMusicFiles-Temp000.temp
  3. 'which is just a text file and can be opened by Notepad. It shows a list of
  4. 'the mp3 songs in that directory. The file is deleted once the music starts.
  5.  
  6. DECLARE LIBRARY 'Directory Information using KERNEL32 provided by Dav
  7.     FUNCTION CURDirectory ALIAS GetCurrentDirectoryA (BYVAL nBufferLen AS LONG, lpBuffer AS STRING)
  8.  
  9.     FUNCTION FILE_load_dir& ALIAS load_dir (s AS STRING)
  10.     FUNCTION FILE_has_next_entry& ALIAS has_next_entry ()
  11.     SUB FILE_close_dir ALIAS close_dir ()
  12.     SUB FILE_get_next_entry ALIAS get_next_entry (s AS STRING, flags AS LONG, file_size AS LONG)
  13.     SUB FILE_get_current_dir ALIAS get_current_dir (s AS STRING)
  14.     FUNCTION FILE_current_dir_length& ALIAS current_dir_length ()
  15.  
  16.  
  17. _TITLE "Mini MP3 Player"
  18. SCREEN _NEWIMAGE(1024, 720, 32)
  19. begin:
  20. DIM f$(100000)
  21. record = 0
  22. rec = 0
  23. oldp = 0
  24. p = 0
  25. PRINT "                Mini MP3 Player"
  26. PRINT "                  By Ken G."
  27. '=== SHOW CURRENT DIRECTORY
  28. CurDir$ = SPACE$(255)
  29. Result = CURDirectory(LEN(CurDir$), CurDir$)
  30. IF Result THEN LOCATE 11, 1: PRINT "Directory: "; LEFT$(CurDir$, Result)
  31. PRINT "            (1) Change Directory"
  32. PRINT "            (2) Play Song"
  33. PRINT "            (3) Play Directory"
  34. PRINT "            (4) Quit"
  35. INPUT "      ->", a
  36. IF a = 1 THEN GOTO directory:
  37. IF a = 2 THEN GOTO song:
  38. IF a = 3 THEN GOTO playdir:
  39. IF a = 4 THEN END
  40. IF a > 4 OR a < 1 OR a <> INT(a) THEN GOTO begin:
  41. directory:
  42. again:
  43. INPUT "Directory: ", d$
  44. IF d$ = "" THEN GOTO begin:
  45. r% = _DIREXISTS(d$)
  46. IF r% <> -1 THEN
  47.     PRINT "Directory doesn't exist."
  48.     PRINT "Try again, or Enter for Menu."
  49.     GOTO again:
  50. GOTO begin:
  51. song:
  52. 'FILES "*.mp3"
  53. again2:
  54. 'INPUT "Song: ", song$
  55.  
  56.     song$ = SelectFile$("*.*", 100, 100)
  57.  
  58. LOOP UNTIL RIGHT$(song$, 3) = "mp3" OR RIGHT$(song$, 3) = "MP3" OR RIGHT$(song$, 3) = "Mp3" OR RIGHT$(song$, 3) = "mP3"
  59.  
  60.  
  61. 'PRINT "You selected:"; song$
  62.  
  63. 'IF RIGHT$(song$, 3) <> "mp3" OR RIGHT$(song$, 3) <> "MP3" OR RIGHT$(song$, 3) <> "Mp3" OR RIGHT$(song$, 3) <> "mP3" THEN GOTO again2:
  64.  
  65. 'fe% = _FILEEXISTS(song$)
  66. 'IF fe% <> -1 THEN GOTO again2:
  67. 'PRINT "Filename doesn't exist."
  68. 'PRINT "Try again, or Enter for Menu."
  69. 'GOTO again2:
  70. 'END IF
  71. s& = _SNDOPEN(song$)
  72. LOCATE 1, 1: PRINT song$
  73. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  74. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  75. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  76.  
  77.     a$ = INKEY$
  78.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  79.     IF a$ = " " THEN _SNDPAUSE s&
  80.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  81.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  82.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: GOTO begin:
  83.     oldp = p
  84.     p = _SNDGETPOS(s&)
  85.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  86.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO begin:
  87. GOTO begin:
  88. playdir:
  89. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  90. SHELL _HIDE "dir *.mp3 /B > MyMusicFiles-Temp000.temp" 'create mp3 files list.
  91. OPEN "MyMusicFiles-Temp000.temp" FOR INPUT AS #1
  92.     CLOSE #1
  93.     SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  94.     CLS
  95.     PRINT "No mp3 songs on this folder."
  96.     PRINT
  97.     INPUT "Press Enter to go back to Menu.", menu$
  98.     GOTO begin:
  99.     LINE INPUT #1, file$
  100.     file(record) = file$
  101.     f$(record) = file$
  102.     PRINT f$(record)
  103.     record = record + 1 'for next loop we needed array higher up to one
  104.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  105. SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  106. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  107. ready:
  108. s& = _SNDOPEN(file(rec))
  109. LOCATE 1, 1: PRINT f$(rec)
  110. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  111. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  112. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  113.  
  114.     a$ = INKEY$
  115.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  116.     IF a$ = " " THEN _SNDPAUSE s&
  117.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  118.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  119.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: GOTO begin:
  120.     oldp = p
  121.     p = _SNDGETPOS(s&)
  122.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  123.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more:
  124. more:
  125. IF rec = record - 1 THEN GOTO begin:
  126. rec = rec + 1
  127. GOTO ready:
  128.  
  129.  
  130. FUNCTION SelectFile$ (search$, x AS INTEGER, y AS INTEGER)
  131.     'save some old values
  132.     LoadFile_DC = _DEFAULTCOLOR: LoadFile_BG = _BACKGROUNDCOLOR
  133.     LoadFile_s = _SOURCE: LoadFile_d = _DEST
  134.     f = _FONT: _FONT 16
  135.     'some variables
  136.  
  137.     LoadFile_BoxColor = &HFFAAAAFF
  138.     LoadFile_FolderColor = &HFFFFFF00
  139.     LoadFile_FileColor = &HFFFFFFFF
  140.     IF INSTR(_OS$, "[WINDOWS]") THEN LoadFile_Slash$ = "\" ELSE LoadFile_Slash$ = "/"
  141.     LoadFile_Dir$ = SPACE$(FILE_current_dir_length)
  142.     FILE_get_current_dir LoadFile_Dir$
  143.     LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_Slash$
  144.     'LoadFile_Dir$ = "." + LoadFile_Slash$
  145.     LoadFile_w = 639: LoadFile_h = 479
  146.     REDIM LoadFile_Label(0) AS STRING: LoadFile_Label(0) = "DIR"
  147.     REDIM LoadFile_DirList(-1 TO 9, -1 TO 9999) AS STRING
  148.     LoadFile_last = 1
  149.     FolderDeep = 1
  150.  
  151.     'some error checking
  152.     IF search$ = "" THEN EXIT SUB 'We can't search for nothing!
  153.  
  154.     'Copy background
  155.     PCOPY 0, 1
  156.     'set workscreen
  157.     LoadFile_ws = _NEWIMAGE(640, 480, 32)
  158.  
  159.     'Count our filetypes to display
  160.     LoadFile_TypeCount = 0
  161.     DO
  162.         LoadFile_TypeCount = LoadFile_TypeCount + 1
  163.         LoadFile_l = INSTR(LoadFile_l + 1, search$, ";") ' look for ; to denote more files
  164.         REDIM _PRESERVE LoadFile_Label(LoadFile_TypeCount) AS STRING
  165.         IF LoadFile_l > 0 THEN LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LoadFile_l - LoadFile_last - 1) ELSE LoadFile_Label(LoadFile_TypeCount) = MID$(search$, LoadFile_last + 1, LEN(search$) - LoadFile_last)
  166.         LoadFile_last = LoadFile_l + 1
  167.     LOOP UNTIL LoadFile_l = 0
  168.     LoadFile_l = 640 / (LoadFile_TypeCount + 1)
  169.     REDIM LoadFile_start(LoadFile_TypeCount), LoadFile_previous(LoadFile_TypeCount), LoadFile_more(LoadFile_TypeCount), LoadFile_Count(LoadFile_TypeCount)
  170.     FOR i = 0 TO LoadFile_TypeCount: LoadFile_start(i) = 1: NEXT
  171.  
  172.     _SOURCE LoadFile_ws: _DEST LoadFile_ws
  173.     DO
  174.         _LIMIT 30
  175.         FOR i = 0 TO LoadFile_TypeCount
  176.             LoadFile_Count(i) = 0
  177.             FOR j = 0 TO 9999
  178.                 LoadFile_DirList(i, j) = ""
  179.             NEXT
  180.         NEXT
  181.         'Generate our updated directory listings.
  182.  
  183.         IF FILE_load_dir&(LoadFile_Dir$ + CHR$(0)) THEN
  184.             DO
  185.                 LoadFile_length = FILE_has_next_entry 'Get length of next entry
  186.                 IF LoadFile_length > -1 THEN 'If we have a next entry
  187.                     LoadFile_nam$ = SPACE$(LoadFile_length) 'Set the size of our string
  188.                     FILE_get_next_entry LoadFile_nam$, LoadFile_flags, LoadFile_file_size 'Get the file's name, size, and 'flags'
  189.                     'Check if it's a file or a directory
  190.  
  191.                     IF _DIREXISTS(LoadFile_Dir$ + LoadFile_nam$) THEN
  192.                         IF LoadFile_nam$ <> "." THEN
  193.                             LoadFile_Count(0) = LoadFile_Count(0) + 1
  194.                             LoadFile_DirList(0, LoadFile_Count(0)) = LoadFile_nam$
  195.                         END IF
  196.                     ELSE 'We have a file
  197.                         FOR i = 1 TO LoadFile_TypeCount
  198.                             LoadFile_ext$ = RIGHT$(LoadFile_nam$, LEN(LoadFile_Label(i)))
  199.                             IF UCASE$(LoadFile_ext$) = UCASE$(LoadFile_Label(i)) THEN
  200.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  201.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LEFT$(LoadFile_nam$, LEN(LoadFile_nam$) - LEN(LoadFile_Label(i)))
  202.                                 EXIT FOR
  203.                             ELSEIF LoadFile_Label(i) = ".*" THEN
  204.                                 LoadFile_Count(i) = LoadFile_Count(i) + 1
  205.                                 LoadFile_DirList(i, LoadFile_Count(i)) = LoadFile_nam$
  206.                             END IF
  207.                         NEXT
  208.                     END IF
  209.                 END IF
  210.             LOOP UNTIL LoadFile_length = -1
  211.             FILE_close_dir
  212.         END IF
  213.  
  214.         updatelist:
  215.  
  216.  
  217.         CLS , &HFF005050 'Draw a nice display box
  218.         COLOR , 0
  219.         LINE (0, 0)-(LoadFile_w, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor, B
  220.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h + 6 - 2 * 16), LoadFile_BoxColor, B
  221.         LINE (0, 0)-(LoadFile_w, LoadFile_h), LoadFile_BoxColor, B
  222.         LINE (1, 1)-(LoadFile_w - 1, LoadFile_h - 1), LoadFile_BoxColor, B
  223.  
  224.         LINE (0, 16 + 3)-(LoadFile_w, 16 + 3), LoadFile_BoxColor
  225.         LINE (0, 16 + 4)-(LoadFile_w, 16 + 4), LoadFile_BoxColor
  226.         FOR i = 0 TO LoadFile_TypeCount
  227.             _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * LEN(LoadFile_Label(i))) / 2, 2), LoadFile_Label(i)
  228.             LINE (i * LoadFile_l, 0)-(i * LoadFile_l, LoadFile_h + 5 - 2 * 16), LoadFile_BoxColor
  229.         NEXT
  230.  
  231.         LINE (627, 2)-(637, 18), &HFFFF0000, BF
  232.         LINE (626, 2)-(637, 18), &HFF000000, B
  233.  
  234.         _PRINTSTRING (628, 2), "X"
  235.         IF selection > 0 THEN
  236.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp$ = LoadFile_DirList(row, selection)
  237.             IF LoadFile_DirList(row, selection) = "" THEN temp$ = ""
  238.             selection = 0
  239.         END IF
  240.         _PRINTSTRING (10, 28 * 16 + 7), LoadFile_Dir$
  241.         _PRINTSTRING (630 - LEN(temp$) * 8, 28 * 16 + 7), temp$
  242.         IF temp$ = "" THEN oldselection = 0
  243.         IF oldselection > 0 THEN LINE (row * LoadFile_l, (oldselection + 1) * 16 + 5)-((row + 1) * LoadFile_l, (oldselection + 2) * 16 + 5), &HAAAAA000, BF
  244.  
  245.         FOR i = 0 TO UBOUND(LoadFile_label)
  246.             IF i = 0 THEN COLOR LoadFile_FolderColor ELSE COLOR LoadFile_FileColor
  247.             counter = 0
  248.             FOR j = LoadFile_start(i) TO LoadFile_start(i) + 24
  249.                 counter = counter + 1
  250.                 IF LoadFile_DirList(i, j) = "" THEN EXIT FOR
  251.                 _PRINTSTRING (i * LoadFile_l + 5, (counter + 1) * 16 + 7), LEFT$(LoadFile_DirList(i, j), LoadFile_l / 8 - 2)
  252.             NEXT
  253.             IF j = LoadFile_start(i) + 25 THEN LoadFile_more(i) = -1 ELSE LoadFile_more(i) = 0
  254.             IF LoadFile_start(i) > 1 THEN LoadFile_previous(i) = -1 ELSE LoadFile_previous(i) = 0
  255.             IF LoadFile_more(i) THEN
  256.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), &HFFFF0000, BF
  257.                 LINE (i * LoadFile_l + 2, 27 * 16 + 5)-((i + 1) * LoadFile_l - 3, 28 * 16 + 3), BoxColor, B
  258.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 11) / 2, 27 * 16 + 5), "SCROLL DOWN"
  259.                 COLOR LoadFile_FileColor
  260.             END IF
  261.             IF LoadFile_previous(i) THEN
  262.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), &HFFFF0000, BF
  263.                 LINE (i * LoadFile_l + 2, 16 + 5)-((i + 1) * LoadFile_l - 3, 2 * 16 + 3), BoxColor, B
  264.                 COLOR &HFFFFFF00: _PRINTSTRING (i * LoadFile_l + (LoadFile_l - 8 * 9) / 2, 16 + 5), "SCROLL UP"
  265.                 COLOR LoadFile_FileColor
  266.             END IF
  267.         NEXT
  268.  
  269.         _PUTIMAGE (0 + x, 0 + y)-(640 + x, 480 + y), LoadFile_ws, 0
  270.         _DISPLAY
  271.  
  272.         change = 0
  273.         DO
  274.             _LIMIT 30
  275.             LoadFile_LMB = 0 'This sets the left mouse button as unacceptable.
  276.             a = _KEYHIT
  277.             SELECT CASE a
  278.                 CASE 8 'backspace
  279.                     temp$ = LEFT$(temp$, LEN(temp$) - 1)
  280.                     change = -1
  281.                 CASE 13 'enter
  282.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  283.                     temp$ = LoadFile_Dir$ + temp$
  284.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = temp$ 'Restore our old settings
  285.                     _FONT f
  286.                     EXIT SUB 'And leave
  287.                 CASE 27 'If ESC is pressed then...
  288.                     DO: LOOP UNTIL INKEY$ = "" 'Clear the keyboard buffer so it doesn't affect the main program.
  289.                     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = "" 'Restore our old settings
  290.                     _FONT f
  291.                     EXIT SUB 'And leave
  292.                 CASE 32 TO 126
  293.                     temp$ = temp$ + CHR$(a)
  294.                     change = -1
  295.             END SELECT
  296.             DO
  297.                 IF _MOUSEBUTTON(1) = 0 THEN LoadFile_LMB = -1 'Only by lifting the mouse, will we count it as down
  298.                 'Note: we ignore LoadFile_LMB for the scroll bars, so we can just hold it down and scroll happily forever and ever...
  299.                 'or until we get to the limit of our file list.
  300.                 'We only check LoadFile_LMB when actually trying to select an item from our list.   No more "OOP!  I held it too long and did something I didn't want to do!"
  301.                 'Now we click once to select, click again to accept that selection.
  302.             LOOP WHILE _MOUSEINPUT
  303.             MX = _MOUSEX: MY = _MOUSEY
  304.             IF _MOUSEBUTTON(2) OR (LoadFile_LMB AND MX > 626 + x AND MX < 638 + x AND MY > 1 + y AND MY < 19 + y AND _MOUSEBUTTON(1)) THEN
  305.                 'restore those old values, and just exit.  Right mouse is an escape
  306.                 COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY: SelectFile$ = ""
  307.                 _FONT f
  308.                 EXIT SUB
  309.             END IF
  310.             IF _MOUSEBUTTON(1) THEN 'Without the mouse being down, we don't need to check squat!
  311.                 'Check the 2 roLoadFile_ws for a click in the proper Y position
  312.                 IF MY >= 16 + 5 + y AND MY <= 2 * 16 + 3 + y THEN 'We're on the top row
  313.                     FOR j = 0 TO UBOUND(LoadFile_label)
  314.                         IF LoadFile_previous(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  315.                             LoadFile_start(j) = LoadFile_start(j) - 1
  316.                             change = -1: selection = 0: click = 0: temp$ = ""
  317.                             EXIT FOR
  318.                         END IF
  319.                     NEXT
  320.                 ELSEIF MY >= 27 * 16 + 5 + y AND MY <= 28 * 16 + 3 + y THEN 'We're on the bottom row
  321.                     FOR j = 0 TO UBOUND(LoadFile_label)
  322.                         IF LoadFile_more(j) AND MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  323.                             LoadFile_start(j) = LoadFile_start(j) + 1
  324.                             change = -1: selection = 0: click = 0: temp$ = ""
  325.                             EXIT FOR
  326.                         END IF
  327.                     NEXT
  328.                 ELSEIF MY >= 37 + y AND MY <= 437 + y AND LoadFile_LMB THEN 'It's in a column somewhere.  Did someone click an item?!
  329.                     FOR j = 0 TO UBOUND(LoadFile_label)
  330.                         IF MX >= j * LoadFile_l + 2 + x AND MX <= (j + 1) * LoadFile_l - 3 + x THEN
  331.                             row = j
  332.                             oldselection = INT((MY - y - 37) / 16) + 1
  333.                             selection = LoadFile_start(j) + oldselection - 1
  334.                             change = -1
  335.                             click = -1
  336.                             EXIT FOR
  337.                         END IF
  338.                     NEXT
  339.                 END IF
  340.             END IF
  341.  
  342.             _DISPLAY
  343.         LOOP UNTIL change
  344.         IF click THEN 'we clicked something besides a scroll bar
  345.             IF LoadFile_Label(row) <> ".*" AND LoadFile_Label(row) <> "DIR" THEN temp1$ = LoadFile_DirList(row, selection) + LoadFile_Label(row) ELSE temp1$ = LoadFile_DirList(row, selection)
  346.             IF temp$ = temp1$ THEN
  347.                 'We picked one!
  348.                 SELECT CASE LoadFile_Label(row)
  349.                     CASE "DIR"
  350.                         IF LoadFile_DirList(row, selection) <> ".." THEN
  351.                             LoadFile_Dir$ = LoadFile_Dir$ + LoadFile_DirList(row, selection) + LoadFile_Slash$
  352.                         ELSE
  353.                             DO
  354.                                 LoadFile_Dir$ = LEFT$(LoadFile_Dir$, LEN(LoadFile_Dir$) - 1)
  355.                             LOOP UNTIL RIGHT$(LoadFile_Dir$, 1) = LoadFile_Slash$ OR LEN(LoadFile_Dir$) = 0
  356.                         END IF
  357.                         FOR i = 1 TO UBOUND(Loadfile_start)
  358.                             LoadFile_start(i) = 1
  359.                         NEXT
  360.                         selection = 0: temp$ = "": oldselection = 0
  361.                     CASE ".*": SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  362.                     CASE ELSE: SelectFile$ = LoadFile_Dir$ + temp$: EXIT DO
  363.                 END SELECT
  364.             END IF
  365.             IF row > 0 THEN _DELAY .2: GOTO updatelist
  366.         ELSE
  367.             _DELAY .05
  368.             GOTO updatelist
  369.         END IF
  370.     LOOP
  371.     'restore those old values
  372.     COLOR LoadFile_DC, LoadFile_BG: _SOURCE LoadFile_s: _DEST LoadFile_d: PCOPY 1, 0: _DISPLAY
  373.     _FONT f
  374.  
  375. 'If you don't have a copy of direntry.h in your QB64 folder, then copy the following code into a new IDE window.
  376. 'Then remove the remarks.
  377. 'And save it as direntry.h
  378. 'direntry.h is required for this to work properly with the library files.
  379. 'I thought adding the code here would be a way to make certain that it'd be easy to recover the file
  380. 'in case something ever happened and it was accidently deleted off the drive for some reason.
  381.  
  382. '#include <dirent.h>
  383. '#include <sys/stat.h>
  384. '#include <unistd.h>
  385.  
  386. 'const int IS_DIR_FLAG = 1, IS_FILE_FLAG = 2;
  387.  
  388. 'DIR *pdir;
  389. 'struct dirent *next_entry;
  390. 'struct stat statbuf1;
  391.  
  392. 'char current_dir[FILENAME_MAX];
  393. '#ifdef QB64_WINDOWS
  394. '  #define GetCurrentDir _getcwd
  395. '#else
  396. '  #define GetCurrentDir getcwd
  397. '#endif
  398.  
  399. 'int load_dir (char * path) {
  400. '  struct dirent *pent;
  401. '  struct stat statbuf1;
  402. '//Open current directory
  403. 'pdir = opendir(path);
  404. 'if (!pdir) {
  405. 'return 0; //Didn't open
  406. '}
  407. 'return -1;
  408. '}
  409.  
  410. 'int has_next_entry () {
  411. '  next_entry = readdir(pdir);
  412. '  if (next_entry == NULL) return -1;
  413.  
  414. '  stat(next_entry->d_name, &statbuf1);
  415. '  return strlen(next_entry->d_name);
  416. '}
  417.  
  418. 'void get_next_entry (char * nam, int * flags, int * file_size) {
  419. '  strcpy(nam, next_entry->d_name);
  420. '  if (S_ISDIR(statbuf1.st_mode)) {
  421. '    *flags = IS_DIR_FLAG;
  422. '  } else {
  423. '    *flags = IS_FILE_FLAG;
  424. '  }
  425. '  *file_size = statbuf1.st_size;
  426. '  return ;
  427. '}
  428.  
  429. 'void close_dir () {
  430. '  closedir(pdir);
  431. '  pdir = NULL;
  432. '  return ;
  433. '}
  434.  
  435. 'int current_dir_length () {
  436. '  GetCurrentDir(current_dir, sizeof(current_dir));
  437. '  return strlen(current_dir);
  438. '}
  439.  
  440. 'void get_current_dir(char *dir) {
  441. '  memcpy(dir, current_dir, strlen(current_dir));
  442. '  return ;
  443. '}
  444.  
  445.  
  446.  
  447.  
« Last Edit: August 22, 2019, 10:13:58 pm by SierraKen »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Problem With Wiki Example
« Reply #12 on: August 22, 2019, 10:21:26 pm »
Wow that has some great potential B+! But when I try to click the .. to go to regular C: it says File Not Found on line 27.
 OPEN TmpFile$ FOR INPUT AS #1

I have to get to C: to get to my Music folder. But that's a really cool folder picker! I'll look into it more. It might be a SUB that I don't need like you said.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Problem With Wiki Example
« Reply #13 on: August 22, 2019, 10:28:13 pm »
Wow that has some great potential B+! But when I try to click the .. to go to regular C: it says File Not Found on line 27.
 OPEN TmpFile$ FOR INPUT AS #1

I have to get to C: to get to my Music folder. But that's a really cool folder picker! I'll look into it more. It might be a SUB that I don't need like you said.

Ah, if your files are near root C: I don't think Windows will let us go there. I could only navigate below users in my user name folder and below, Desktop, Documents, Downloads, ... there might be a way through but I don't know it.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Problem With Wiki Example
« Reply #14 on: August 22, 2019, 10:39:51 pm »
Actually B+ your program starts out right where your QB64 programs are, not the Users folder. I just ran a scan on my computer and it doesn't have the file DIR$INF0.INF. I wonder if it's because I am 64 bit Windows 10. I have my programs in (you guys will laugh) C:\QBasic because when I started I converted a lot of QBasic programs to QB64. And I have my entire QB64 inside C:\QBasic. So, this demonstration program starts at C:\QBasic. I just can't get it to C: and you are probably right, Microsoft is being Microsoft again. lol

I need to do some things tonight so I'll look into all of this another day real soon. Thanks again you 2. I haven't given up hope, yet. lol