News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Explorer sucks, FileOpen$() works

Started by jj2007, September 30, 2012, 08:28:47 AM

Previous topic - Next topic

jj2007

As a remedy against my eternal allergy to Windows Explorer and its habit to present me folders with gross boring icons in useless sorting orders, I decided to develop something simple - really simple (console assembly & link if you are still using an editor without autodetection):

include \masm32\MasmBasic\MasmBasic.inc   ; download
  Init

  .if FileOpen$("Rich source=*.asc|Poor sauce=*.asm|Resource=*.rc")
       PrintLine "You opened  [", FileOpen$(), "]"          ; empty brackets means result only
  .else
       PrintLine "You cancelled"
  .endif

  .if FileSave$("Rich source=*.asc|Poor sauce=*.asm|Other stuff=*.*", "Save your source as...", "MySource.asm")
       PrintLine "You really want to save [", FileSave$(), "]??"          ; empty brackets means result only
  .endif

  Inkey
  Exit       ; full syntax: FileOpen$("filter" [, "title"] [, "current"] [, flags] [, sortcolumn])
end start

Under the hood, a whopping 500 bytes are working, but the surface looks neat and tidy :bgrin:

More usage examples attached. Users with OPENFILENAME experience may have some fun with various advanced options.

jj2007

I could not resist to add a Unicode version  :biggrin:

The FileOpenDemoSource.zip archive contains a 7-Zip archive with some Unicode name test files.

qWord

Hi,
Looks good - have you implement the whole dialog yourself?
MREAL macros - when you need floating point arithmetic while assembling!

jj2007

Quote from: qWord on October 02, 2012, 09:32:47 AM
Hi,
Looks good - have you implement the whole dialog yourself?

Thanks :biggrin:
Under the hood are GetSaveFileName, GetOpenFileName and their W variants, plus a hook procedure. And yes it's written completely from scratch.

I doubt that M$ will take over the design for Windows 9, but IMHO for a coder the details view with latest files on top is the "natural" design ;-)

hutch--

I must be lazy, I use the ancient WINFILE from NT4. With a little assistance it even works on Win7 64 bit.  :biggrin:

japheth

Quote from: jj2007 on September 30, 2012, 08:28:47 AM
As a remedy against my eternal allergy to Windows Explorer and its habit to present me folders with gross boring icons in useless sorting orders...

Windows Explorer never treats me like this, it always shows files in neat detailed view. You must do something wrong - perhaps it feels a significant lack of love on your side ...

Quote
include \masm32\MasmBasic\MasmBasic.inc   ; download
  Init

  .if FileOpen$("Rich source=*.asc|Poor sauce=*.asm|Resource=*.rc")
       PrintLine "You opened  [", FileOpen$(), "]"          ; empty brackets means result only
  .else
       PrintLine "You cancelled"
  .endif

  .if FileSave$("Rich source=*.asc|Poor sauce=*.asm|Other stuff=*.*", "Save your source as...", "MySource.asm")
       PrintLine "You really want to save [", FileSave$(), "]??"          ; empty brackets means result only
  .endif

  Inkey
  Exit       ; full syntax: FileOpen$("filter" [, "title"] [, "current"] [, flags] [, sortcolumn])
end start

There's not ONE true assembly line in your code. What is a noobie supposed to think about Masm if it sees such a thing?


jj2007

Quote from: japheth on October 02, 2012, 07:28:42 PM
Windows Explorer never treats me like this, it always shows files in neat detailed view.
Teach me: Which magic are you using that forces Explorer to show you all folders in detailed view, most recent files first?

QuoteThere's not ONE true assembly line in your code. What is a noobie supposed to think about Masm if it sees such a thing?

That Masm is as easy as BASIC  :biggrin:

japheth

Quote from: jj2007 on October 02, 2012, 08:09:33 PM
Teach me: Which magic are you using that forces Explorer to show you all folders in detailed view, most recent files first?

I select Tools/Folder Options, then View, and then press "Apply to all Folders" ( the check-box "Remember each folder's view setting"  is NOT selected ).

Quote
That Masm is as easy as BASIC  :biggrin:

I'm very old-fashioned and strongly believe that to truly learn something, it must be coupled with some pain. Now, to see BASIC code is always "some pain", but it's the wrong type of pain.

dedndave

i do check the "Remember each folders view settings" box
once you have set all the folders to your "default" mode,
you can go to things like the Control Panel folder and make them different


jj2007

#9
Quote from: japheth on October 02, 2012, 09:39:20 PM
I select Tools/Folder Options, then View, and then press "Apply to all Folders" ( the check-box "Remember each folder's view setting"  is NOT selected ).

Thank you, Japheth and Dave, for reminding me that Explorer has this option. Unfortunately, they are not being used when calling GetOpenFileName from an app.

QuoteI'm very old-fashioned and strongly believe that to truly learn something, it must be coupled with some pain. Now, to see BASIC code is always "some pain", but it's the wrong type of pain.

