News:

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

Main Menu

Project: TheBox, a handy little container

Started by NoCforMe, December 31, 2022, 02:42:12 PM

Previous topic - Next topic

NoCforMe

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:

  • An icon browser, which is an interesting project in itself (see below)
  • An improved configuration file parser
  • Drag-n-drop capability to add items
  • A (hopefully) simple, intuitive, easy-to-get-around-in user interface

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 current window size and position
  • The background colors to use (unselected background and selected)
  • The font and font size for caption text
  • The items

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.)
Assembly language programming should be fun. That's why I do it.

hutch--

Hi David,

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

zedd151


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!

NoCforMe

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.
Assembly language programming should be fun. That's why I do it.

NoCforMe

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.
Assembly language programming should be fun. That's why I do it.

zedd151

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.

jj2007

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)

NoCforMe

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.
Assembly language programming should be fun. That's why I do it.

jj2007

My rather weird experience with the forum watcher 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.

NoCforMe

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?")
Assembly language programming should be fun. That's why I do it.

jj2007

I know, David. Only this program behaved like that, others work fine.

zedd151

Quote from: jj2007 on December 31, 2022, 10:39:29 PM
My rather weird experience with the forum watcher 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.

HSE

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:
Equations in Assembly: SmplMath

zedd151

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: 

hutch--

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.