1 /*********************************************************************
2 *
3 * File : $Source: /cvsroot/ijbswa/current/w32taskbar.c,v $
4 *
5 * Purpose : Functions for creating, setting and destroying the
6 * workspace tray icon
7 *
8 * Copyright : Written by and Copyright (C) 2001-2002 members of
9 * the Privoxy team. https://www.privoxy.org/
10 *
11 * Written by and Copyright (C) 1999 Adam Lock
12 * <locka@iol.ie>
13 *
14 * This program is free software; you can redistribute it
15 * and/or modify it under the terms of the GNU General
16 * Public License as published by the Free Software
17 * Foundation; either version 2 of the License, or (at
18 * your option) any later version.
19 *
20 * This program is distributed in the hope that it will
21 * be useful, but WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A
23 * PARTICULAR PURPOSE. See the GNU General Public
24 * License for more details.
25 *
26 * The GNU General Public License should be included with
27 * this file. If not, you can view it at
28 * http://www.gnu.org/copyleft/gpl.html
29 * or write to the Free Software Foundation, Inc., 59
30 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 *
32 *********************************************************************/
33
34
35 #include "config.h"
36
37 #include <stdio.h>
38
39 #ifndef STRICT
40 #define STRICT
41 #endif
42 #include <windows.h>
43
44 #include "w32taskbar.h"
45 #include "w32res.h"
46 #include "w32log.h"
47
48 #ifndef _WIN_CONSOLE /* entire file */
49
50 #define WM_TRAYMSG WM_USER+1
51
52 static HMENU g_hmenuTray;
53 static HWND g_hwndTrayX;
54 static UINT g_traycreatedmsg;
55
56 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
57
58
59 /*********************************************************************
60 *
61 * Function : CreateTrayWindow
62 *
63 * Description : Creates and returns the invisible window responsible
64 * for processing tray messages.
65 *
66 * Parameters :
67 * 1 : hInstance = instance handle of this application
68 *
69 * Returns : Handle of the systray window.
70 *
71 *********************************************************************/
CreateTrayWindow(HINSTANCE hInstance)72 HWND CreateTrayWindow(HINSTANCE hInstance)
73 {
74 WNDCLASS wc;
75 static const char *szWndName = "PrivoxyTrayWindow";
76
77 wc.style = 0;
78 wc.lpfnWndProc = TrayProc;
79 wc.cbClsExtra = 0;
80 wc.cbWndExtra = 0;
81 wc.hInstance = hInstance;
82 wc.hIcon = 0;
83 wc.hCursor = 0;
84 wc.hbrBackground = 0;
85 wc.lpszMenuName = 0;
86 wc.lpszClassName = szWndName;
87
88 RegisterClass(&wc);
89
90 /* TaskbarCreated is sent to a window when it should re-add its tray icons */
91 g_traycreatedmsg = RegisterWindowMessage("TaskbarCreated");
92
93 g_hwndTrayX = CreateWindow(szWndName, szWndName,
94 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
95 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
96
97 ShowWindow(g_hwndTrayX, SW_HIDE);
98 UpdateWindow(g_hwndTrayX);
99
100 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
101
102 return g_hwndTrayX;
103
104 }
105
106
107 /*********************************************************************
108 *
109 * Function : TraySetIcon
110 *
111 * Description : Sets the tray icon to the specified shape.
112 *
113 * Parameters :
114 * 1 : hwnd = handle of the systray window
115 * 2 : uID = user message number to notify systray window
116 * 3 : hicon = set the current icon to this handle
117 *
118 * Returns : Same value as `Shell_NotifyIcon'.
119 *
120 *********************************************************************/
TraySetIcon(HWND hwnd,UINT uID,HICON hicon)121 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
122 {
123 NOTIFYICONDATA nid;
124
125 memset(&nid, 0, sizeof(nid));
126
127 nid.cbSize = sizeof(nid);
128 nid.hWnd = hwnd;
129 nid.uID = uID;
130 nid.uFlags = NIF_ICON;
131 nid.uCallbackMessage = 0;
132 nid.hIcon = hicon;
133
134 return(Shell_NotifyIcon(NIM_MODIFY, &nid));
135
136 }
137
138
139 /*********************************************************************
140 *
141 * Function : TrayAddIcon
142 *
143 * Description : Adds a tray icon.
144 *
145 * Parameters :
146 * 1 : hwnd = handle of the systray window
147 * 2 : uID = user message number to notify systray window
148 * 3 : hicon = handle of icon to add to systray window
149 * 4 : pszToolTip = tool tip when mouse hovers over systray window
150 *
151 * Returns : Same as `Shell_NotifyIcon'.
152 *
153 *********************************************************************/
TrayAddIcon(HWND hwnd,UINT uID,HICON hicon,const char * pszToolTip)154 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
155 {
156 NOTIFYICONDATA nid;
157
158 memset(&nid, 0, sizeof(nid));
159
160 nid.cbSize = sizeof(nid);
161 nid.hWnd = hwnd;
162 nid.uID = uID;
163 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
164 nid.uCallbackMessage = WM_TRAYMSG;
165 nid.hIcon = hicon;
166
167 if (pszToolTip)
168 {
169 strcpy(nid.szTip, pszToolTip);
170 }
171
172 return(Shell_NotifyIcon(NIM_ADD, &nid));
173
174 }
175
176
177 /*********************************************************************
178 *
179 * Function : TrayDeleteIcon
180 *
181 * Description : Deletes a tray icon.
182 *
183 * Parameters :
184 * 1 : hwnd = handle of the systray window
185 * 2 : uID = user message number to notify systray window
186 *
187 * Returns : Same as `Shell_NotifyIcon'.
188 *
189 *********************************************************************/
TrayDeleteIcon(HWND hwnd,UINT uID)190 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
191 {
192 NOTIFYICONDATA nid;
193
194 memset(&nid, 0, sizeof(nid));
195
196 nid.cbSize = sizeof(nid);
197 nid.hWnd = hwnd;
198 nid.uID = uID;
199
200 return(Shell_NotifyIcon(NIM_DELETE, &nid));
201
202 }
203
204
205 /*********************************************************************
206 *
207 * Function : TrayProc
208 *
209 * Description : Call back procedure processes tray messages.
210 *
211 * Parameters :
212 * 1 : hwnd = handle of the systray window
213 * 2 : msg = message number
214 * 3 : wParam = first param for this message
215 * 4 : lParam = next param for this message
216 *
217 * Returns : Appropriate M$ window message handler codes.
218 *
219 *********************************************************************/
TrayProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)220 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
221 {
222 switch (msg)
223 {
224 case WM_CREATE:
225 return 0;
226
227 case WM_CLOSE:
228 PostQuitMessage(0);
229 return 0;
230
231 case WM_TRAYMSG:
232 {
233 /* UINT uID = (UINT) wParam; */
234 UINT uMouseMsg = (UINT) lParam;
235
236 if (uMouseMsg == WM_RBUTTONDOWN)
237 {
238 POINT pt;
239 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
240 GetCursorPos(&pt);
241 SetForegroundWindow(g_hwndLogFrame);
242 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
243 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0);
244 }
245 else if (uMouseMsg == WM_LBUTTONDBLCLK)
246 {
247 ShowLogWindow(TRUE);
248 }
249 }
250 return 0;
251
252 default:
253
254 if (msg == g_traycreatedmsg)
255 {
256 TrayAddIcon(g_hwndTrayX, 1, g_hiconApp, "Privoxy");
257 }
258 break;
259 }
260
261 return DefWindowProc(hwnd, msg, wParam, lParam);
262
263 }
264
265
266 #endif /* ndef _WIN_CONSOLE - entire file */
267
268 /*
269 Local Variables:
270 tab-width: 3
271 end:
272 */
273