It is currently Thu Jul 18, 2019 8:33 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re:
PostPosted: Thu Dec 06, 2018 1:25 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1893
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Thu Dec 06, 2018 6:15 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
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.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Fri Dec 07, 2018 5:06 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Thu Dec 06, 2018 10:00 pm 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1893
Thanks JHPJHP. :) In the meantime, does anyone know why Freak's example no longer works?


Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Fri Dec 07, 2018 5:31 pm 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
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 will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Last edited by JHPJHP on Sat Dec 08, 2018 2:25 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Sat Dec 08, 2018 12:58 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1893
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"?


Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Sat Dec 08, 2018 2:12 am 
Offline
Addict
Addict
User avatar

Joined: Sat Oct 09, 2010 3:47 am
Posts: 1572
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.

_________________

I will be unreachable from the forum for an indefinite period; downloads moved to My PureBasic Stuff.
_________________


Top
 Profile  
Reply with quote  
 Post subject: Re: Window hooking?
PostPosted: Sat Dec 08, 2018 3:53 am 
Offline
Addict
Addict

Joined: Mon Feb 16, 2015 2:49 pm
Posts: 1893
All this 32 vs 64 bit stuff is so annoying. :evil: Thanks for helping me out, JHPJHP. :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye