viewpoint-particle

Author Topic: Finding and Activating Unsaved NotePad Windows  (Read 108 times)

pguild

  • Newbie
  • *
  • Posts: 29
Finding and Activating Unsaved NotePad Windows
« on: September 23, 2019, 12:01:49 pm »
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)



td

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: Finding and Activating Unsaved NotePad Windows
« Reply #1 on: September 24, 2019, 09:30:22 am »
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

  • Sr. Member
  • ****
  • Posts: 276
Re: Finding and Activating Unsaved NotePad Windows
« Reply #2 on: September 25, 2019, 12:08:11 pm »
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

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: Finding and Activating Unsaved NotePad Windows
« Reply #3 on: September 25, 2019, 07:40:23 pm »
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

  • Newbie
  • *
  • Posts: 29
Re: Finding and Activating Unsaved NotePad Windows
« Reply #4 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.

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.


td

  • Tech Support
  • *****
  • Posts: 3103
    • WinBatch
Re: Finding and Activating Unsaved NotePad Windows
« Reply #5 on: September 25, 2019, 10:42:15 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