A Little Gotcha

Started by George Vagenas, September 10, 2014, 04:56:34 PM

Previous topic - Next topic

George Vagenas

Add this item to popmenu.mnw
Code (winbatch) Select
;__________________________________________________________________________________________
Tilde Test
      Test = wingetactive()
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
     
      winiconize(Test)
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
      winactivate(Test)



Now run this code to create the test folders
Code (winbatch) Select
   dirchange('C:\')
   Cnts = ''
   Cnt = 0
   while direxist('F00ey' : Cnts)
      Cnts = Cnt+1
      Cnt = Cnt+1
   endwhile
   F00ey = 'F00ey' : Cnts
   dirmake(F00ey)
   dirchange(F00ey)
   dirmake('Test!')
   dirmake('Test~')
   run('Explorer.exe', '"C:\' : F00ey : '"')

   return


Or if you don't like running test scripts then create the following test folders:
C:\F00ey
C:\F00ey\Test!
C:\F00ey\Test~
Now start Explorer, navigate to "C:\F00ey\Test!" and select Tilde Test from popmenu, runs as expected.  Navigate to "C:\F00ey\Test~", repeat Tilde Test and the script errors out with "1041: WinIconze: Window not found"
Thanks

George

....IFICantBYTE

The ~ tilde means it must match a window title of EXACTLY "Test" to iconize, nothing else as far as I understand it, so if it had any other characters before or after "Test", including an actual tilde in the title, then it won't match, wont find it, and will give you that error.

Sorry if I'm wrong and don't understand what you are asking.. I didn't actually try your example as I don't use popmenu
Regards,
....IFICantBYTE

Nothing sucks more than that moment during an argument when you realize you're wrong. :)

George Vagenas

Yes! that's the Gotcha, WinBatch is treating a string variable that contains a tilde the same as a literal string.  Try this script in Studio.
Code (winbatch) Select
   windowontop('', 1)
   dirchange('C:\')
   Cnts = ''
   Cnt = 0
   while direxist('F00ey' : Cnts)
      Cnts = Cnt+1
      Cnt = Cnt+1
   endwhile
   F00ey = 'F00ey' : Cnts
   dirmake(F00ey)
   dirchange(F00ey)
   dirmake('Test!')
   dirmake('Test~')
   Chk = 'C:\' : F00ey : '\Test~'
   run('Explorer.exe', '"' : Chk : '"')
   
   if direxist(Chk) then pause(`DEBUG PAUSE`, 'Folder "' : Chk : '" exists!')
   if winexist(Chk) then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!')
      else pause(`DEBUG PAUSE`, 'Window "' : Chk : '" does not exist!')

:cancel   
   return

How would you check for the existence of a window that has a tilde in its title?  If you run the code in Studio you'll have an Explorer window with the title "C:\F00ey\Test~" which Winbatch says doesn't exist.  Winbatch is treating this line:
Code (winbatch) Select
if winexist(Chk) then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!')
The same as this line:
Code (winbatch) Select
if winexist("C:\F00ey\Test~") then pause(`DEBUG PAUSE`, 'Window "' : Chk : '" exists!') and it shouldn't.
Thanks

George

td

In this case you add a tilde...
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

And which case would that be, the first example or my reply to IFICANTBYTE?  What you seem to be saying is that the script needs to anticipate the possibility that a window's title ends with a tilde? (the only situation that causes a problem)  Maybe the help topic for "partial window names" should be updated to indicate the need for special handling of window titles ending with a tilde.
In my situation where the script is running on my own system its an easy fix and I can modify the actual code to deal with it.  If I actually had a Tilde Test popmenu.mnw item it would now look like this:
Code (winbatch) Select
;__________________________________________________________________________________________
Tilde Test
      Test = wingetactive()
      if strindex(Test, '~', 0, @backscan)==strlen(Test) then Test = Test:'~'
      winiconize(Test)
      pause(`DEBUG PAUSE`, strCat(`Test = `, Test))   ;***DEBUG LINE***
      winactivate(Test)
Thanks

George

td

Or in the case where an end match isn't needed or wanted then just strip off the tilde.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade