Finding and Activating Unsaved NotePad Windows

Started by pguild, September 23, 2019, 12:01:49 PM

Previous topic - Next topic

pguild

This is more of a heads up than a question.
If the user has opened a notepad file, the Window name will (at first) be the same as the filename.
If the user minimizes the file (without editing it), you can use Winbatch to activate it and bring it back to its last visible location.

   if winexist(NotePadFilename) ;if window already open
      BEEP()
      winactivate(NotePadFilename) ;activate it
  endif

However, if the user has edited the file, Windows prefixes "*" to the window name and the above
code will not work!  However, if you also check for the filename with * prefixed to it, then
the window can be found and activated.  8)


www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

td

If you use a partial-window-name, you don't have to worry about an application changing part of the title. See  "Home -> Windows Interface Language Reference -> Things to Know -> Partial Window Names" in the Consolidated WIL Help file for a better explanation than I could give here if you are unfamiliar with the term.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

snowsnowsnow

A good general technique is to use Window IDs instead of Window names, whenever possible.

The general idea is that you use the function WinIdGet() to get a window ID for the window, before anyone (or anything) has had a chance to change the window title.  After that, you can use the ID in (just about) any WinBatch function, rather than relying on the title having not been changed.

td

Good point and funny you should mention that.  The next version WinBatch+Compiler has some enhancement that expands the usefulness of "WinIds".
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pguild

Thanks for your replies.

If the name starts with *winbatch and I tell the system to look for winbatch, will it find it?  I don't think so. The first part of the window name must match and *winbatch does not match winbatch.

An advantage of searching for *winbatch is that I can alert the user that the file is open but not saved.
I could also ask the user "Do you want to open the saved version of the file or already opened but not saved file.

I don't think using a window ID will work in my case unless I store the ID somewhere each time I open the window.
It's easier just to search for the window name with * prefixed to it.

www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

td

Quote from: pguild on September 25, 2019, 08:38:09 PM
Thanks for your replies.

If the name starts with *winbatch and I tell the system to look for winbatch, will it find it?  I don't think so. The first part of the window name must match and *winbatch does not match winbatch.

Using a partial window name would allow a function to match "*winbatch".  You apparently didn't look at the discussion on partial window names in the Consolidated WIL Help file.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade