Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Task Create/Switch Events Plugin problem and solution

Found a bug in EventGhost? Report it here.
Post Reply
EvilMF
Posts: 4
Joined: Sat Dec 07, 2013 5:24 pm

Task Create/Switch Events Plugin problem and solution

Post by EvilMF »

I use PotPlayer as my primary video player, and I recently downloaded EventGhost and tried to make these two apps work together.
However, I encountered one problem: when PotPlayer window gets focus, Task Create/Switch Events Plugin doesn't report corresponding Activated event.
As a result, it is very inconvenient to use this player with EventGhost (I tried to use Process.Created event instead, but it only works once and doesn't help if the already launched app becomes active).
So, I took a look at the plugin source code, and I found that the problem is inside CheckWindow function.
The call of GetWindowLong(hwnd, GWL_HWNDPARENT) for main PotPlayer window returns a handle, so the function returns and no event is generated.

I believe that the purpose of this code is to prevent event generation for child windows (or am I missing something here?).
In that case, the code should be corrected a bit.
GetWindowLong(GWL_HWNDPARENT) does the same as GetParent function.
From GetParent description:
"If the window is a child window, the return value is a handle to the parent window.
If the window is a top-level window with the WS_POPUP style, the return value is a handle to the owner window."
Main PotPlayer window has WS_POPUP/WS_OVERLAPPED style and is owned by another WS_POPUP/WS_OVERLAPPED window with zero size (found this with Winspector; probably a strange window hierarchy).
So, main window doesn't have a parent (to be more precise, it has desktop window as a parent), but it has an owner.
The right way would be to change GetParent (which returns also the owner) to GetAncestor, as suggested in MSDN:
"To obtain the parent window and not the owner, instead of using GetParent, use GetAncestor with the GA_PARENT flag"

I changed the code in the following way:

def __start__(self, *dummyArgs):
...
self.desktop = GetDesktopWindow()

def CheckWindow(self, hwnd):
...
parent = GetAncestor(hwnd, GA_PARENT)
if parent and parent != self.desktop:
return

And everything works fine - Activated/Deactivated events for PotPlayer are generated.
Updated plugin is attached.
I haven't found any side effects with this fix, but I'm not 100% sure it is OK.
Would be glad to see some comments from the creator of this plugin.
Attachments
Task.zip
(2.77 KiB) Downloaded 337 times
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Task Create/Switch Events Plugin problem and solution

Post by Pako »

EvilMF wrote:Would be glad to see some comments from the creator of this plugin.
I am afraid that you will not get it.
Mr. Bitmonster (author of the plugin and also the program EventGhost) completely left the project and he is not involved here at all.
If someone else does not take up with it, so I might check it out sometime (when I have time).

Note: I've never needed this plugin and I do not use it. Better would be someone who uses it.

Pako
Tryanderror
Posts: 10
Joined: Wed Jun 08, 2011 8:48 pm

Re: Task Create/Switch Events Plugin problem and solution

Post by Tryanderror »

Great! Thanks a lot EvilMF. :D

I tried your modified plugin today and it works as expected. This is finally the solution for my (maybe misplaced) post here: viewtopic.php?f=2&t=3599&p=21576#p21576

Best wishes
Tryanderror
Post Reply