Author |
Topic: GetOpenFileName selecting *multiple* files? (Read 562 times) |
|
Malcolm
Guest
|
 |
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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
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.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
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.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
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.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #15 on: Feb 22nd, 2010, 09:31am » |
|
on Feb 22nd, 2010, 12:20am, Guest-Malcolm wrote:| The essential difference from Richard's code is that I did not store the strings in an array |
|
I nearly always want to sort the list of filenames, so I need them in an array anyway for the convenience of using SORTLIB.
Quote: IF Ofn.nFileExtension.l& THEN nFiles%=1 |
|
Are you sure this works reliably? According to my reading of MSDN, if the user selects a single file which doesn't have an extension Ofn.nFileExtension.l% will be zero and your code will assume a multiple-file selection has been made!
http://msdn.microsoft.com/en-us/library/ms646839.aspx
'If lpstrFile points to a string that does not contain any "." character such as "c:\dir1\dir2\readme", this member contains zero'.
Richard.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #16 on: Feb 22nd, 2010, 2:11pm » |
|
Quote:| Are you sure this works reliably? |
|
Probably not! Of course it would fail to play anything with no extension either.
It is worthy of an additional check for that case though, thanks.
|
|
Logged
|
|
|
|
81RED
Guest
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #17 on: Feb 22nd, 2010, 2:32pm » |
|
on Feb 22nd, 2010, 05:21am, Guest-Malcolm wrote: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. |
|
Wow, that was quick. Excellent job. It it was up to me, the trackbar (did we agree on that term?) should be a little bit bigger as it currently requires something equivalent to surgical precision to hit. Neverthelesss, your audioplayer is now the standard application for playback on my PCs.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #18 on: Feb 22nd, 2010, 2:35pm » |
|
on Feb 22nd, 2010, 2:11pm, Guest-Malcolm wrote:| Of course it would fail to play anything with no extension either. |
|
That's not obvious to me. I can rename a .MP3 file to have no extension, and it will still play in Windows Media Player (it warns me that it's not a recognised extension, but asks if I want to play it anyway). Often, with media files, the file type is identified by information within the file itself (e.g. a header) rather than the extension.
If it really is the case that your program won't play a file if it doesn't have one of the 'recognised' extensions, why does it let me select an 'All files (*.*)' filter?
Richard.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #19 on: Feb 22nd, 2010, 3:51pm » |
|
If it finds a codec it will play other types. I just can't predict what file extensions might be used in the furute.
No extension give a "Wrong File Type" error.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #20 on: Feb 22nd, 2010, 4:59pm » |
|
on Feb 22nd, 2010, 3:51pm, Guest-Malcolm wrote:| No extension give a "Wrong File Type" error. |
|
A possible explanation is that Windows Media Player is probably using Direct Show (or something even more modern!) and your program is using MCI. It may well be that MCI still uses the file extension to identify the type.
later Confirmed it: I can play my renamed MP3 file (with no extension) using the Direct Show code here:
http://bb4w.wikispaces.com/Playing+a+media+file+using+Direct+Show
Fortunately for you, as far as audio is concerned MCI still seems to support all the common formats. For video, it's no longer very satisfactory to use MCI since too many formats only have Direct Show (or later) codecs.
Richard.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #21 on: Feb 25th, 2010, 5:45pm » |
|
Quote: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!). |
|
Absolutely they are. That will be the last selected file (or the end of the shift left click selection), then the order in which they appear in the directory listing. If the file directory was sorted on a particular criterion prior to selection that is the order.
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #22 on: Feb 25th, 2010, 5:54pm » |
|
Quote:| Fortunately for you, as far as audio is concerned MCI still seems to support all the common formats. |
|
Unless anyone thinks that MCI is going away anytime soon, the Microsoft developers blog tells how they planned to get rid of MCI in the 64 bit platforms until they realized that CD support could not be done by any of the alternatives they had, so they put MCI back in. The question then becomes when can you end of life an API. They seemed to think it can only happen with a change of platform and when there are well accepted alternatives. That typically means 3 to 4 versions of windows after the alternative API is introduced. Or perhaps when CDs are the equivalent of 8-track.
So the next platform change after 64 bit might be some while. I'll certainly be too old to care.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #23 on: Feb 25th, 2010, 11:42pm » |
|
on Feb 25th, 2010, 5:45pm, Guest-Malcolm wrote: Link, please! Not that I disbelieve you, but I'd like to see it from the horse's mouth. On a quick search, I didn't manage to find anything in MSDN about the returned file order.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: GetOpenFileName selecting *multiple* files?
« Reply #24 on: Feb 25th, 2010, 11:50pm » |
|
on Feb 25th, 2010, 5:54pm, Guest-Malcolm wrote:| Unless anyone thinks that MCI is going away anytime soon... |
|
MCI can't go away, any more than any other Windows API, but new audio formats can come along which MCI won't necessarily support. Is your audio player happy to play Ogg Vorbis files, for example? These are becoming increasingly popular.
Richard.
|
|
Logged
|
|
|
|
|