1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.7 2002/03/31 17:19:00 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/Attic/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.7 2002/03/31 17:19:00 jongfoster
36 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
38 * Revision 1.6 2002/03/26 22:57:10 jongfoster
39 * Web server name should begin www.
41 * Revision 1.5 2002/03/24 12:03:47 jongfoster
44 * Revision 1.4 2001/11/16 00:46:31 jongfoster
45 * Fixing compiler warnings
47 * Revision 1.3 2001/05/22 18:56:28 oes
50 * Revision 1.2 2001/05/20 15:07:54 jongfoster
51 * File is now ignored if _WIN_CONSOLE is defined.
53 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
54 * Initial import of version 2.9.3 source tree
57 *********************************************************************/
69 #include "w32taskbar.h"
73 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
75 #ifndef _WIN_CONSOLE /* entire file */
77 #define WM_TRAYMSG WM_USER+1
79 static HMENU g_hmenuTray;
80 static HWND g_hwndTrayX;
81 static UINT g_traycreatedmsg;
83 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
86 /*********************************************************************
88 * Function : CreateTrayWindow
90 * Description : Creates and returns the invisible window responsible
91 * for processing tray messages.
94 * 1 : hInstance = instance handle of this application
96 * Returns : Handle of the systray window.
98 *********************************************************************/
99 HWND CreateTrayWindow(HINSTANCE hInstance)
102 static const char *szWndName = "PrivoxyTrayWindow";
105 wc.lpfnWndProc = TrayProc;
108 wc.hInstance = hInstance;
111 wc.hbrBackground = 0;
113 wc.lpszClassName = szWndName;
117 /* TaskbarCreated is sent to a window when it should re-add its tray icons */
118 g_traycreatedmsg = RegisterWindowMessage("TaskbarCreated");
120 g_hwndTrayX = CreateWindow(szWndName, szWndName,
121 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
122 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
124 ShowWindow(g_hwndTrayX, SW_HIDE);
125 UpdateWindow(g_hwndTrayX);
127 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
134 /*********************************************************************
136 * Function : TraySetIcon
138 * Description : Sets the tray icon to the specified shape.
141 * 1 : hwnd = handle of the systray window
142 * 2 : uID = user message number to notify systray window
143 * 3 : hicon = set the current icon to this handle
145 * Returns : Same value as `Shell_NotifyIcon'.
147 *********************************************************************/
148 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
152 memset(&nid, 0, sizeof(nid));
154 nid.cbSize = sizeof(nid);
157 nid.uFlags = NIF_ICON;
158 nid.uCallbackMessage = 0;
161 return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
166 /*********************************************************************
168 * Function : TrayAddIcon
170 * Description : Adds a tray icon.
173 * 1 : hwnd = handle of the systray window
174 * 2 : uID = user message number to notify systray window
175 * 3 : hicon = handle of icon to add to systray window
176 * 4 : pszToolTip = tool tip when mouse hovers over systray window
178 * Returns : Same as `Shell_NotifyIcon'.
180 *********************************************************************/
181 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
185 memset(&nid, 0, sizeof(nid));
187 nid.cbSize = sizeof(nid);
190 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
191 nid.uCallbackMessage = WM_TRAYMSG;
196 strcpy(nid.szTip, pszToolTip);
199 return( Shell_NotifyIcon(NIM_ADD, &nid) );
204 /*********************************************************************
206 * Function : TrayDeleteIcon
208 * Description : Deletes a tray icon.
211 * 1 : hwnd = handle of the systray window
212 * 2 : uID = user message number to notify systray window
214 * Returns : Same as `Shell_NotifyIcon'.
216 *********************************************************************/
217 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
221 memset(&nid, 0, sizeof(nid));
223 nid.cbSize = sizeof(nid);
227 return( Shell_NotifyIcon(NIM_DELETE, &nid) );
232 /*********************************************************************
234 * Function : TrayProc
236 * Description : Call back procedure processes tray messages.
239 * 1 : hwnd = handle of the systray window
240 * 2 : msg = message number
241 * 3 : wParam = first param for this message
242 * 4 : lParam = next param for this message
244 * Returns : Appropriate M$ window message handler codes.
246 *********************************************************************/
247 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
260 /* UINT uID = (UINT) wParam; */
261 UINT uMouseMsg = (UINT) lParam;
263 if (uMouseMsg == WM_RBUTTONDOWN)
266 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
268 SetForegroundWindow(g_hwndLogFrame);
269 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
270 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
272 else if (uMouseMsg == WM_LBUTTONDBLCLK)
281 if (msg == g_traycreatedmsg)
283 TrayAddIcon(g_hwndTray, 1, g_hiconApp, "Privoxy");
288 return DefWindowProc(hwnd, msg, wParam, lParam);
293 #endif /* ndef _WIN_CONSOLE - entire file */