WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: pguild on September 23, 2019, 12:01:49 PM

Title: Finding and Activating Unsaved NotePad Windows
Post by: pguild 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)


Title: Re: Finding and Activating Unsaved NotePad Windows
Post by: td 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.
Title: Re: Finding and Activating Unsaved NotePad Windows
Post by: snowsnowsnow 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.
Title: Re: Finding and Activating Unsaved NotePad Windows
Post by: td 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".
Title: Re: Finding and Activating Unsaved NotePad Windows
Post by: 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.

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.

Title: Re: Finding and Activating Unsaved NotePad Windows
Post by: td on September 25, 2019, 10:42:15 PM
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.