Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

ControlFocus not working?


  • Please log in to reply
9 replies to this topic
kli6891
  • Members
  • 46 posts
  • Last active: Nov 24 2012 08:12 PM
  • Joined: 01 Aug 2009
I ran this code while on an open explorer window, with the expectation that the message box should say "edit1", but it reported "DirectUIHWND3" instead.

controlfocus, Edit1, ahk_class CabinetWClass
controlgetfocus, output, ahk_class CabinetWClass
msgbox %output%

What's odd is that if I manually activate the location bar first (Edit1 is the location bar), the script will work, even after the location bar loses focus.

So basically, the script works some of the time, but that's good enough :D

I'm running Win7.


Help/enlightenment, anyone?

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
I'll peek next time I'm on my Win7 system.

aaffe
  • Members
  • 1045 posts
  • Last active: Jan 16 2014 01:32 PM
  • Joined: 17 May 2007
For me this one works. I have to start the script directly out of explorer.
I dont know why sometimes it is CabinetWClass, other times ExploreWClass...
controlfocus, Edit1, ahk_class ExploreWClass
controlgetfocus, output, ahk_class ExploreWClass
msgbox %output%


kli6891
  • Members
  • 46 posts
  • Last active: Nov 24 2012 08:12 PM
  • Joined: 01 Aug 2009

For me this one works. I have to start the script directly out of explorer.
I dont know why sometimes it is CabinetWClass, other times ExploreWClass...

controlfocus, Edit1, ahk_class ExploreWClass
controlgetfocus, output, ahk_class ExploreWClass
msgbox %output%


Unfortunately, that doesn't work either. Message box shows nothing :(

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
is the script (or target program) running as admin?

a non-admin script can't interact with an admin program

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

I dont know why sometimes it is CabinetWClass, other times ExploreWClass...


It has to do with Microsoft's distinction between a directory being explored(ExploreWClass) and being opened(CabinetWClass). I practically tore my hair out for about a month while I was trying to figure out why I couldn't use my hotkeys consistently to sort my music files in a certain directory because the class of the window would change between those two even though the title stayed the same.

Here's an example (albeit shaky). If you create a new My Computer window using Win+E, that is really a command to explore My Computer, thus the window will be ExploreWClass. However if you were to use the AHK command to create a new My Computer window:

Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d}

That is a command to open My Computer, so the window will instead be CabinetWClass.

Now if you want things to get really funky, use Win+E to "explore" My Computer, check the class: ExploreWClass. Then right-click a drive/folder and select Open. Check the class again: CabinetWClass! Right-click a folder inside of there and select Explore, it becomes ExploreWClass again!

Why this distinction was necessary, I don't know, but that's pretty much why you'll see some windows as ExploreWClass and others as CabinetWClass.

kli6891
  • Members
  • 46 posts
  • Last active: Nov 24 2012 08:12 PM
  • Joined: 01 Aug 2009

is the script (or target program) running as admin?

a non-admin script can't interact with an admin program


I just ran it in admin mode (by compiling and running the exe with admin privileges), and the result is the same. :(

EDIT:

Something just occurred to me, which may be a solution.

I'm running a 64-bit edition of windows, and according to the page on MSDN about WOW64,

The system isolates 32-bit applications from 64-bit applications, which includes preventing file and registry collisions.


Perhaps this has something to do with it?

I dont know why sometimes it is CabinetWClass, other times ExploreWClass...


It has to do with Microsoft's distinction between a directory being explored(ExploreWClass) and being opened(CabinetWClass). I practically tore my hair out for about a month while I was trying to figure out why I couldn't use my hotkeys consistently to sort my music files in a certain directory because the class of the window would change between those two even though the title stayed the same.

Here's an example (albeit shaky). If you create a new My Computer window using Win+E, that is really a command to explore My Computer, thus the window will be ExploreWClass. However if you were to use the AHK command to create a new My Computer window:

Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d}

That is a command to open My Computer, so the window will instead be CabinetWClass.

Now if you want things to get really funky, use Win+E to "explore" My Computer, check the class: ExploreWClass. Then right-click a drive/folder and select Open. Check the class again: CabinetWClass! Right-click a folder inside of there and select Explore, it becomes ExploreWClass again!

Why this distinction was necessary, I don't know, but that's pretty much why you'll see some windows as ExploreWClass and others as CabinetWClass.


I just pressed win+e, but window spy still shows CabinetWClass. Perhaps MS changed something in Windows 7?

sinkfaze
  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

I just pressed win+e, but window spy still shows CabinetWClass. Perhaps MS changed something in Windows 7?


Could be, I did fail to mention that I was using Windows XP.

aaffe
  • Members
  • 1045 posts
  • Last active: Jan 16 2014 01:32 PM
  • Joined: 17 May 2007
Thanks sinkfaze for your detailled explanation.

I dont know why sometimes it is CabinetWClass, other times ExploreWClass...


It has to do with Microsoft's distinction between a directory being explored(ExploreWClass) and being opened(CabinetWClass). I practically tore my hair out for about a month while I was trying to figure out why I couldn't use my hotkeys consistently to sort my music files in a certain directory because the class of the window would change between those two even though the title stayed the same.

Here's an example (albeit shaky). If you create a new My Computer window using Win+E, that is really a command to explore My Computer, thus the window will be ExploreWClass. However if you were to use the AHK command to create a new My Computer window:

Run ::{20d04fe0-3aea-1069-a2d8-08002b30309d}

That is a command to open My Computer, so the window will instead be CabinetWClass.

Now if you want things to get really funky, use Win+E to "explore" My Computer, check the class: ExploreWClass. Then right-click a drive/folder and select Open. Check the class again: CabinetWClass! Right-click a folder inside of there and select Explore, it becomes ExploreWClass again!

Why this distinction was necessary, I don't know, but that's pretty much why you'll see some windows as ExploreWClass and others as CabinetWClass.



kli6891
  • Members
  • 46 posts
  • Last active: Nov 24 2012 08:12 PM
  • Joined: 01 Aug 2009
Ok, I investigated further, and found this:


(I got this code from PhiLho, here, and modified it a bit:


F12::
WinGetClass explorerClass, A
ControlGetText currentPath, Edit1, ahk_class %explorerClass%
msgbox %currentPath%
return


When I press F12 on an open explorer window, if the location bar has been previously activated, it correctly shows the path. If I then switch to another location, and press F12 again, the path shown is the still the previous folder's path. Now, if I activate the location bar again, the path shown by F12 is now correct.


Thoughts on what the problem is?
Thanks.