WinGetActive Redux

Started by George Vagenas, June 21, 2014, 02:16:17 AM

Previous topic - Next topic

George Vagenas

Back in April I had a problem with a FileMenu script which I posted here, http://forum.winbatch.com/index.php?topic=905.msg3815#msg3815, recently I had the same problem reoccur so I tried to fix it in the same way by running a script from the Explore context menu rather than have the code in line or as a called procedure.  Problem is that it did not work and WinGetActive() returned "Processing..."

Believe me, I am aware that my coding skills have atrophied but this result did not sit right with me, as it goes against my prior experience in using WinBatch scripts with Explorer and Explorer extentions, namely "PowerDesk" and "Directory Opus".  So as a test I ran the same code in Windows XP and it executed as I thought it should.  Not only that, but while still running XP, I modified "FileMenu for all filetypes.mnw" and entered the code inline as an item in the menu and it returned the title of the "Directory Opus" window.
Code (winbatch) Select
      trgDir = wingetactive()
      Cnts = itemcount(trgDir, '\')
      if Cnts==1
         display(5, 'Can''t Gather Vids to Root!', 'Try a different folder.')
      endif
     
      Trg = itemextract(Cnts, trgDir, '\')
      dirchange('..')


I don't have any files which I can run the original script against but I suspect that it too would now fail.  I exported the inline code to a script and tested it in WinBatch, it worked as expected.  But now it makes no difference if I run or call the script from FileMenu, trgDir is returned as "Processing..."

Beyond getting my script to work I think WinGetActive() should work the same whether I'm using a FileMenu script in XP or Windows 7 but it doesn't.  The active window is the Explorer window from which the script is invoked not the script invoked from the context menu or the context menu itself.  Please fix this.

Thanks

George

td

There are a few holes in your description of the problem but assuming I have filled the missing parts with the correct assumptions, I don't believe there is a 'fix' for your problem.  Your issue  has to do with the bitness of the OS and they way FileMenu works on 64-bit systems.   The WinGetActive is accurately retuning the active window text.  It is just that the active window isn't the same for 64-bit FileMenu.

There are likely different WinBatch functions you can use to get to the same end in your menu script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Deana

It appears to be the subtly in difference between an active window and a window with focus. I have found the cGetFocus can be used in this instance. Once you get the window with focus you can get that parents owner handle to get the title. This seems to work for me on Windows 7 from FileMenu:

Code (winbatch) Select
_Get Active Window Name From Filemenu
      ; Load Appropriate Extender
      AddExtender("wwctl44i.dll",0,"wwctl64i.dll")
      hwndFocus = cGetFocus()
      owner =  cWndInfo(hwndFocus,9)
      thistext = cWndInfo(owner,0)
      Pause('cGetFocus Focused Window',thistext)   

Deana F.
Technical Support
Wilson WindowWare Inc.

td

The active windows is the window at the top of the display z-order.  The focus window is the window currently receiving user input.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

I need to back track a bit on the last post.  The active windows does not necessarily have to be on top of the z-order, although it almost always is.   It is defined as the window that the user is currently working with.  The focus window is defined as the window with the keyboard input. 

The point is more or less moot with regard to FileMenu 64-bit.  WinGetActive and cGetFocus are returning the same window.  The difference is that cGetFocus is returning a window handle that can be passed to cWndInfo to obtain the window's owner window.  Because FileMenu is a shell extension, that owner window is the current running shell's app window.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

Here is another way to get the shell window's caption which is also the caption of the window the was returned by WinGetActive() of the old 32-bit FileMenu:
Code (winbatch) Select

_Get Active Window Name From Filemenu
        strCaption = WinName()
        Message("Shell Window Caption", strCaption)
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

George Vagenas

Tony thanks, a direct result.
Thanks

George