/[winpt]/trunk/PTD/PTD.cpp
ViewVC logotype

Diff of /trunk/PTD/PTD.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 248 by twoaday, Fri Jul 28 11:11:09 2006 UTC revision 334 by twoaday, Sun Nov 27 12:00:45 2011 UTC
# Line 1  Line 1 
1  /* PTD.cpp - Privacy Tray Dynamic  /* PTD.cpp - Privacy Tray Dynamic
2   *      Copyright (C) 2002-2006 Timo Schulz   *      Copyright (C) 2002-2009 Timo Schulz
3   *   *
4   * This file is part of WinPT.   * This file is part of WinPT.
5   *   *
# Line 12  Line 12 
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>
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 becuase theat     This shared data is required by the hook function because that
27     function is called in the context of the actual thread running the     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     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. */     function back to us.  We use a shared data segment for this. */
# Line 55  static HWND  systab_c32    ATTR_SEC = NU Line 46  static HWND  systab_c32    ATTR_SEC = NU
46  #undef ATTR_SEC  #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    
 void dns_cleanup (void);  
   
54    
55  static LRESULT CALLBACK  static LRESULT CALLBACK
56  PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam)  PTD_CBT_proc (int code, WPARAM wparam, LPARAM lparam)
# Line 73  PTD_CBT_proc (int code, WPARAM wparam, L Line 62  PTD_CBT_proc (int code, WPARAM wparam, L
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. */
# Line 94  PTD_CBT_proc (int code, WPARAM wparam, L Line 83  PTD_CBT_proc (int code, WPARAM wparam, L
83    
84  /* Return the last selected window */  /* Return the last selected window */
85  extern "C" HWND  extern "C" HWND
86  PTD_get_curr_hwnd (void)  PTD_get_current_window (void)
87  {  {
88      return curr_focus;      return curr_focus;
89  }  }
# Line 126  PTD_initialize (void) Line 115  PTD_initialize (void)
115       * As a result we need to ignore those windows to prevent failured       * As a result we need to ignore those windows to prevent failured
116       * in the code.       * in the code.
117       */       */
118        
119        // FIXME: I doubt this is working for Windows 7
120      shell_traywnd = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL);      shell_traywnd = FindWindowEx (NULL, NULL, "Shell_TrayWnd", NULL);
121      rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL);      rebar_w32 = FindWindowEx (shell_traywnd, NULL, "ReBarWindow32", NULL);
122      mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL);      mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL);
123      systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL);      systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL);
124            
125      /*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 "
126                 "mstask_swc=%p systab_c32=%p",               "mstask_swc=%p systab_c32=%p",
127                 tray_proc_id, cbt_hook, shell_traywnd, rebar_w32,               tray_proc_id, cbt_hook, shell_traywnd, rebar_w32,
128                 mstask_swc, systab_c32);*/               mstask_swc, systab_c32);*/
129            
130      return TRUE;      return TRUE;
131  }  }
# Line 142  PTD_initialize (void) Line 133  PTD_initialize (void)
133    
134  /* Remove the CTB hook from the system and reset all variables. */  /* Remove the CTB hook from the system and reset all variables. */
135  extern "C" void  extern "C" void
136  PTD_delete (void)  PTD_delete_hook (void)
137  {  {
138      if (!cbt_hook)      if (!cbt_hook)
139          return;          return;
     dns_cleanup ();  
140      UnhookWindowsHookEx (cbt_hook);      UnhookWindowsHookEx (cbt_hook);
141      cbt_hook = NULL;      cbt_hook = NULL;
142      shell_traywnd = NULL;      shell_traywnd = NULL;
# Line 156  PTD_delete (void) Line 146  PTD_delete (void)
146    
147  /* Return if the CTB hook is currently used. */  /* Return if the CTB hook is currently used. */
148  extern "C" int  extern "C" int
149  PTD_is_used (void)  PTD_is_hook_used (void)
150  {  {
151      return shell_traywnd && cbt_hook;      return shell_traywnd && cbt_hook;
152  }  }
153    
154    /* From the MSDN:
155     * "Typically, an application uses this function to play back a series
156     * of mouse and keyboard messages recorded previously by the
157     * JournalRecordProc hook procedure. As long as a JournalPlaybackProc
158     * hook procedure is installed, regular mouse and keyboard input is disabled."
159     */
160  static LRESULT CALLBACK  static LRESULT CALLBACK
161  PTD_playback_proc (int code, WPARAM wparam, LPARAM lparam)  PTD_playback_proc (int code, WPARAM wparam, LPARAM lparam)
162  {  {
163      LPEVENTMSG em;      LPEVENTMSG em;
164            
165      if (code == HC_SKIP) {      if (code == HC_SKIP) {
166          key_idx++;          keyidx++;
167          if (key_idx == nkeys) {          if (keyidx >= nkeys) {
168              UnhookWindowsHookEx (journ_hook);              UnhookWindowsHookEx (journ_hook);
169              journ_hook = NULL;              journ_hook = NULL;
170          }          }
# Line 182  PTD_playback_proc (int code, WPARAM wpar Line 177  PTD_playback_proc (int code, WPARAM wpar
177           * paramH - specifies the scan code.                                       * paramH - specifies the scan code.                            
178           */           */
179          em = (LPEVENTMSG )lparam;          em = (LPEVENTMSG )lparam;
180          if (journ_keys[key_idx] & 0x8000)          if (journ_keys[keyidx] & 0x8000)
181              em->message = journ_keys[key_idx] & 0x4000 ? WM_SYSKEYDOWN : WM_KEYDOWN;              em->message = journ_keys[keyidx] & 0x4000 ? WM_SYSKEYDOWN : WM_KEYDOWN;
182          else          else
183              em->message = journ_keys[key_idx] & 0x4000 ? WM_SYSKEYUP : WM_KEYUP;              em->message = journ_keys[keyidx] & 0x4000 ? WM_SYSKEYUP : WM_KEYUP;
184          em->paramL = LOBYTE( journ_keys[key_idx] )          em->paramL = LOBYTE (journ_keys[keyidx])
185              | (MapVirtualKey (LOBYTE (journ_keys[key_idx]), 0) << 8);              | (MapVirtualKey (LOBYTE (journ_keys[keyidx]), 0) << 8);
186          em->paramH = 1;          em->paramH = 1;
187          em->time = GetTickCount ();          em->time = GetTickCount ();
188          return 0;          return 0;
# Line 199  PTD_playback_proc (int code, WPARAM wpar Line 194  PTD_playback_proc (int code, WPARAM wpar
194    
195    
196  extern "C" BOOL  extern "C" BOOL
197  PTD_keyb_send (UINT *keys, UINT n_keys)  PTD_keyboard_send_keys (UINT *keys, UINT n_keys)
198  {  {
199      MSG msg;      MSG msg;
200      journ_keys = keys;      journ_keys = keys;
201      key_idx = 0;      keyidx = 0;
202      nkeys =  n_keys;          nkeys = n_keys;
203            
204        /* Return immediately if there is an active hook */
205      if (journ_hook)      if (journ_hook)
206          return FALSE;          return FALSE;
207            
208      while (GetAsyncKeyState (VK_MENU) & 0x8000      while (GetAsyncKeyState (VK_MENU) & 0x8000 ||
209              || GetAsyncKeyState (VK_SHIFT) & 0x8000             GetAsyncKeyState (VK_SHIFT) & 0x8000 ||
210              || GetAsyncKeyState (VK_CONTROL) & 0x8000) {             GetAsyncKeyState (VK_CONTROL) & 0x8000) {
211          if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {          if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE)) {
212              if (msg.message == WM_QUIT) {              if (msg.message == WM_QUIT) {
213                  PostMessage (msg.hwnd, msg.message, msg.wParam, msg.lParam);                  PostMessage (msg.hwnd, msg.message, msg.wParam, msg.lParam);
# Line 243  PTD_keyb_send (UINT *keys, UINT n_keys) Line 239  PTD_keyb_send (UINT *keys, UINT n_keys)
239  }  }
240    
241    
242  /* Display a JPG picture in the given window at the given point. */  /* Main entry point for the DLL */
 extern "C" int  
 PTD_jpg_show (HWND hwnd, POINT *p, LPCSTR name)  
 {  
     CJPG jpg;  
     HDC hdc;  
     POINT sizewnd;  
     RECT rwnd;  
     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. */  
     }  
   
     GetWindowRect (hwnd, &rwnd);  
     sizewnd.x = rwnd.right - rwnd.left;  
     sizewnd.y = rwnd.bottom - rwnd.top;  
     rc = jpg.show (hdc, p, &sizewnd, 0, 0);  
   
     ReleaseDC (hwnd, hdc);  
     jpg.freePictureData ();  
     return rc;  
 }  
   
                   
243  extern "C" BOOL WINAPI  extern "C" BOOL WINAPI
244  DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)  DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)
245  {  {
246      switch (reason)  {      switch (reason)  {
247      case DLL_PROCESS_ATTACH:      case DLL_PROCESS_ATTACH:
248          glob_hinst = hinst;          /* Handle to the attached process */
249            glob_hinst = hinst;
250          break;          break;
251      case DLL_THREAD_ATTACH:          
252        case DLL_PROCESS_DETACH:
253          break;          break;
254            
255        case DLL_THREAD_ATTACH:  
256      case DLL_THREAD_DETACH:        case DLL_THREAD_DETACH:  
257          break;          break;
258      case DLL_PROCESS_DETACH:          
         break;  
259      }      }
260        
261      return TRUE;      return TRUE;
262  }  }

Legend:
Removed from v.248  
changed lines
  Added in v.334

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26