BBC BASIC for Windows
« GetOpenFileName selecting *multiple* files? »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:15pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1 2  Notify Send Topic Print
 veryhotthread  Author  Topic: GetOpenFileName selecting *multiple* files?  (Read 553 times)
81RED
Guest
xx GetOpenFileName selecting *multiple* files?
« Thread started on: Feb 20th, 2010, 11:17am »

Has anyone ever used the Windows GetOpenFileName API call to select and process multiple files? (As in selecting more than one file when presented with the file browser dialogue)

According to the OPENFILENAME structure documented here:
http://msdn.microsoft.com/en-us/library/ms646839%28VS.85%29.aspx

It certainly looks like it should be possible, but given my track record of almost* consistently failing to translate anything on MSDN into functioning BB4W code, I'd really appreciate some help.. embarassed

*Actually managed to create a multiline tooltip last night from the documentation found on MSDN. But to be honest, that was rather trivial compared to the above link which causes me to involuntarily reach for my medication.

User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #1 on: Feb 20th, 2010, 3:03pm »

It's only a matter of setting the flag

OFN_ALLOWMULTISELECT

There's an example in my Audio Player.
http://tech.groups.yahoo.com/group/bb4w/files/Sound-Music/
User IP Logged

81RED
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #2 on: Feb 20th, 2010, 6:04pm »

Absolutely fantastic, thank you very much Malcolm! cheesy

How on earth one is supposed to deduce that Ofn.flags% = &80206 by reading that MSDN article, I will ponder some other day....
User IP Logged

Richard Russell
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #3 on: Feb 20th, 2010, 11:16pm »

on Feb 20th, 2010, 3:03pm, Guest-Malcolm wrote:
It's only a matter of setting the flag OFN_ALLOWMULTISELECT

Actually there's quite a lot more to it than that, because of the rather complicated way the list of files is returned. You need to take account of two cases: when only one file was selected and when two or more files are selected; the data formats are different!

Normally I'd list the code here, but as I'm still hors de combat (after more than two weeks) I can't easily access my main PC on which the code resides. Sorry.

If you still want it after I'm fully recovered (could be a few more weeks at least) remind me then.

Richard.
User IP Logged

Richard Russell
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #4 on: Feb 20th, 2010, 11:25pm »

on Feb 20th, 2010, 6:04pm, Simon Mathiassen wrote:
How on earth one is supposed to deduce that Ofn.flags% = &80206 by reading that MSDN article

One isn't. Now we have Michael Hutton's excellent 'Windows Constants' utility we write this and then get the utility to do the hard work:

Code:
Ofn.flags% = OFN_EXPLORER + OFN_ALLOWMULTISELECT + OFN_HIDEREADONLY 


(OFN_OVERWRITEPROMPT, which is also set in the hex constant you quoted, is meaningless when selecting a file to be read).

Richard.
User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #5 on: Feb 21st, 2010, 12:24am »

Quote:
Actually there's quite a lot more to it than that, because of the rather complicated way the list of files is returned. You need to take account of two cases: when only one file was selected and when two or more files are selected; the data formats are different!


True. The sorting of different formats is also in The Audio Player. I had forgotten that was necessary.

The other thing you need to realize is that the last selected file comes first or top of you returned list.

So if you are in the habit of selecting down from the top. the order will be, the bottom file, then the top reading down the selection to the bottom -1.
If you select from the bottom up then the order is top to bottom. There may be a flag that stop this but I never found it.

User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #6 on: Feb 21st, 2010, 09:28am »

on Feb 21st, 2010, 12:24am, Guest-Malcolm wrote:
The other thing you need to realize is that the last selected file comes first or top of you returned list.
So if you are in the habit of selecting down from the top. the order will be, the bottom file, then the top reading down the selection to the bottom -1.
If you select from the bottom up then the order is top to bottom. There may be a flag that stop this but I never found it.

In fact I don't think the order of the returned files is guaranteed to have any specific relationship with the order in which they are selected (especially if you use Shift+LeftClick to do the multi-selection, because then they weren't selected in any order!).

If the order matters, I put the returned filenames into an array (the code I wanted to post does that anyway) then I sort the array into alphabetical sequence.

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #7 on: Feb 21st, 2010, 09:58am »

on Feb 20th, 2010, 11:16pm, Guest-Richard Russell wrote:
Normally I'd list the code here, but as I'm still hors de combat (after more than two weeks) I can't easily access my main PC

I've managed to extract the code by connecting to my main PC wirelessly (sneaky!). Here it is:

Code:
      fp% = fs.lpstrFile%
      total% = 0
      WHILE ($$fp% <> "")
        o$(total%) = $$fp%
        fp% += LEN$$fp% + 1
        total% += 1
      ENDWHILE
      IF total% > 1 THEN
        total% -= 1
        FOR I% = 1 TO total%
          o$(I%) = o$(0) + "\" + o$(I%)
        NEXT
      ELSE
        o$(1) = o$(0)
      ENDIF 

It is assumed that the o$() array has already been dimensioned to hold as many files as may ever be selected. On exit from this code total% holds the number of files selected and o$(1) to o$(total%) are the full path+filenames of the selected files.

Richard.
User IP Logged

81RED
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #8 on: Feb 21st, 2010, 1:09pm »

@Richard: Thank you for that code! Is somewhat more transparent than what I ended up with after taking snippets from Malcolms Audioplayer source, and is something that's definitely worthy of a wiki entry if you ask me. Am doing my best not to think about how long that would have taken me, had you gentlemen not been there to help....

@Malcolm: Your Audioplayer is wonderful! Ultra-lightweight and loads practically instantly compared to several other "bloatware" offerings currently available. Adding a seeking trackbar and mouse scrollwheel volume controls would put it right in the frontline. smiley
User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #9 on: Feb 21st, 2010, 3:06pm »


