PureBasic Forum
http://forums.purebasic.com/english/

Window hooking?
http://forums.purebasic.com/english/viewtopic.php?f=13&t=13850
Page 2 of 2

Author:  Dude [ Thu Dec 06, 2018 1:25 pm ]
Post subject:  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.

Author:  JHPJHP [ Thu Dec 06, 2018 6:15 pm ]
Post subject:  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
Microsoft wrote:
[This function is not intended for general use. It may be altered or unavailable in subsequent versions of Windows.]

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.

NB*: Included with the full source code is an executable originally created using PureBasic v5.31.

Author:  Dude [ Thu Dec 06, 2018 10:00 pm ]
Post subject:  Re: Window hooking?

Thanks JHPJHP. :) In the meantime, does anyone know why Freak's example no longer works?

Author:  JHPJHP [ Fri Dec 07, 2018 5:31 pm ]
Post subject:  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.

Author:  Dude [ Sat Dec 08, 2018 12:58 am ]
Post subject:  Re: Window hooking?

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.

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. ;)

Semi-related question: in your example above, I see you use this to test the opening of the library:

Code:
user32=OpenLibrary(#PB_Any,"user32.dll")
If IsLibrary(user32)

However, I've always done it like this:

Code:
user32=OpenLibrary(#PB_Any,"user32.dll")
If user32<>0

Does your version have any advantages over mine, that I may not be aware of? Looks like yours is "safer"?

Author:  JHPJHP [ Sat Dec 08, 2018 2:12 am ]
Post subject:  Re: Window hooking?

Hi Dude,

Dude wrote:
Does your version have any advantages over mine, that I may not be aware of? Looks like yours is "safer"?

Safer only because it should be future proof, but it's not a result that is likely to change.

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 decided to write the example by freak from scratch to determine what the problem might be.
- 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.

Author:  Dude [ Sat Dec 08, 2018 3:53 am ]
Post subject:  Re: Window hooking?

All this 32 vs 64 bit stuff is so annoying. :evil: Thanks for helping me out, JHPJHP. :)

Page 2 of 2 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/