/[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 59 by twoaday, Wed Nov 2 13:50:48 2005 UTC revision 305 by twoaday, Fri Mar 23 11:32:28 2007 UTC
# Line 1  Line 1 
1  /* PTD.cpp - Privacy Tray Dynamic  /* PTD.cpp - Privacy Tray Dynamic
2   *      Copyright (C) 2002-2005 Timo Schulz   *      Copyright (C) 2002-2007 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>
 #include <windows.h>  
21  #include <stdio.h>  #include <stdio.h>
22  #include <ocidl.h>  #include <ocidl.h>
23  #include <olectl.h>  #include <olectl.h>
# Line 32  Line 26 
26    
27  HINSTANCE glob_hinst;  HINSTANCE glob_hinst;
28    
29  /* 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.
30       This shared data is required by the hook function because that
31       function is called in the context of the actual thread running the
32       hook and thus we need a way to communicate the result of our hook
33       function back to us.  We use a shared data segment for this. */
34    #ifdef __GNUC__
35    #define ATTR_SEC __attribute__((section (".SHARDAT"), shared))
36    #else
37    #define ATTR_SEC
38  #pragma data_seg(".SHARDAT")  #pragma data_seg(".SHARDAT")
39  static HHOOK    cbt_hook = NULL;    /* CTB hook handle. */  #endif
40  static DWORD    tray_proc_id = 0;   /* WinPT PID */  static HHOOK cbt_hook      ATTR_SEC = NULL; /* CTB hook handle. */
41  static HWND     shell_traywnd = 0;  /* Tray window handle. */  static DWORD tray_proc_id  ATTR_SEC = 0;    /* WinPT PID */
42  static HWND     curr_focus = NULL;  /* Current window focus handle. */  static HWND  shell_traywnd ATTR_SEC = 0;    /* Tray window handle. */
43  static HWND     rebar_w32 = NULL;  static HWND  curr_focus    ATTR_SEC = NULL; /* Current window focus handle. */
44  static HWND     mstask_swc = NULL;  static HWND  rebar_w32     ATTR_SEC = NULL;
45  static HWND     systab_c32 = NULL;  static HWND  mstask_swc    ATTR_SEC = NULL;
46    static HWND  systab_c32    ATTR_SEC = NULL;
47    #ifndef __GNUC__
48  #pragma data_seg()  #pragma data_seg()
49    #endif
50    #undef ATTR_SEC
51    
52  static unsigned *journ_keys = 0;  static unsigned *journ_keys = 0;
53  static unsigned key_idx = 0;  static unsigned keyidx = 0;
54  static unsigned nkeys = 0;  static unsigned nkeys = 0;
55  static HHOOK journ_hook = NULL;     /* Journaling hook  handle. */  static HHOOK journ_hook = NULL;  /* Journaling hook  handle. */
56    
57    
58    void dns_cleanup (void);
59    
60    
61  static LRESULT CALLBACK  static LRESULT CALLBACK
# Line 59  PTD_CBT_proc (int code, WPARAM wparam, L Line 68  PTD_CBT_proc (int code, WPARAM wparam, L
68          /* A window is about to receive the keyboard focus */                    /* A window is about to receive the keyboard focus */          
69                    
70          curr_hwnd = (HWND)wparam;          curr_hwnd = (HWND)wparam;
71          GetWindowThreadProcessId( curr_hwnd, &proc_id );          GetWindowThreadProcessId (curr_hwnd, &proc_id);
72          /* Only if the current window is different from this window list,          /* Only if the current window is different from this window list,
73             we set the new focus. For more information read the hint in             we set the new focus. For more information read the hint in
74             PTD_initialize. */             PTD_initialize. */
# Line 93  PTD_initialize (void) Line 102  PTD_initialize (void)
102      tray_proc_id = GetCurrentProcessId ();      tray_proc_id = GetCurrentProcessId ();
103      cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0);      cbt_hook = SetWindowsHookEx (WH_CBT, PTD_CBT_proc, glob_hinst, 0);
104      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);  
105          return FALSE;          return FALSE;
       }  
106            
   
107      /* Okay, what are we doing here:      /* Okay, what are we doing here:
108       * 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
109       * 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
# Line 126  PTD_initialize (void) Line 126  PTD_initialize (void)
126      mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL);      mstask_swc = FindWindowEx (rebar_w32, NULL, "MSTaskSwWClass", NULL);
127      systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL);      systab_c32 = FindWindowEx (mstask_swc, NULL, "SysTabControl32", NULL);
128            
129      /*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 "
130                 "mstask_swc=%p systab_c32=%p",               "mstask_swc=%p systab_c32=%p",
131                 tray_proc_id, cbt_hook, shell_traywnd, rebar_w32,               tray_proc_id, cbt_hook, shell_traywnd, rebar_w32,
132                 mstask_swc, systab_c32);*/               mstask_swc, systab_c32);*/
133            
134      return TRUE;      return TRUE;
135  }  }
# Line 141  PTD_delete (void) Line 141  PTD_delete (void)
141  {  {
142      if (!cbt_hook)      if (!cbt_hook)
143          return;          return;
144        dns_cleanup ();
145      UnhookWindowsHookEx (cbt_hook);      UnhookWindowsHookEx (cbt_hook);
146      cbt_hook = NULL;      cbt_hook = NULL;
147      shell_traywnd = NULL;      shell_traywnd = NULL;
# Line 162  PTD_playback_proc (int code, WPARAM wpar Line 163  PTD_playback_proc (int code, WPARAM wpar
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 176  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;
189      }      }
190            
191      return CallNextHookEx (journ_hook, code, wparam, lparam);      return CallNextHookEx (journ_hook, code, wparam, lparam);
192  } /* PTD_Playback_proc */  }
193    
194    
195    
# Line 197  PTD_keyb_send (UINT *keys, UINT n_keys) Line 198  PTD_keyb_send (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      if (journ_hook)      if (journ_hook)
# Line 243  PTD_jpg_show (HWND hwnd, POINT *p, LPCST Line 244  PTD_jpg_show (HWND hwnd, POINT *p, LPCST
244  {  {
245      CJPG jpg;      CJPG jpg;
246      HDC hdc;      HDC hdc;
247      POINT p2;      POINT sizewnd;
248        RECT rwnd;
249      BOOL rc;      BOOL rc;
250    
251      rc = jpg.load (name);      rc = jpg.load (name);
# Line 256  PTD_jpg_show (HWND hwnd, POINT *p, LPCST Line 258  PTD_jpg_show (HWND hwnd, POINT *p, LPCST
258          return -2; /* XXX: use real return code. */          return -2; /* XXX: use real return code. */
259      }      }
260    
261      p2.x = jpg.m_Width;      GetWindowRect (hwnd, &rwnd);
262      p2.y = jpg.m_Height;      sizewnd.x = rwnd.right - rwnd.left;
263      rc = jpg.show (hdc, p, &p2, 0, 0);      sizewnd.y = rwnd.bottom - rwnd.top;
264        rc = jpg.show (hdc, p, &sizewnd, 0, 0);
265    
266      ReleaseDC (hwnd, hdc);      ReleaseDC (hwnd, hdc);
267      jpg.freePictureData ();      jpg.freePictureData ();
268      return rc;      return rc;
269  }  }
270    
   
271                                    
272  BOOL WINAPI  extern "C" BOOL WINAPI
273  DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)  DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserv)
274  {  {
275      switch (reason)  {      switch (reason)  {
276      case DLL_PROCESS_ATTACH:      case DLL_PROCESS_ATTACH:
277          glob_hinst = hinst;          glob_hinst = hinst;
278          break;          break;
279      case DLL_THREAD_ATTACH:        case DLL_THREAD_ATTACH:  
280          break;          break;
# Line 283  DllMain (HINSTANCE hinst, DWORD reason, Line 285  DllMain (HINSTANCE hinst, DWORD reason,
285      }      }
286      return TRUE;      return TRUE;
287  }  }
   

Legend:
Removed from v.59  
changed lines
  Added in v.305

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26