1 |
/* PTD.cpp - Privacy Tray Dynamic |
/* PTD.cpp - Privacy Tray Dynamic |
2 |
* Copyright (C) 2002-2005 Timo Schulz |
* Copyright (C) 2002-2009 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
|
* |
|
|
* You should have received a copy of the GNU General Public License |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
15 |
*/ |
*/ |
|
|
|
16 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
17 |
#include <config.h> |
#include <config.h> |
18 |
#endif |
#endif |
19 |
|
|
20 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
21 |
#include <stdio.h> |
#include <stdio.h> |
|
#include <ocidl.h> |
|
|
#include <olectl.h> |
|
|
|
|
|
#include "wptJPG.h" |
|
22 |
|
|
23 |
HINSTANCE glob_hinst; |
HINSTANCE glob_hinst; |
24 |
|
|
25 |
/* 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. |
26 |
|
This shared data is required by the hook function because that |
27 |
|
function is called in the context of the actual thread running the |
28 |
|
hook and thus we need a way to communicate the result of our hook |
29 |
|
function back to us. We use a shared data segment for this. */ |
30 |
|
#ifdef __GNUC__ |
31 |
|
#define ATTR_SEC __attribute__((section (".SHARDAT"), shared)) |
32 |
|
#else |
33 |
|
#define ATTR_SEC |
34 |
#pragma data_seg(".SHARDAT") |
#pragma data_seg(".SHARDAT") |
35 |
static HHOOK cbt_hook = NULL; /* CTB hook handle. */ |
#endif |
36 |
static DWORD tray_proc_id = 0; /* WinPT PID */ |
static HHOOK cbt_hook ATTR_SEC = NULL; /* CTB hook handle. */ |
37 |
static HWND shell_traywnd = 0; /* Tray window handle. */ |
static DWORD tray_proc_id ATTR_SEC = 0; /* WinPT PID */ |
38 |
static HWND curr_focus = NULL; /* Current window focus handle. */ |
static HWND shell_traywnd ATTR_SEC = 0; /* Tray window handle. */ |
39 |
static HWND rebar_w32 = NULL; |
static HWND curr_focus ATTR_SEC = NULL; /* Current window focus handle. */ |
40 |
static HWND mstask_swc = NULL; |
static HWND rebar_w32 ATTR_SEC = NULL; |
41 |
static HWND systab_c32 = NULL; |
static HWND mstask_swc ATTR_SEC = NULL; |
42 |
|
static HWND systab_c32 ATTR_SEC = NULL; |
43 |
|
#ifndef __GNUC__ |
44 |
#pragma data_seg() |
#pragma data_seg() |
45 |
|
#endif |
46 |
|
#undef ATTR_SEC |
47 |
|
|
48 |
static unsigned *journ_keys = 0; |
static unsigned *journ_keys = 0; |
49 |
static unsigned key_idx = 0; |
static unsigned keyidx = 0; |
50 |
static unsigned nkeys = 0; |
static unsigned nkeys = 0; |
51 |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
62 |
/* A window is about to receive the keyboard focus */ |
/* A window is about to receive the keyboard focus */ |
63 |
|
|
64 |
curr_hwnd = (HWND)wparam; |
curr_hwnd = (HWND)wparam; |
65 |
GetWindowThreadProcessId( curr_hwnd, &proc_id ); |
GetWindowThreadProcessId (curr_hwnd, &proc_id); |
66 |
/* Only if the current window is different from this window list, |
/* Only if the current window is different from this window list, |
67 |
we set the new focus. For more information read the hint in |
we set the new focus. For more information read the hint in |
68 |
PTD_initialize. */ |
PTD_initialize. */ |
96 |
tray_proc_id = GetCurrentProcessId (); |
tray_proc_id = GetCurrentProcessId (); |
97 |
cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0); |
cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0); |
98 |
if (cbt_hook == NULL) |
if (cbt_hook == NULL) |
|
{ |
|
|
char buf[500]; |
|
|
|
|
|
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError (), |
|
|
MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), |
|
|
buf, sizeof buf -1, NULL); |
|
|
MessageBox (NULL, buf, "Error", MB_OK|MB_ICONSTOP); |
|
99 |
return FALSE; |
return FALSE; |
|
} |
|
100 |
|
|
|
|
|
101 |
/* Okay, what are we doing here: |
/* Okay, what are we doing here: |
102 |
* 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 |
103 |
* 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 |
120 |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
121 |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
122 |
|
|
123 |
/*log_foo ("tray_proc_id=%u cbt_hook=%p shell_traywnd=%p rebar_w32=%p " |
/*debug ("tray_proc_id=%u cbt_hook=%p shell_traywnd=%p rebar_w32=%p " |
124 |
"mstask_swc=%p systab_c32=%p", |
"mstask_swc=%p systab_c32=%p", |
125 |
tray_proc_id, cbt_hook, shell_traywnd, rebar_w32, |
tray_proc_id, cbt_hook, shell_traywnd, rebar_w32, |
126 |
mstask_swc, systab_c32);*/ |
mstask_swc, systab_c32);*/ |
127 |
|
|
128 |
return TRUE; |
return TRUE; |
129 |
} |
} |
156 |
LPEVENTMSG em; |
LPEVENTMSG em; |
157 |
|
|
158 |
if (code == HC_SKIP) { |
if (code == HC_SKIP) { |
159 |
key_idx++; |
keyidx++; |
160 |
if (key_idx == nkeys) { |
if (keyidx == nkeys) { |
161 |
UnhookWindowsHookEx (journ_hook); |
UnhookWindowsHookEx (journ_hook); |
162 |
journ_hook = NULL; |
journ_hook = NULL; |
163 |
} |
} |
170 |
* paramH - specifies the scan code. |
* paramH - specifies the scan code. |
171 |
*/ |
*/ |
172 |
em = (LPEVENTMSG )lparam; |
em = (LPEVENTMSG )lparam; |
173 |
if (journ_keys[key_idx] & 0x8000) |
if (journ_keys[keyidx] & 0x8000) |
174 |
em->message = journ_keys[key_idx] & 0x4000 ? WM_SYSKEYDOWN : WM_KEYDOWN; |
em->message = journ_keys[keyidx] & 0x4000 ? WM_SYSKEYDOWN : WM_KEYDOWN; |
175 |
else |
else |
176 |
em->message = journ_keys[key_idx] & 0x4000 ? WM_SYSKEYUP : WM_KEYUP; |
em->message = journ_keys[keyidx] & 0x4000 ? WM_SYSKEYUP : WM_KEYUP; |
177 |
em->paramL = LOBYTE( journ_keys[key_idx] ) |
em->paramL = LOBYTE( journ_keys[keyidx] ) |
178 |
| (MapVirtualKey (LOBYTE (journ_keys[key_idx]), 0) << 8); |
| (MapVirtualKey (LOBYTE (journ_keys[keyidx]), 0) << 8); |
179 |
em->paramH = 1; |
em->paramH = 1; |
180 |
em->time = GetTickCount (); |
em->time = GetTickCount (); |
181 |
return 0; |
return 0; |
182 |
} |
} |
183 |
|
|
184 |
return CallNextHookEx (journ_hook, code, wparam, lparam); |
return CallNextHookEx (journ_hook, code, wparam, lparam); |
185 |
} /* PTD_Playback_proc */ |
} |
186 |
|
|
187 |
|
|
188 |
|
|
191 |
{ |
{ |
192 |
MSG msg; |
MSG msg; |
193 |
journ_keys = keys; |
journ_keys = keys; |
194 |
key_idx = 0; |
keyidx = 0; |
195 |
nkeys = n_keys; |
nkeys = n_keys; |
196 |
|
|
197 |
if (journ_hook) |
if (journ_hook) |
198 |
return FALSE; |
return FALSE; |
231 |
} |
} |
232 |
|
|
233 |
|
|
234 |
/* Display a JPG picture in the given window at the given point. */ |
/*FILE *fp;*/ |
|
extern "C" int |
|
|
PTD_jpg_show (HWND hwnd, POINT *p, LPCSTR name) |
|
|
{ |
|
|
CJPG jpg; |
|
|
HDC hdc; |
|
|
POINT p2; |
|
|
BOOL rc; |
|
|
|
|
|
rc = jpg.load (name); |
|
|
if (!rc) |
|
|
return -1; /* XXX: use real return code. */ |
|
|
hdc = GetWindowDC (hwnd); |
|
|
rc = jpg.updateSizeOnDC (hdc); |
|
|
if (!rc) { |
|
|
ReleaseDC (hwnd, hdc); |
|
|
return -2; /* XXX: use real return code. */ |
|
|
} |
|
|
|
|
|
p2.x = jpg.m_Width; |
|
|
p2.y = jpg.m_Height; |
|
|
rc = jpg.show (hdc, p, &p2, 0, 0); |
|
|
|
|
|
ReleaseDC (hwnd, hdc); |
|
|
jpg.freePictureData (); |
|
|
return rc; |
|
|
} |
|
|
|
|
235 |
|
|
236 |
|
extern "C" BOOL WINAPI |
|
BOOL WINAPI |
|
237 |
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv) |
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv) |
238 |
{ |
{ |
239 |
switch (reason) { |
switch (reason) { |
240 |
case DLL_PROCESS_ATTACH: |
case DLL_PROCESS_ATTACH: |
241 |
glob_hinst = hinst; |
glob_hinst = hinst; |
242 |
|
/* |
243 |
|
fp = fopen ("attach_pid.txt", "a+b"); |
244 |
|
if (fp != NULL) { |
245 |
|
fprintf (fp, "[+ %lu]\r\n", GetCurrentProcessId()); |
246 |
|
fclose (fp); |
247 |
|
}*/ |
248 |
break; |
break; |
249 |
case DLL_THREAD_ATTACH: |
|
250 |
|
case DLL_PROCESS_DETACH: |
251 |
|
/*fp = fopen ("attach_pid.txt", "a+b"); |
252 |
|
if (fp != NULL) { |
253 |
|
fprintf (fp, "[- %lu]\r\n", GetCurrentProcessId()); |
254 |
|
fclose (fp); |
255 |
|
}*/ |
256 |
break; |
break; |
257 |
|
|
258 |
|
case DLL_THREAD_ATTACH: |
259 |
case DLL_THREAD_DETACH: |
case DLL_THREAD_DETACH: |
260 |
break; |
break; |
261 |
case DLL_PROCESS_DETACH: |
|
|
break; |
|
262 |
} |
} |
263 |
|
|
264 |
return TRUE; |
return TRUE; |
265 |
} |
} |
|
|
|