I agree it is much more compact than my code and deserved of a Wiki in due course.

Quote:
Adding a seeking trackbar and mouse scrollwheel volume controls would put it right in the frontline.


I don't understand the seeking trackbar. Is that how far through a track one is? The standard trackbar is kind of large so it would involve designing my own. But I guess that's possible. Thanks for the comments.

User IP Logged

81RED
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #10 on: Feb 21st, 2010, 3:23pm »

on Feb 21st, 2010, 3:06pm, Guest-Malcolm wrote:
I don't understand the seeking trackbar. Is that how far through a track one is?

Sorry Malcolm, I'm not entirely sure what the correct English term is - but yes, its purpose is to quickly go to/seek to a certain point in the track. If you for example want to resume listening to something at the 30-minute mark out of a 1 hour track, you would drag the "trackbar" to the middle.

Hope that makes some sort of sense...
User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #11 on: Feb 21st, 2010, 3:56pm »

OK. Yes your terminology was correct.
I'll see if that is something I can do. Note that the randomizing code has a bug I have just noticed so I will be reissuing the program soon. It may have some new features.

Quote:
I've managed to extract the code by connecting to my main PC wirelessly (sneaky!).

Richard, thanks for the code snippet. I am always amazed at the brevity of your code.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #12 on: Feb 21st, 2010, 4:39pm »

on Feb 21st, 2010, 3:56pm, Guest-Malcolm wrote:
Richard, thanks for the code snippet. I am always amazed at the brevity of your code.

I expect it stems from the reduced capacity of my brain - quite literally as I have a fluid-filled arachnoid cyst where some of my brain should be!

Richard.
User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #13 on: Feb 22nd, 2010, 12:20am »

Here is the essence of the code I used in the Audio Player.
I was also extracting the name less path for the title bar. (not shown here)

Code:
      REM Open or select multiple files
      
      OFN_ALLOWMULTISELECT = &200  :REM Thanks to Michael Hutton for ADD WIN CONSTANTS
      OFN_EXPLORER = &80000
      OFN_HIDEREADONLY = &4
      OFN_OVERWRITEPROMPT = &2
      
      REM Define OpenFile Structure for Open Dialog box
      DIM Ofn{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
      \      lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
      \      lpstrFile%, nMaxFile%, lpstrFileTitle%, \
      \      nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
      \      flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
      \      lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
      DIM FileName% 7999  :REM Room for 256 file titles.
      filter$ = "Media files"+CHR$0+"*.MP3;*.WMA;*.WAV;*.MID"+CHR$0+"All files"+CHR$0+"*.*"+CHR$0+CHR$0
      Ofn.lStructSize% = DIM(Ofn{})
      Ofn.hwndOwner% = @hwnd%
      Ofn.lpstrFilter% = !^filter$
      Ofn.lpstrFile% = FileName%        :REM A pointer to where all the file names are returned.
      Ofn.nMaxFile% = 8000
      Ofn.flags% =   OFN_HIDEREADONLY OR OFN_ALLOWMULTISELECT OR OFN_EXPLORER
      
      DIM Song%(256) :REM Holds offset to start of song(n)'s filename in returned string.
      
      SYS "GetOpenFileName", Ofn{} TO R%  :REM Normal Open Dialog operation
      a$=""
      
      IF $$FileName%="" THEN PRINT "None Selected":END
      
      nFiles%=0
      IF Ofn.nFileExtension.l&  THEN
        nFiles%=1
      ELSE :REM More than one file
        I%=Ofn.nFileOffset.l& : REM First file name starts at FileName%?nFileOffset.l&
        Song%(nFiles%)=I% : REM Format in FileName%  Path null title1 null title2 null title3 null : I% points to first null
        REPEAT
          WHILE FileName%?I% >0  AND  I% < 7999 :REM Look for Zero's that terminate title strings.
            I%+=1
          ENDWHILE
          nFiles%+=1 :I%+=1
          Song%(nFiles%)=I%  :REM Save the position of the title within $$FileName%
          :REM Song (n)'s filename starts at Song%(n) offset from FileName%
        UNTIL FileName%?I%=0 OR nFiles%=256
      ENDIF
      Fn$=$$FileName%
      
      
      REM Test
      PRINT "Number of files :"; nFiles%
      IF nFiles%>1 THEN
        FOR Trk%=0 TO nFiles%-1
          a$=Fn$+"\"+$$(FileName%+Song%(Trk%))
          PRINTa$
        NEXT
      ELSE a$=Fn$
      ENDIF
      
      END
 


The essential difference from Richard's code is that I did not store the strings in an array because they are already stored in the buffer. I had an array to store the start position of the strings of the file titles in the buffer. Then I compiled the complete filename with path as needed.

Obviously if I wanted to use the buffer for some other file operation then this would not be acceptable. I only had a play list to open and each selection overwrote the previous.
But it does consume less memory which might be important. It really wasn't for me as the Audio Player quickly grew too large for the Demo version of BB4W.


User IP Logged

Malcolm
Guest
xx Re: GetOpenFileName selecting *multiple* files?
« Reply #14 on: Feb 22nd, 2010, 05:21am »

Quote:
Adding a seeking trackbar and mouse scrollwheel volume controls would put it right in the frontline. smiley


Actually that worked out easier than I thought it would.
Take a look in the Temp Folder for a test version and let me know if that's what you had in mind. Suggestions about the implementations welcomed.
Still to test it fully on CD's but it seems to work on MP3 and WMA just fine. Window had to get a little larger.
User IP Logged

Pages: 1 2  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls