1 |
/* PTD.cpp - Privacy Tray Dynamic |
/* PTD.cpp - Privacy Tray Dynamic |
2 |
* Copyright (C) 2002-2005 Timo Schulz |
* Copyright (C) 2002-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
23 |
#endif |
#endif |
24 |
|
|
25 |
#include <windows.h> |
#include <windows.h> |
|
#include <windows.h> |
|
26 |
#include <stdio.h> |
#include <stdio.h> |
27 |
#include <ocidl.h> |
#include <ocidl.h> |
28 |
#include <olectl.h> |
#include <olectl.h> |
31 |
|
|
32 |
HINSTANCE glob_hinst; |
HINSTANCE glob_hinst; |
33 |
|
|
34 |
/* 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. |
35 |
|
This shared data is required by the hook function becuase theat |
36 |
|
function is called in the context of the actual thread running the |
37 |
|
hook and thus we need a way to communicate the result of our hook |
38 |
|
function back to us. We use a shared data segment for this. */ |
39 |
|
#ifdef __GNUC__ |
40 |
|
#define ATTR_SEC __attribute__((section (".SHARDAT"), shared)) |
41 |
|
#else |
42 |
|
#define ATTR_SEC |
43 |
#pragma data_seg(".SHARDAT") |
#pragma data_seg(".SHARDAT") |
44 |
static HHOOK cbt_hook = NULL; /* CTB hook handle. */ |
#endif |
45 |
static DWORD tray_proc_id = 0; /* WinPT PID */ |
static HHOOK cbt_hook ATTR_SEC = NULL; /* CTB hook handle. */ |
46 |
static HWND shell_traywnd = 0; /* Tray window handle. */ |
static DWORD tray_proc_id ATTR_SEC = 0; /* WinPT PID */ |
47 |
static HWND curr_focus = NULL; /* Current window focus handle. */ |
static HWND shell_traywnd ATTR_SEC = 0; /* Tray window handle. */ |
48 |
static HWND rebar_w32 = NULL; |
static HWND curr_focus ATTR_SEC = NULL; /* Current window focus handle. */ |
49 |
static HWND mstask_swc = NULL; |
static HWND rebar_w32 ATTR_SEC = NULL; |
50 |
static HWND systab_c32 = NULL; |
static HWND mstask_swc ATTR_SEC = NULL; |
51 |
|
static HWND systab_c32 ATTR_SEC = NULL; |
52 |
|
#ifndef __GNUC__ |
53 |
#pragma data_seg() |
#pragma data_seg() |
54 |
|
#endif |
55 |
|
#undef ATTR_SEC |
56 |
|
|
57 |
static unsigned *journ_keys = 0; |
static unsigned *journ_keys = 0; |
58 |
static unsigned key_idx = 0; |
static unsigned key_idx = 0; |
60 |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
61 |
|
|
62 |
|
|
63 |
|
void dns_cleanup (void); |
64 |
|
|
65 |
|
|
66 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
67 |
PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam) |
PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam) |
68 |
{ |
{ |
107 |
tray_proc_id = GetCurrentProcessId (); |
tray_proc_id = GetCurrentProcessId (); |
108 |
cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0); |
cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0); |
109 |
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); |
|
110 |
return FALSE; |
return FALSE; |
|
} |
|
111 |
|
|
|
|
|
112 |
/* Okay, what are we doing here: |
/* Okay, what are we doing here: |
113 |
* 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 |
114 |
* 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 |
146 |
{ |
{ |
147 |
if (!cbt_hook) |
if (!cbt_hook) |
148 |
return; |
return; |
149 |
|
dns_cleanup (); |
150 |
UnhookWindowsHookEx (cbt_hook); |
UnhookWindowsHookEx (cbt_hook); |
151 |
cbt_hook = NULL; |
cbt_hook = NULL; |
152 |
shell_traywnd = NULL; |
shell_traywnd = NULL; |
194 |
} |
} |
195 |
|
|
196 |
return CallNextHookEx (journ_hook, code, wparam, lparam); |
return CallNextHookEx (journ_hook, code, wparam, lparam); |
197 |
} /* PTD_Playback_proc */ |
} |
198 |
|
|
199 |
|
|
200 |
|
|
249 |
{ |
{ |
250 |
CJPG jpg; |
CJPG jpg; |
251 |
HDC hdc; |
HDC hdc; |
252 |
POINT p2; |
POINT sizewnd; |
253 |
|
RECT rwnd; |
254 |
BOOL rc; |
BOOL rc; |
255 |
|
|
256 |
rc = jpg.load (name); |
rc = jpg.load (name); |
263 |
return -2; /* XXX: use real return code. */ |
return -2; /* XXX: use real return code. */ |
264 |
} |
} |
265 |
|
|
266 |
p2.x = jpg.m_Width; |
GetWindowRect (hwnd, &rwnd); |
267 |
p2.y = jpg.m_Height; |
sizewnd.x = rwnd.right - rwnd.left; |
268 |
rc = jpg.show (hdc, p, &p2, 0, 0); |
sizewnd.y = rwnd.bottom - rwnd.top; |
269 |
|
rc = jpg.show (hdc, p, &sizewnd, 0, 0); |
270 |
|
|
271 |
ReleaseDC (hwnd, hdc); |
ReleaseDC (hwnd, hdc); |
272 |
jpg.freePictureData (); |
jpg.freePictureData (); |
273 |
return rc; |
return rc; |
274 |
} |
} |
275 |
|
|
|
|
|
276 |
|
|
277 |
BOOL WINAPI |
extern "C" BOOL WINAPI |
278 |
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv) |
DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv) |
279 |
{ |
{ |
280 |
switch (reason) { |
switch (reason) { |
281 |
case DLL_PROCESS_ATTACH: |
case DLL_PROCESS_ATTACH: |
282 |
glob_hinst = hinst; |
glob_hinst = hinst; |
283 |
break; |
break; |
284 |
case DLL_THREAD_ATTACH: |
case DLL_THREAD_ATTACH: |
285 |
break; |
break; |
290 |
} |
} |
291 |
return TRUE; |
return TRUE; |
292 |
} |
} |
|
|
|