1 |
/* PTD.cpp - Privacy Tray Dynamic |
/* PTD.cpp - Privacy Tray Dynamic |
2 |
* Copyright (C) 2002-2009 Timo Schulz |
* Copyright (C) 2002-2009, 2012 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
20 |
#include <windows.h> |
#include <windows.h> |
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
|
|
23 |
|
/* Reference to the DLL module handle */ |
24 |
HINSTANCE glob_hinst; |
HINSTANCE glob_hinst; |
25 |
|
|
26 |
/* We need a special section in the DLL for storing our shared data. |
/* We need a special section in the DLL for storing our shared data. |
46 |
#endif |
#endif |
47 |
#undef ATTR_SEC |
#undef ATTR_SEC |
48 |
|
|
49 |
|
/* Static variables that are used to record and replay key strokes */ |
50 |
static unsigned *journ_keys = 0; |
static unsigned *journ_keys = 0; |
51 |
static unsigned keyidx = 0; |
static unsigned keyidx = 0; |
52 |
static unsigned nkeys = 0; |
static unsigned nkeys = 0; |
53 |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
54 |
|
|
55 |
|
|
56 |
|
/* Callback function for the Computer Based Training (CBT) hook */ |
57 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
58 |
PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam) |
PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam) |
59 |
{ |
{ |
60 |
HWND curr_hwnd = NULL; |
HWND curr_hwnd; |
61 |
DWORD proc_id = 0; |
DWORD proc_id; |
62 |
|
|
63 |
if (code >= 0 && code == HCBT_SETFOCUS) { |
if (code >= 0 && code == HCBT_SETFOCUS) { |
64 |
/* A window is about to receive the keyboard focus */ |
/* A window is about to receive the keyboard focus */ |
65 |
|
|
66 |
|
proc_id = 0; |
67 |
curr_hwnd = (HWND)wparam; |
curr_hwnd = (HWND)wparam; |
68 |
GetWindowThreadProcessId (curr_hwnd, &proc_id); |
GetWindowThreadProcessId (curr_hwnd, &proc_id); |
69 |
/* Only if the current window is different from this window list, |
/* Only if the current window is different from this window list, |
70 |
we set the new focus. For more information read the hint in |
we set the new focus. For more information read the hint in |
71 |
PTD_initialize. */ |
PTD_initialize. */ |
72 |
if ((proc_id != tray_proc_id) |
if ((proc_id != tray_proc_id) && |
73 |
&& (curr_hwnd != NULL) |
(curr_hwnd != NULL) && |
74 |
&& (curr_hwnd != curr_focus) |
(curr_hwnd != curr_focus) && |
75 |
&& (curr_hwnd != shell_traywnd) |
(curr_hwnd != shell_traywnd) && |
76 |
&& (curr_hwnd != systab_c32) |
(curr_hwnd != systab_c32) && |
77 |
&& (curr_hwnd != mstask_swc) |
(curr_hwnd != mstask_swc) && |
78 |
&& (curr_hwnd != rebar_w32)) { |
(curr_hwnd != rebar_w32)) { |
79 |
curr_focus = curr_hwnd; |
curr_focus = curr_hwnd; |
80 |
} |
} |
81 |
} |
} |
104 |
/* Okay, what are we doing here: |
/* Okay, what are we doing here: |
105 |
* In the past I used the Spy++ application to find out why the old current |
* In the past I used the Spy++ application to find out why the old current |
106 |
* window doesn't work on so much systems. Now we try to use the computer |
* window doesn't work on so much systems. Now we try to use the computer |
107 |
* based training hook, more precise the HCBT_SETFOCUS to find out the |
* based training hook, more precisely the HCBT_SETFOCUS to find out the |
108 |
* last window focus. But to succeed we need to ignore some windows |
* last window focus. But to succeed we need to ignore some windows |
109 |
* because otherwise our own window or a window from the taskbar |
* because otherwise our own window or a window from the taskbar |
110 |
* would be recognized. |
* would be recognized. |
124 |
rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL); |
rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL); |
125 |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
126 |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
127 |
|
|
|
/*debug ("tray_proc_id=%u cbt_hook=%p shell_traywnd=%p rebar_w32=%p " |
|
|
"mstask_swc=%p systab_c32=%p", |
|
|
tray_proc_id, cbt_hook, shell_traywnd, rebar_w32, |
|
|
mstask_swc, systab_c32);*/ |
|
|
|
|
128 |
return TRUE; |
return TRUE; |
129 |
} |
} |
130 |
|
|
243 |
{ |
{ |
244 |
switch (reason) { |
switch (reason) { |
245 |
case DLL_PROCESS_ATTACH: |
case DLL_PROCESS_ATTACH: |
|
/* Handle to the attached process */ |
|
246 |
glob_hinst = hinst; |
glob_hinst = hinst; |
247 |
break; |
break; |
248 |
|
|