1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 2.0 2002/06/04 14:34:21 jongfoster Exp $";
2 /*********************************************************************
4 * File : $Source: /cvsroot/ijbswa/current/src/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 2.0 2002/06/04 14:34:21 jongfoster
36 * Moving source files to src/
38 * Revision 1.7 2002/03/31 17:19:00 jongfoster
39 * Win32 only: Enabling STRICT to fix a VC++ compile warning.
41 * Revision 1.6 2002/03/26 22:57:10 jongfoster
42 * Web server name should begin www.
44 * Revision 1.5 2002/03/24 12:03:47 jongfoster
47 * Revision 1.4 2001/11/16 00:46:31 jongfoster
48 * Fixing compiler warnings
50 * Revision 1.3 2001/05/22 18:56:28 oes
53 * Revision 1.2 2001/05/20 15:07:54 jongfoster
54 * File is now ignored if _WIN_CONSOLE is defined.
56 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
57 * Initial import of version 2.9.3 source tree
60 *********************************************************************/
72 #include "w32taskbar.h"
76 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
78 #ifndef _WIN_CONSOLE /* entire file */
81 * Our custom message ID.
83 #define WM_TRAYMSG WM_USER+1
86 * The menu handle for the tray icon's pop-up menu.
88 static HMENU g_hmenuTray;
91 * The invisible window responsible for processing tray messages.
93 static HWND g_hwndTrayX;
95 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
98 /*********************************************************************
100 * Function : CreateTrayWindow
102 * Description : Creates and returns the invisible window responsible
103 * for processing tray messages.
106 * 1 : hInstance = instance handle of this application
108 * Returns : Handle of the systray window.
110 *********************************************************************/
111 HWND CreateTrayWindow(HINSTANCE hInstance)
114 static const char *szWndName = "PrivoxyTrayWindow";
117 wc.lpfnWndProc = TrayProc;
120 wc.hInstance = hInstance;
123 wc.hbrBackground = 0;
125 wc.lpszClassName = szWndName;
129 g_hwndTrayX = CreateWindow(szWndName, szWndName,
130 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
131 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
133 ShowWindow(g_hwndTrayX, SW_HIDE);
134 UpdateWindow(g_hwndTrayX);
136 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
143 /*********************************************************************
145 * Function : TraySetIcon
147 * Description : Sets the tray icon to the specified shape.
150 * 1 : hwnd = handle of the systray window
151 * 2 : uID = user message number to notify systray window
152 * 3 : hicon = set the current icon to this handle
154 * Returns : Same value as `Shell_NotifyIcon'.
156 *********************************************************************/
157 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
161 memset(&nid, 0, sizeof(nid));
163 nid.cbSize = sizeof(nid);
166 nid.uFlags = NIF_ICON;
167 nid.uCallbackMessage = 0;
170 return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
175 /*********************************************************************
177 * Function : TrayAddIcon
179 * Description : Adds a tray icon.
182 * 1 : hwnd = handle of the systray window
183 * 2 : uID = user message number to notify systray window
184 * 3 : hicon = handle of icon to add to systray window
185 * 4 : pszToolTip = tool tip when mouse hovers over systray window
187 * Returns : Same as `Shell_NotifyIcon'.
189 *********************************************************************/
190 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
194 memset(&nid, 0, sizeof(nid));
196 nid.cbSize = sizeof(nid);
199 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
200 nid.uCallbackMessage = WM_TRAYMSG;
205 strcpy(nid.szTip, pszToolTip);
208 return( Shell_NotifyIcon(NIM_ADD, &nid) );
213 /*********************************************************************
215 * Function : TrayDeleteIcon
217 * Description : Deletes a tray icon.
220 * 1 : hwnd = handle of the systray window
221 * 2 : uID = user message number to notify systray window
223 * Returns : Same as `Shell_NotifyIcon'.
225 *********************************************************************/
226 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
230 memset(&nid, 0, sizeof(nid));
232 nid.cbSize = sizeof(nid);
236 return( Shell_NotifyIcon(NIM_DELETE, &nid) );
241 /*********************************************************************
243 * Function : TrayProc
245 * Description : Call back procedure processes tray messages.
248 * 1 : hwnd = handle of the systray window
249 * 2 : msg = message number
250 * 3 : wParam = first param for this message
251 * 4 : lParam = next param for this message
253 * Returns : Appropriate M$ window message handler codes.
255 *********************************************************************/
256 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
269 /* UINT uID = (UINT) wParam; */
270 UINT uMouseMsg = (UINT) lParam;
272 if (uMouseMsg == WM_RBUTTONDOWN)
275 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
277 SetForegroundWindow(g_hwndLogFrame);
278 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
279 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
281 else if (uMouseMsg == WM_LBUTTONDBLCLK)
293 return DefWindowProc(hwnd, msg, wParam, lParam);
298 #endif /* ndef _WIN_CONSOLE - entire file */