Believe me, there was some pain involved when developing MasmBasic (e.g. the workarounds for a well-known alternative assembler :biggrin:)

That is nothing, though, compared to the pain of looking at C or C++ code with its horrible orgy of include statements and {brackets} and semicolons after each line, and .Break; statements after each case to prevent fall-thru etc - I guess the guy who developed the syntax died from repetitive stress injury.

Not to mention that 90% of all "simple" Hello World etc examples of C or C++ code that you find on the web fail miserably with more or less incomprehensive error messages ("failed to convert", asdijsfjaufj.h missing or corrupt, ...) when opened in the Industry Standard, i.e. Visual Express.

Not to mention that many of the "brofessional" applications developed in C or C++, like MSIE, Office, Acrobat, Firefox are, after decades of development, still ridden with partly dangerous bugs. My best guess is that their coders need something more simple and reliable, like BASIC.

hutch--

Basic as a computer language is fundamentally a concept, the idea that at least some programming tasks need not be complicated with the format of the language or more correctly that the language should at least simplify tasks that are simple in nature. It is the confines of a language that make the difference, many dialects of basic are little better than crippleware (most Microsoft versions from QB onwards). This has also produced a high level of ignorance in "other language" experts in associating Basic with 1980 line numbered ROM basic yet like any other language, Basic has evolved.

The FORTRAN of 1980, ALGOL of earlier periods and the early C language formats gave way to more powerful and usually simpler dialects in compiled languages but over time it also lead to trashy languages that placed simplicity above performance. In modern times C and its derivative C++ have become the dominant professional language, Pascal is on its last legs and basic survives in a number of specialised dialects. Assembler has a botique notch for specialised tasks, usually performance requirements.

When I write basic, I use a specialised basic compiler, in my case PowerBASIC as it has been a very useful tool over the 15 years I have used it as it is flexible enough for me to write in a funny combination of asm, basic and C, usually mixed. Where I want the architectural advantage of asm, I use MASM as it allows me to do things that compilers don't. The other factor is I like writing general purpose code in MASM and have years of libraries to support it. The last version of QE that I wrote was in MASM rather than PB as it saved me over 2 weeks in its production, the difference I attribute to both a large collection of libraries (all MASM) and the architectural freedom to write anything I liked.

Now with the dialect of basic that JJ has designed, I have a reasonable idea of where he is coming from in that I used GFA basic back in the middle 1990s as it outperformed the current Microsoft C++ in both speed and size. Back then it was a dialect of basic that routinely used addressing, the full API functions and its libraries were all hand written assembler. Over time my targeting of apps has shifted, I write the type of stuff I long ago wrote in C in MASM, the type of stuff I write in basic contains near identical assembler code and the difference is in leveraging the different capacities of both language formats.

Where I want the capacity of the dynamic string engine and a large number of intrinsics, I use the basic compiler, when I want the architectural adantages of an assembler, I use MASM and I live with a reasonably large range of overlap between them, particularly as I can routinely port MASM to basic these days. Apart from a lot of extra work to create it, JJ has done a similar thing in that he can write something that looks a lot like basic yet can directly drop into MASM code when the task requires it. I see his dialect as a viable extension to MASM that leverages many of the advantages of basic yet retains the performance of MASM.

jj2007

#11
Quote from: hutch-- on October 03, 2012, 03:11:10 AMJJ has done a similar thing in that he can write something that looks a lot like basic yet can directly drop into MASM code when the task requires it. I see his dialect as a viable extension to MASM that leverages many of the advantages of basic yet retains the performance of MASM.

Thanks, Hutch - that is precisely my idea. MasmBasic is inline basic for assembler; you replace
include \masm32\include\masm32rt.inc with
include \masm32\MasmBasic\MasmBasic.inc and... your app still assembles as before. However, you can speed up your production process with, see above, a file opener that would otherwise cost a bit of time, say: 5 minutes for our geeks here, but weeks for the assembly noob.
So let the newbie be impressed by the easiness of "assembler", and let him concentrate his efforts instead on learning opcodes. The deb macro will show him what happens to eax...

By the way, if I had not discovered the Masm macro engine, I would have probably settled for PowerBasic. It is a good product, and it was the only real alternative to my old 16-bit GfaBasic. Now I do all my projects in MasmBasic, but the share of "real" assembly remains high. It is good to have a dynamic string engine, it is good to have imul eax, myvar, 100, too. Let both worlds coexist  :biggrin:

I have updated the library with a fix for an incompatibility issue between XP and Win7, and I have added a new function:
   FileOpenSetFolder "\masm32\RichMasm\SimpleDialog"
   wFileOpenSetFolder "\masm32\examples\unicode_extended\UnicodeTest_GUI"

Sample attached (zip archive with 7-zip archive inside - my WinZip doesn't know about Unicode file names...). MasmBasic version 3 October required, tested with JWasm and Masm 6.15, 8, 9 and 10.