20 |
|
|
21 |
#include <windows.h> |
#include <windows.h> |
22 |
#include <stdio.h> |
#include <stdio.h> |
23 |
|
#include <ocidl.h> |
24 |
|
#include <olectl.h> |
25 |
|
|
26 |
|
#include "wptJPG.h" |
27 |
|
|
28 |
HINSTANCE glob_hinst; |
HINSTANCE glob_hinst; |
29 |
|
|
30 |
/* 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 */ |
31 |
#pragma data_seg(".SHARDAT") |
#pragma data_seg(".SHARDAT") |
32 |
static HHOOK cbt_hook = NULL; |
static HHOOK cbt_hook = NULL; /* CTB hook handle. */ |
33 |
static DWORD tray_proc_id = 0; |
static DWORD tray_proc_id = 0; /* WinPT PID */ |
34 |
static HWND shell_traywnd = 0; |
static HWND shell_traywnd = 0; /* Tray window handle. */ |
35 |
static HWND curr_focus = NULL; |
static HWND curr_focus = NULL; /* Current window focus handle. */ |
36 |
static HWND rebar_w32 = NULL; |
static HWND rebar_w32 = NULL; |
37 |
static HWND mstask_swc = NULL; |
static HWND mstask_swc = NULL; |
38 |
static HWND systab_c32 = NULL; |
static HWND systab_c32 = NULL; |
39 |
#pragma data_seg() |
#pragma data_seg() |
40 |
|
|
41 |
static unsigned * journ_keys = 0; |
static unsigned *journ_keys = 0; |
42 |
static unsigned key_idx = 0; |
static unsigned key_idx = 0; |
43 |
static unsigned nkeys = 0; |
static unsigned nkeys = 0; |
44 |
static HHOOK journ_hook = NULL; |
static HHOOK journ_hook = NULL; /* Journaling hook handle. */ |
45 |
|
|
46 |
|
|
47 |
static LRESULT CALLBACK |
static LRESULT CALLBACK |
70 |
} |
} |
71 |
|
|
72 |
return CallNextHookEx (cbt_hook , code, wparam, lparam); |
return CallNextHookEx (cbt_hook , code, wparam, lparam); |
73 |
} /* PTD_CBT_proc */ |
} |
74 |
|
|
75 |
|
|
76 |
|
/* Return the last selected window */ |
77 |
HWND |
HWND |
78 |
PTD_get_curr_hwnd (void) |
PTD_get_curr_hwnd (void) |
79 |
{ |
{ |
80 |
return curr_focus; |
return curr_focus; |
81 |
} /* PTD_get_curr_hwnd */ |
} |
82 |
|
|
83 |
|
|
84 |
|
/* Initialize CTB hook and try to find the system windows. */ |
85 |
BOOL |
BOOL |
86 |
PTD_initialize (void) |
PTD_initialize (void) |
87 |
{ |
{ |
88 |
tray_proc_id = GetCurrentProcessId( ); |
tray_proc_id = GetCurrentProcessId (); |
89 |
cbt_hook = SetWindowsHookEx( WH_CBT, PTD_CBT_proc, glob_hinst, 0 ); |
cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0); |
90 |
if( cbt_hook == NULL ) |
if (cbt_hook == NULL) |
91 |
return FALSE; |
return FALSE; |
92 |
|
|
93 |
/* Okay, what are we doing here: |
/* Okay, what are we doing here: |
94 |
* In the past I used the Spy++ application to find out why the old current window |
* In the past I used the Spy++ application to find out why the old current |
95 |
* doesn't work on so much systems. Now we try to use the computer based training |
* window doesn't work on so much systems. Now we try to use the computer |
96 |
* hook, more precise the HCBT_SETFOCUS to find out the last window focus. But to |
* based training hook, more precise the HCBT_SETFOCUS to find out the |
97 |
* succeed we need to ignore some windows because otherwise our own window or a |
* last window focus. But to succeed we need to ignore some windows |
98 |
* window from the taskbar would be recognized. |
* because otherwise our own window or a window from the taskbar |
99 |
|
* would be recognized. |
100 |
* |
* |
101 |
* Here is what the Spy++ says about the windows order: |
* Here is what the Spy++ says about the windows order: |
102 |
* Shell_TrayWnd |
* Shell_TrayWnd |
104 |
* \ MSTaskSwWClass |
* \ MSTaskSwWClass |
105 |
* \ SysTabControl32 |
* \ SysTabControl32 |
106 |
* |
* |
107 |
* As a result we need to ignore those windows to prevent failured in the code. |
* As a result we need to ignore those windows to prevent failured |
108 |
|
* in the code. |
109 |
*/ |
*/ |
110 |
shell_traywnd = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL); |
shell_traywnd = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL); |
111 |
rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL); |
rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL); |
112 |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL); |
113 |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL); |
114 |
|
|
115 |
/*_log_box ("tray_proc_id=%u cbt_hook=%p shell_traywnd=%p rebar_w32=%p " |
/*log_foo ("tray_proc_id=%u cbt_hook=%p shell_traywnd=%p rebar_w32=%p " |
116 |
"mstask_swc=%p systab_c32=%p", |
"mstask_swc=%p systab_c32=%p", |
117 |
tray_proc_id, cbt_hook, shell_traywnd, rebar_w32, |
tray_proc_id, cbt_hook, shell_traywnd, rebar_w32, |
118 |
mstask_swc, systab_c32);*/ |
mstask_swc, systab_c32);*/ |
119 |
|
|
120 |
return TRUE; |
return TRUE; |
121 |
} /* PTD_initialize */ |
} |
122 |
|
|
123 |
|
|
124 |
|
/* Remove the CTB hook from the system and reset all variables. */ |
125 |
void |
void |
126 |
PTD_delete (void) |
PTD_delete (void) |
127 |
{ |
{ |
131 |
cbt_hook = NULL; |
cbt_hook = NULL; |
132 |
shell_traywnd = NULL; |
shell_traywnd = NULL; |
133 |
tray_proc_id = 0; |
tray_proc_id = 0; |
134 |
} /* PTD_delete */ |
} |
135 |
|
|
136 |
|
|
137 |
|
/* Return if the CTB hook is currently used. */ |
138 |
int |
int |
139 |
PTD_is_used (void) |
PTD_is_used (void) |
140 |
{ |
{ |
141 |
return shell_traywnd && cbt_hook; |
return shell_traywnd && cbt_hook; |
142 |
} /* PTD_is_used */ |
} |
143 |
|
|
144 |
|
|
145 |
LRESULT CALLBACK |
static LRESULT CALLBACK |
146 |
PTD_playback_proc (int code, WPARAM wparam, LPARAM lparam) |
PTD_playback_proc (int code, WPARAM wparam, LPARAM lparam) |
147 |
{ |
{ |
148 |
LPEVENTMSG em; |
LPEVENTMSG em; |
177 |
} /* PTD_Playback_proc */ |
} /* PTD_Playback_proc */ |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
BOOL |
BOOL |
182 |
PTD_keyb_send (UINT * keys, UINT n_keys) |
PTD_keyb_send (UINT *keys, UINT n_keys) |
183 |
{ |
{ |
184 |
MSG msg; |
MSG msg; |
|
|
|
185 |
journ_keys = keys; |
journ_keys = keys; |
186 |
key_idx = 0; |
key_idx = 0; |
187 |
nkeys = n_keys; |
nkeys = n_keys; |
220 |
} |
} |
221 |
|
|
222 |
return TRUE; |
return TRUE; |
223 |
} /* PTD_keyb_send */ |
} |
224 |
|
|
225 |
|
|
226 |
|
/* Return version of the PTD library. */ |
227 |
const char * |
const char * |
228 |
PTD_get_version (void) |
PTD_get_version (void) |
229 |
{ |
{ |
230 |
return "0.8.0"; |
return "0.8.1"; |
231 |
} /* PTD_get_version */ |
} |
232 |
|
|
233 |
|
|
234 |
|
/* Display a JPG picture in the given window at the given point. */ |
235 |
|
int |
236 |
|
PTD_jpg_show (HWND hwnd, POINT *p, LPCSTR name) |
237 |
|
{ |
238 |
|
CJPG jpg; |
239 |
|
HDC hdc; |
240 |
|
POINT p2; |
241 |
|
BOOL rc; |
242 |
|
|
243 |
|
rc = jpg.load (name); |
244 |
|
if (!rc) |
245 |
|
return -1; /* XXX: use real return code. */ |
246 |
|
hdc = GetWindowDC (hwnd); |
247 |
|
rc = jpg.updateSizeOnDC (hdc); |
248 |
|
if (!rc) { |
249 |
|
ReleaseDC (hwnd, hdc); |
250 |
|
return -2; /* XXX: use real return code. */ |
251 |
|
} |
252 |
|
|
253 |
|
p2.x = jpg.m_Width; |
254 |
|
p2.y = jpg.m_Height; |
255 |
|
rc = jpg.show (hdc, p, &p2, 0, 0); |
256 |
|
|
257 |
|
ReleaseDC (hwnd, hdc); |
258 |
|
jpg.freePictureData (); |
259 |
|
return rc; |
260 |
|
} |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
BOOL WINAPI |
BOOL WINAPI |
276 |
break; |
break; |
277 |
} |
} |
278 |
return TRUE; |
return TRUE; |
279 |
} /* DllMain */ |
} |
280 |
|
|