The MASM Forum

General => The Workshop => Topic started by: NoCforMe on December 31, 2022, 02:42:12 PM

Title: Project: TheBox, a handy little container
Post by: NoCforMe on December 31, 2022, 02:42:12 PM
Just finished got this li'l project ready for its first spin around the block. (Like most of my projects, it'll probably never really be finished.) This one fills a need I've had since switching away from Windows XP: it's basically a folder you can use to store things in and have them in one place. Sounds trivial, but check it out; there may be more here than meets the eye at first.

TheBox is a window that can hold "items", items being any kind of file. After placing items in this window you can access them just like in an Explorer window. Double-click the item and it opens. (It can be any kind of file, not just an executable.) You can assign an "altIcon" (alternate icon) to the item if you wish, and set its caption.

It does sound simple now that I describe it, but it's not really simple. Complete code and all files needed to create it attached below.

Here's what went into this little project:

Items can be added either by dragging them into the window or through the Add Item menu item and browsing to the file. Either way, the full file path is stored, and its parsed (through my GRE (Get Root and Extension) technology to separate the root filename from the path; this is set as the default caption, same as when you create a shortcut through Explorer. You can edit this caption; an edit window pops up and accepts the new name. (Editing and some other functions are available through a right-click pop-up menu.)

The "default" icon is gotten by calling SHGetFileInfo(); actually, this is only done when it's time to paint the item's window. This function gives us the icon associated with the item, the same one that Windows uses whenever it displays an icon for a file.

There's a lot of stuff in this program to let you assign "alternate" icons, even though this will probably not be used all that often. (It was fun to program, though, which is why I did it.) You can choose an icon from any other file, executable or not, and assign it to an item. That "altIcon" is stored as two simple pieces of data: the name of the file and an index. The index lets you select an icon from files that have multiple icons. If an altIcon is selected, the icon display routines use ExtractIconEx() instead, which is an incredibly easy-to-use function:


INVOKE ExtractIconEx, <file name>, <icon index>, ADDR iconHandle, NULL, 1


gets the requested icon and stores its handle in IconHandle. Easy peasy. (This same function is used in the icon browser, where it can retrieve all of the icons in a file in one fell swoop. Pretty kewl.)

Another incredibly easy thing to do was opening an item. I tried using CreateProcess() at first, but it was a pain in the ass. Then I found ShellExecute(). It's so damn simple:


INVOKE ShellExecute, NULL, OFFSET OpenStr, <file name>, NULL, NULL, SW_NORMAL


opens any file that can be opened by Windows. If it's not an executable, the appropriate application is opened. Also very kewl.

To create the icon browser I needed a control to hold the icons and allow them to be scrolled through. I looked at the dialog you get when you select Properties--> Change Icon (only seems to be available for shortcuts, not for .exes). WinSpy told me that the window displaying the icons was a ListBox, but I couldn't see any way for a Windows listbox to work. Then I realized: hey, my homemade control, which I call mcListbox (for multi-column listbox) should work. (That control is used in my editor, EdAsm, which I posted here earlier.) Well, I tried it and realized it would work, but not in the unfinished state it was in. It was really designed to display text items, with maybe an icon at the left of each item. So nothing to do but to get it ready for this project. That was about a day-and-a-half's work. I even added the keyboard interface it had been lacking. So if you use the icon browser, that's mcListbox showing those icons. (If anyone's interested in using that control I can post it as another project.) That code is in an object file (no .asm source for it here; it's pretty big).

A major part of this project is its configuration functionality. It uses a simple ASCII text configuration file, TheBox.cfg, which is created in the folder containing the executable (it finds its "home" folder and always looks for the .cfg file there). The config file stores:

The config file in the zip attachment is empty. Add some items, then look at the config file (after you close the program) and see how it stores them.

For this parser I added something which I think is potentially very useful: forgiveness. Up to now all my parsers would stop and return an error if they ran into any "unknown" text, like an unknown keyword. For this project, I made the parser simply scan off any such unknown identifiers, by simply scanning to the end of line and ignoring that line. (The parser is line-oriented, with one "record" per line, except for some multi-line constructs like the "item" here.) So this makes the parser "future-proof", so new features, with new configuration items, can be added to the program, but an older version of the program could still read a new config file and not choke.

You can test this feature if you want: edit the config file and add a line, like "icecream = delicious" or whatever, then try running the program. It should still read the rest of the config file. (Just don't put this statement inside the "item ()" block.)

So check it out and let us know what you think. If you find any problems please report them here. (You can purchase an extended technical support plan for $19.95 which will give you exclusive access to our busy call center, where Rajesh, oops, "Roger" will be happy to help you.)
Title: Re: Project: TheBox, a handy little container
Post by: hutch-- on December 31, 2022, 02:49:38 PM
Hi David,

It works great on my Win10 64 Pro.  Looks like a good idea, hope you keep working on it.  :thumbsup:
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on December 31, 2022, 02:56:48 PM

Hi David!

Idea: Get Root and Extension Accessing Technology ... Acronym "GREAT"!  :tongue:
I'm on the porch on my iPad at the moment, but I'll take a look at this program once I'm back inside...  :biggrin:


Welcome back!
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on December 31, 2022, 03:11:35 PM
Quote from: hutch-- on December 31, 2022, 02:49:38 PM
Hi David,

It works great on my Win10 64 Pro.  Looks like a good idea, hope you keep working on it.  :thumbsup:

Thanks, Hutch! You can submit wish-list items to my github. (Just kidding.)

Remember how before Windows 7 you could create folders where each could be set up differently, like a small window just showing icons, instead of having folder settings apply to all folders? That's why I made this, to more or less recreate that functionality that Micro$oft took away from us.
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on December 31, 2022, 03:14:41 PM
Quote from: zedd151 on December 31, 2022, 02:56:48 PM

Idea: Get Root and Extension Accessing Technology ... Acronym "GREAT"!  :tongue:

I want you on my marketing team.
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on December 31, 2022, 03:17:19 PM
Quote from: NoCforMe on December 31, 2022, 03:14:41 PM
I want you on my marketing team.
You have to have a catchy (or memorable) buzzword for advertising purposes.  :tongue: 

edited to add:
Just briefly looked at it. Too cool, a mini File Explorer! (with extras)
I'll play with it at length tomorrow over the weekend.
Title: Re: Project: TheBox, a handy little container
Post by: jj2007 on December 31, 2022, 07:57:14 PM
Excellent :thumbsup:

One minor suggestion: optionally make it a topmost window (invoke CreateWindowExW, WS_EX_TOPMOST, ...), so that the user can more easily drag items from Explorer into it (that's what I do with WinZip, for example)
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on December 31, 2022, 09:54:15 PM
Done; it's a menu item. (I could make it a config item, probably will so it "remembers" how it was previously set. Simple.)

BTW, if anyone wants to do this (keep a window on top or not dynamically), the way to do it is through SetWindowPos() (using the HWND_TOPMOST and HWND_NOTOPMOST flags), not through SetWindowLong(GWL_EXSTYLE) as one would think.
Title: Re: Project: TheBox, a handy little container
Post by: jj2007 on December 31, 2022, 10:39:29 PM
My rather weird experience with the forum watcher (http://masm32.com/board/index.php?topic=9237.0) is that SetWindowPos works when you launch the proggie from Explorer, but not when you launch it from the taskbar. Why that is, no idea, but using the WS_EX_TOPMOST style was the workaround that fixed the problem.
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on December 31, 2022, 11:15:53 PM
Hmm, I just tried running TheBox from the taskbar (actually pinned a shortcut there, not the .exe, but should be the same, right?) and the keep-on-top thing worked fine, can toggle it on or off. Maybe the problem was your specific configuration? (Hah, the old tech-support cop-out: "Have you changed anything on your computer? loaded any new software?")
Title: Re: Project: TheBox, a handy little container
Post by: jj2007 on January 01, 2023, 12:27:56 AM
I know, David. Only this program behaved like that, others work fine.
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on January 01, 2023, 02:13:06 AM
Quote from: jj2007 on December 31, 2022, 10:39:29 PM
My rather weird experience with the forum watcher (http://masm32.com/board/index.php?topic=9237.0) is that SetWindowPos works when you launch the proggie from Explorer, but not when you launch it from the taskbar. Why that is, no idea, but using the WS_EX_TOPMOST style was the workaround that fixed the problem.
Was it 'pinned' to the task bar, or 'minimized' to the task bar? Or even in the 'notification area' of the task bar? I've never had issues with pinning, or minimizing... I guess I'll have to look at forum Watcher to see what the issue could be. Did try different OS? Tech Support: did you try restarting the computer to try to resolve this?  :tongue:  Just kidding...


oops. Sorry David I'll continue this in Jochens forum watcher thread.
Title: Re: Project: TheBox, a handy little container
Post by: HSE on January 01, 2023, 02:28:00 AM
Quote from: NoCforMe on December 31, 2022, 02:42:12 PM
it's basically a folder you can use to store things in and have them in one place.

:thumbsup:

But don't work with *.lnk files´ :biggrin:
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on January 01, 2023, 02:31:33 AM
Quote from: HSE on January 01, 2023, 02:28:00 AM
But don't work with *.lnk files´ :biggrin:
Yes, I had noticed that one too. Should be a not so complicated way to do that? Even if opening the .lnk file to get the path to the actual file. I had never done it but it should be possible??? I might just have to experiment myself with it someday ... if only to see if it can be done easily ...  :cool: 
Title: Re: Project: TheBox, a handy little container
Post by: hutch-- on January 01, 2023, 08:39:51 AM
Something I did test was opening the CFG file and changing the order of the files that had been added through the interface. I think we could talk David into adding some editing capacity to add, remove or change the order. I would not overly worry about the .lnk files, just set up the actual files, not the Explorer .lnk format files.
Title: Re: Project: TheBox, a handy little container
Post by: jj2007 on January 01, 2023, 09:36:51 AM
Quote from: zedd151 on January 01, 2023, 02:31:33 AMEven if opening the .lnk file to get the path to the actual file. I had never done it but it should be possible???

IPersistFile STRUCT
QueryInterface dd ?
AddRef dd ?
Release dd ?
GetClassID dd ?
IsDirty dd ?
Load dd ?
Save dd ?
SaveCompleted dd ?
GetCurFile dd ?
IPersistFile ENDS


GetCurFile (https://learn.microsoft.com/en-us/windows/win32/api/objidl/nf-objidl-ipersistfile-getcurfile)
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 01, 2023, 10:12:18 AM
So Hutch, you hit on exactly what the obvious next step is for this li'l program, the ability to reorder items, ideally by dragging them in the window. Could be done in a clunkier way, say by having a list that you reorder, but dragging would be the best.

This isn't trivial or easy, so I think I'll keep it in mind for a programming push sometime in the near future.

Any other suggestions for features are appreciated.
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 01, 2023, 10:17:39 AM
Quote from: HSE on January 01, 2023, 02:28:00 AM
Quote from: NoCforMe on December 31, 2022, 02:42:12 PM
it's basically a folder you can use to store things in and have them in one place.

:thumbsup:

But don't work with *.lnk files´ :biggrin:

I just tried it with a shortcut; created the shortcut (a .lnk file) in the folder with the app, dragged the shortcut to TheBox, double-clicked it and it opened just fine. Did it not work for you? What happened, nothing?

I tell you, that ShellExecute() is powerful magic. It seems to know how to open anything.
Title: Re: Project: TheBox, a handy little container
Post by: HSE on January 01, 2023, 10:38:13 AM
Quote from: NoCforMe on January 01, 2023, 10:17:39 AM
Did it not work for you?

I will try again next year  :thumbsup:
Title: Re: Project: TheBox, a handy little container
Post by: jj2007 on January 01, 2023, 11:07:24 AM
Quote from: hutch-- on January 01, 2023, 08:39:51 AMwe could talk David into adding some editing capacity to add, remove or change the order

Details view, sorted by date, latest on top? Oh no... that resembles too much an MRU :biggrin:

(http://www.jj2007.eu/pics/MruWithDateTime.png)
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 01, 2023, 11:13:25 AM
Yeah, that might be a wee bit overkill. I did code a Properties dialog (right-click on any item, choose "Properties" from the popup menu).

Hutch, you can delete items from that same menu. I could code a dialog with a list of items and let you pick and delete them there.
Title: Re: Project: TheBox, a handy little container
Post by: daydreamer on January 01, 2023, 10:38:36 PM
Hi David
great :thumbsup:
works on win10
Title: Re: Project: TheBox, a handy little container
Post by: HSE on January 02, 2023, 01:35:57 AM
Quote from: NoCforMe on January 01, 2023, 10:17:39 AM
Did it not work for you?

:thumbsup: Work perfectly.
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 02, 2023, 05:36:27 AM
Quote from: HSE on January 02, 2023, 01:35:57 AM
Quote from: NoCforMe on January 01, 2023, 10:17:39 AM
Did it not work for you?

:thumbsup: Work perfectly.

Wow, it only took you a year to reply!
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on January 02, 2023, 05:39:22 AM
Quote from: NoCforMe on January 02, 2023, 05:36:27 AM
Wow, it only took you a year to reply!
* since last year   :tongue:
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 02, 2023, 05:47:10 AM
Once you try to explain the joke it's no longer funny.
Title: Re: Project: TheBox, a handy little container
Post by: zedd151 on January 02, 2023, 06:05:49 AM
Quote from: NoCforMe on January 02, 2023, 05:47:10 AM
Once you try to explain the joke it's no longer funny.
Yes that is correct; but would have been more accurate and make more sense, the way I corrected it.  :biggrin:  And just as funny.   :tongue:  Sort of like saying on New Years Eve, "I'll quit smoking/drinking or whatever until next year".   :cool: 
To keep this on topic, TheBox works as well on Windows 10 as it did on Windows 7 for me! :thumbsup:
Title: Re: Project: TheBox, a handy little container
Post by: NoCforMe on January 02, 2023, 08:26:26 AM
[nevermind, posted in wrong place]