Window hooking?
Re:
Trying to use Freak's code in 2018 to detect and move an opening window automatically, and even though the hook installs correctly, no windows are captured or shown in the listviewbox. What would be wrong? Yes, I've compiled the first part as a DLL and the main app calls it successfully, and I also tried with my anti-virus disabled.
Re: Window hooking?
Hi Dude,
The following method might provide an alternate solution RegisterShellHookWindow (no DLL required).
NOTE: Microsoft Warning
- I have used this method from Windows XP through Windows 10 without a problem
NB*: Included with the full source code is an executable originally created using PureBasic v5.31.
The following method might provide an alternate solution RegisterShellHookWindow (no DLL required).
NOTE: Microsoft Warning
- I have used this method from Windows XP through Windows 10 without a problem
This was my earliest bit of PureBasic programming. Aside from the "messy code", changes are needed to execute / compile Window Watcher in the latest releases of PureBasic; dependancy no longer supported.Microsoft wrote:[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]
NB*: Included with the full source code is an executable originally created using PureBasic v5.31.
Last edited by JHPJHP on Fri Dec 07, 2018 5:06 am, edited 1 time in total.
Re: Window hooking?
Thanks JHPJHP. In the meantime, does anyone know why Freak's example no longer works?
Re: Window hooking?
Hi Dude,
I know it can be a pain to go through a bunch of script for a few lines of code, so I extracted the relevant bits related to your request.
- Windows Services & Other Stuff:
-- \Other_Stuff\OtherStuff\
--- RegisterShellHookWindow.pb
While performing cursory tests in Windows 10, I observed the following while opening a variety of applications:
- File Explorer moved to the set position before the Window was visible
- UltraEdit moved to the set position after the Window was visible
- Calculator did not respond to the SetWindowPos Function
Replace "File Explorer" in the WindowProc Procedure to suit your needs.
I know it can be a pain to go through a bunch of script for a few lines of code, so I extracted the relevant bits related to your request.
- Windows Services & Other Stuff:
-- \Other_Stuff\OtherStuff\
--- RegisterShellHookWindow.pb
While performing cursory tests in Windows 10, I observed the following while opening a variety of applications:
- File Explorer moved to the set position before the Window was visible
- UltraEdit moved to the set position after the Window was visible
- Calculator did not respond to the SetWindowPos Function
Replace "File Explorer" in the WindowProc Procedure to suit your needs.
Last edited by JHPJHP on Sat Dec 08, 2018 2:25 am, edited 2 times in total.
Re: Window hooking?
Hi, yes that can be true, but I wasn't intending on skipping your code or anything - I did intend to go through it because I ran the exe and I can see it does what I want. But I was also genuinely curious as to why Freak's example no longer works, especially since the hook installed successfully and there were no errors with it. Just the target window did nothing, where it used to in the past. But thanks for saving me the time of sifting through your code.JHPJHP wrote:I know it can be a pain to go through a bunch of script for a few lines of code, so I extracted the relevant bits related to your request.
Semi-related question: in your example above, I see you use this to test the opening of the library:
Code: Select all
user32=OpenLibrary(#PB_Any,"user32.dll")
If IsLibrary(user32)
Code: Select all
user32=OpenLibrary(#PB_Any,"user32.dll")
If user32<>0
Re: Window hooking?
Hi Dude,
- I wonder if it had to do with a 32 / 64 bit process to DLL conflict
Windows Services & Other Stuff:
- \Other_Stuff\OtherStuff\SetWindowsHookEx\
-- SetWindowsHookEx.pb, SetWindowsHookEx_DLL.pb
SetWindowsHookEx.pb:
- if the window you want to effect was created from a 32 bit process, execute this file from PureBasic x86
- if the window you want to effect was created from a 64 bit process, execute this file from PureBasic x64
NB*: RegisterShellHookWindow.pb is not effected by the process the window was created in.
Safer only because it should be future proof, but it's not a result that is likely to change.Dude wrote:Does your version have any advantages over mine, that I may not be aware of? Looks like yours is "safer"?
I decided to write the example by freak from scratch to determine what the problem might be.Dude wrote:... I was also genuinely curious as to why Freak's example no longer works, especially since the hook installed successfully and there were no errors with it.
- I wonder if it had to do with a 32 / 64 bit process to DLL conflict
Windows Services & Other Stuff:
- \Other_Stuff\OtherStuff\SetWindowsHookEx\
-- SetWindowsHookEx.pb, SetWindowsHookEx_DLL.pb
SetWindowsHookEx.pb:
- if the window you want to effect was created from a 32 bit process, execute this file from PureBasic x86
- if the window you want to effect was created from a 64 bit process, execute this file from PureBasic x64
NB*: RegisterShellHookWindow.pb is not effected by the process the window was created in.
Re: Window hooking?
All this 32 vs 64 bit stuff is so annoying. Thanks for helping me out, JHPJHP.