Page 1 of 1

Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items)  Topic is solved

Posted: 31 Jan 2017, 09:43
by jeeswg
Windows 7: invert selection and set details/list view programmatically

Code: Select all

q::
ControlGet, hCtl, Hwnd,, SHELLDLL_DefView1, A

PostMessage, 0x111, 28706, 0,, % "ahk_id " hCtl ;edit, invert selection
PostMessage, 0x111, 28747, 0,, % "ahk_id " hCtl ;view, details
PostMessage, 0x111, 28753, 0,, % "ahk_id " hCtl ;view, list
PostMessage, 0x111, 28705, 0,, % "ahk_id " hCtl ;edit, select all
PostMessage, 0x111, 31492, 0,, % "ahk_id " hCtl ;view, sort by, name
return
Internet Explorer 11: save as

Code: Select all

;seems to work on both control types
;change NN in TabWindowClassNN / Shell DocObject ViewNN to refer to other tabs
q::
ControlGet, hCtl, Hwnd,, TabWindowClass1, A
ControlGet, hCtl, Hwnd,, Shell DocObject View1, A

PostMessage, 0x111, 258, 0,, % "ahk_id " hCtl ;file, save as...
return
Well that's what happens when you never ever give up.

Useful link:
[huge ToolTip appears showing menu item IDs for context menu]
Get Info from Context Menu - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/1975 ... text-menu/

Btw if there is a window spy that can work on a context menu,
that would be really useful, the spies I came across,
need you to drag cross hairs onto the context menu, but that makes the menu disappear.

Re: Windows 7 - invert selection, set details view/list view (Explorer/Internet Explorer PostMessage/SendMessage)

Posted: 31 Jan 2017, 17:16
by jeeswg
Are there any obstacles stopping a PostMessage/SendMessage 32-bit/64-bit spy/detector
program being written in AutoHotkey?

Re: Windows 7 - invert selection, set details view/list view (Explorer/Internet Explorer PostMessage/SendMessage)

Posted: 31 Jan 2017, 17:56
by qwerty12
jeeswg wrote:Are there any obstacles stopping a PostMessage/SendMessage 32-bit/64-bit spy/detector
program being written in AutoHotkey?
Inaccuracies abound, so you'll want a second opinion, but this is the way I see it in theory:

If you mean something like Spy++, kinda. I think Spy++ works by using a WH_CALLWNDPROC hook inside the target process. When the hook procedure is in a DLL, SetWindowsHookEx handles the injection of the DLL into the target process and all works well.

Now, there is a DLL version of AutoHotkey by HotkeyIt, so I don't think it's impossible, but just harder. I would use a host script with InjectAhkDll to inject AutoHotkey_H into the process (SetWindowsHookEx would be out because any function written inside a script loaded by AutoHotkey_H.dll wouldn't actually belong to the DLL proper), load a script that calls SetWindowsHookEx once inside the script and then find a suitable form of IPC to relay the results back to your host...

Re: Windows 7 - invert selection, set details view/list view (Explorer/Internet Explorer PostMessage/SendMessage)

Posted: 01 Feb 2017, 13:09
by jeeswg
Thanks, this is a really good response.

Re: Windows 7 - invert selection, set details view/list view (Explorer/Internet Explorer PostMessage/SendMessage)

Posted: 20 Jun 2017, 09:29
by sancarn
qwerty12 wrote:Now, there is a DLL version of AutoHotkey by HotkeyIt, so I don't think it's impossible, but just harder. I would use a host script with InjectAhkDll to inject AutoHotkey_H into the process (SetWindowsHookEx would be out because any function written inside a script loaded by AutoHotkey_H.dll wouldn't actually belong to the DLL proper), load a script that calls SetWindowsHookEx once inside the script and then find a suitable form of IPC to relay the results back to your host...
From my own research it seems like you will need to write an own C++ based dll to get this working. I don't think injecting any old DLL into a process will do anything. I think that perhaps one of the best ways to do it would be to send a copy of all messages to a named pipe. AHK can hook onto changes in the pipe fairly easily I'd assume. One would just need that DLL to initiate the process. Another more complicated setup would be to raise COM Events for each hook. It would be significantly more powerful as you could easily filter out the messages you want to see.

@jeeswg did you by any chance figure out how to achieve this?

Re: Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items)

Posted: 20 Jun 2017, 09:47
by jeeswg
I haven't tried to write a window spy to receive messages in AHK yet. But I did once use AutoHotkey_H to inject an AHK dll (AutoHotkeyMini.dll) into Notepad to set the colour of the Edit control. Setting the colour involved receiving messages, so perhaps that's an approach you could try.

Re: Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items)

Posted: 20 Jun 2017, 10:12
by sancarn
I too just used Autohotkey_L to inject the AHKMini dlll into notepad (just following Hotkeyit's example linked by qwerty12). It doesn't surprise me that AHK.dll was running code but it surprised me that Hotkeyit has implemented a way to get at the injected object! Crazy stuff!

For the above did you just use a OnMessage() function to call a function to send messages back to the notepad control?

Re: Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items)

Posted: 20 Jun 2017, 10:25
by jeeswg
Not OnMessage, I used: RegisterCallback function and SetWindowLong via DllCall. I would suppose that AHK sets up each GUI window/control it makes to work with OnMessage, so RegisterCallback would be necessary for windows/controls that AHK didn't itself make. Haha it is pretty crazy.

Re: Windows 7 - invert selection, set details view/list view (trigger Explorer/Internet Explorer menu items)

Posted: 20 Jun 2017, 11:32
by sancarn
jeeswg wrote:Not OnMessage, I used: RegisterCallback function and SetWindowLong via DllCall. I would suppose that AHK sets up each GUI window/control it makes to work with OnMessage, so RegisterCallback would be necessary for windows/controls that AHK didn't itself make. Haha it is pretty crazy.
Hmmm I guess SetWindowLong only has permission to run, if it is called on the same process which the caller belongs to... Because I also tried to use SetWindowLong from AHK_L directly on another program and got access denied no matter which way I tried.

Will definitely try this! It may even be good as a general 'library' for getting messages from other processes...

Re: Windows 7 - invert selection, set details view/list view (Explorer/Internet Explorer PostMessage/SendMessage)

Posted: 23 Aug 2017, 16:38
by jeeswg
sancarn wrote:@jeeswg did you by any chance figure out how to achieve this?
I've posted a prototype window spy here:
how to dll Inject - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 82#p166682

That's as far as I wanted to go with working on a window spy, although currently it has some problems to do with crashing when you want to either close the target program or close AutoHotkey.