1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.9 2006/07/18 14:48:48 david__schmidt Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/w32taskbar.c,v $
6 * Purpose : Functions for creating, setting and destroying the
9 * Copyright : Written by and Copyright (C) 2001-2002 members of
10 * the Privoxy team. http://www.privoxy.org/
12 * Written by and Copyright (C) 1999 Adam Lock
15 * This program is free software; you can redistribute it
16 * and/or modify it under the terms of the GNU General
17 * Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at
19 * your option) any later version.
21 * This program is distributed in the hope that it will
22 * be useful, but WITHOUT ANY WARRANTY; without even the
23 * implied warranty of MERCHANTABILITY or FITNESS FOR A
24 * PARTICULAR PURPOSE. See the GNU General Public
25 * License for more details.
27 * The GNU General Public License should be included with
28 * this file. If not, you can view it at
29 * http://www.gnu.org/copyleft/gpl.html
30 * or write to the Free Software Foundation, Inc., 59
31 * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 * $Log: w32taskbar.c,v $
35 * Revision 1.9 2006/07/18 14:48:48 david__schmidt
36 * Reorganizing the repository: swapping out what was HEAD (the old 3.1 branch)
37 * with what was really the latest development (the v_3_0_branch branch)
39 * Revision 1.7.2.2 2003/03/19 21:27:42 gliptak
40 * Corrected compilation error/typo
42 * Revision 1.7.2.1 2002/11/20 14:39:32 oes
43 * Applied patch by Mattes Dolak which adds re-creation of the win32 taskbar
44 * icon on reception of the "TaskbarCreated" window message.
46 * Revision 1.7 2002/03/31 17:19:00 jongfoster
47 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
49 * Revision 1.6 2002/03/26 22:57:10 jongfoster
50 * Web server name should begin www.
52 * Revision 1.5 2002/03/24 12:03:47 jongfoster
55 * Revision 1.4 2001/11/16 00:46:31 jongfoster
56 * Fixing compiler warnings
58 * Revision 1.3 2001/05/22 18:56:28 oes
61 * Revision 1.2 2001/05/20 15:07:54 jongfoster
62 * File is now ignored if _WIN_CONSOLE is defined.
64 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
65 * Initial import of version 2.9.3 source tree
68 *********************************************************************/
80 #include "w32taskbar.h"
84 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
86 #ifndef _WIN_CONSOLE /* entire file */
88 #define WM_TRAYMSG WM_USER+1
90 static HMENU g_hmenuTray;
91 static HWND g_hwndTrayX;
92 static UINT g_traycreatedmsg;
94 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
97 /*********************************************************************
99 * Function : CreateTrayWindow
101 * Description : Creates and returns the invisible window responsible
102 * for processing tray messages.
105 * 1 : hInstance = instance handle of this application
107 * Returns : Handle of the systray window.
109 *********************************************************************/
110 HWND CreateTrayWindow(HINSTANCE hInstance)
113 static const char *szWndName = "PrivoxyTrayWindow";
116 wc.lpfnWndProc = TrayProc;
119 wc.hInstance = hInstance;
122 wc.hbrBackground = 0;
124 wc.lpszClassName = szWndName;
128 /* TaskbarCreated is sent to a window when it should re-add its tray icons */
129 g_traycreatedmsg = RegisterWindowMessage("TaskbarCreated");
131 g_hwndTrayX = CreateWindow(szWndName, szWndName,
132 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
133 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
135 ShowWindow(g_hwndTrayX, SW_HIDE);
136 UpdateWindow(g_hwndTrayX);
138 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
145 /*********************************************************************
147 * Function : TraySetIcon
149 * Description : Sets the tray icon to the specified shape.
152 * 1 : hwnd = handle of the systray window
153 * 2 : uID = user message number to notify systray window
154 * 3 : hicon = set the current icon to this handle
156 * Returns : Same value as `Shell_NotifyIcon'.
158 *********************************************************************/
159 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
163 memset(&nid, 0, sizeof(nid));
165 nid.cbSize = sizeof(nid);
168 nid.uFlags = NIF_ICON;
169 nid.uCallbackMessage = 0;
172 return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
177 /*********************************************************************
179 * Function : TrayAddIcon
181 * Description : Adds a tray icon.
184 * 1 : hwnd = handle of the systray window
185 * 2 : uID = user message number to notify systray window
186 * 3 : hicon = handle of icon to add to systray window
187 * 4 : pszToolTip = tool tip when mouse hovers over systray window
189 * Returns : Same as `Shell_NotifyIcon'.
191 *********************************************************************/
192 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
196 memset(&nid, 0, sizeof(nid));
198 nid.cbSize = sizeof(nid);
201 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
202 nid.uCallbackMessage = WM_TRAYMSG;
207 strcpy(nid.szTip, pszToolTip);
210 return( Shell_NotifyIcon(NIM_ADD, &nid) );
215 /*********************************************************************
217 * Function : TrayDeleteIcon
219 * Description : Deletes a tray icon.
222 * 1 : hwnd = handle of the systray window
223 * 2 : uID = user message number to notify systray window
225 * Returns : Same as `Shell_NotifyIcon'.
227 *********************************************************************/
228 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
232 memset(&nid, 0, sizeof(nid));
234 nid.cbSize = sizeof(nid);
238 return( Shell_NotifyIcon(NIM_DELETE, &nid) );
243 /*********************************************************************
245 * Function : TrayProc
247 * Description : Call back procedure processes tray messages.
250 * 1 : hwnd = handle of the systray window
251 * 2 : msg = message number
252 * 3 : wParam = first param for this message
253 * 4 : lParam = next param for this message
255 * Returns : Appropriate M$ window message handler codes.
257 *********************************************************************/
258 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
271 /* UINT uID = (UINT) wParam; */
272 UINT uMouseMsg = (UINT) lParam;
274 if (uMouseMsg == WM_RBUTTONDOWN)
277 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
279 SetForegroundWindow(g_hwndLogFrame);
280 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
281 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
283 else if (uMouseMsg == WM_LBUTTONDBLCLK)
292 if (msg == g_traycreatedmsg)
294 TrayAddIcon(g_hwndTrayX, 1, g_hiconApp, "Privoxy");
299 return DefWindowProc(hwnd, msg, wParam, lParam);
304 #endif /* ndef _WIN_CONSOLE - entire file */