1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.11 2009/05/16 13:27:20 fabiankeil 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.
33 *********************************************************************/
45 #include "w32taskbar.h"
49 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
51 #ifndef _WIN_CONSOLE /* entire file */
53 #define WM_TRAYMSG WM_USER+1
55 static HMENU g_hmenuTray;
56 static HWND g_hwndTrayX;
57 static UINT g_traycreatedmsg;
59 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
62 /*********************************************************************
64 * Function : CreateTrayWindow
66 * Description : Creates and returns the invisible window responsible
67 * for processing tray messages.
70 * 1 : hInstance = instance handle of this application
72 * Returns : Handle of the systray window.
74 *********************************************************************/
75 HWND CreateTrayWindow(HINSTANCE hInstance)
78 static const char *szWndName = "PrivoxyTrayWindow";
81 wc.lpfnWndProc = TrayProc;
84 wc.hInstance = hInstance;
89 wc.lpszClassName = szWndName;
93 /* TaskbarCreated is sent to a window when it should re-add its tray icons */
94 g_traycreatedmsg = RegisterWindowMessage("TaskbarCreated");
96 g_hwndTrayX = CreateWindow(szWndName, szWndName,
97 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
98 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
100 ShowWindow(g_hwndTrayX, SW_HIDE);
101 UpdateWindow(g_hwndTrayX);
103 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
110 /*********************************************************************
112 * Function : TraySetIcon
114 * Description : Sets the tray icon to the specified shape.
117 * 1 : hwnd = handle of the systray window
118 * 2 : uID = user message number to notify systray window
119 * 3 : hicon = set the current icon to this handle
121 * Returns : Same value as `Shell_NotifyIcon'.
123 *********************************************************************/
124 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
128 memset(&nid, 0, sizeof(nid));
130 nid.cbSize = sizeof(nid);
133 nid.uFlags = NIF_ICON;
134 nid.uCallbackMessage = 0;
137 return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
142 /*********************************************************************
144 * Function : TrayAddIcon
146 * Description : Adds a tray icon.
149 * 1 : hwnd = handle of the systray window
150 * 2 : uID = user message number to notify systray window
151 * 3 : hicon = handle of icon to add to systray window
152 * 4 : pszToolTip = tool tip when mouse hovers over systray window
154 * Returns : Same as `Shell_NotifyIcon'.
156 *********************************************************************/
157 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
161 memset(&nid, 0, sizeof(nid));
163 nid.cbSize = sizeof(nid);
166 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
167 nid.uCallbackMessage = WM_TRAYMSG;
172 strcpy(nid.szTip, pszToolTip);
175 return( Shell_NotifyIcon(NIM_ADD, &nid) );
180 /*********************************************************************
182 * Function : TrayDeleteIcon
184 * Description : Deletes a tray icon.
187 * 1 : hwnd = handle of the systray window
188 * 2 : uID = user message number to notify systray window
190 * Returns : Same as `Shell_NotifyIcon'.
192 *********************************************************************/
193 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
197 memset(&nid, 0, sizeof(nid));
199 nid.cbSize = sizeof(nid);
203 return( Shell_NotifyIcon(NIM_DELETE, &nid) );
208 /*********************************************************************
210 * Function : TrayProc
212 * Description : Call back procedure processes tray messages.
215 * 1 : hwnd = handle of the systray window
216 * 2 : msg = message number
217 * 3 : wParam = first param for this message
218 * 4 : lParam = next param for this message
220 * Returns : Appropriate M$ window message handler codes.
222 *********************************************************************/
223 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
236 /* UINT uID = (UINT) wParam; */
237 UINT uMouseMsg = (UINT) lParam;
239 if (uMouseMsg == WM_RBUTTONDOWN)
242 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
244 SetForegroundWindow(g_hwndLogFrame);
245 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
246 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
248 else if (uMouseMsg == WM_LBUTTONDBLCLK)
257 if (msg == g_traycreatedmsg)
259 TrayAddIcon(g_hwndTrayX, 1, g_hiconApp, "Privoxy");
264 return DefWindowProc(hwnd, msg, wParam, lParam);
269 #endif /* ndef _WIN_CONSOLE - entire file */