1 /*********************************************************************
3 * File : $Source: /cvsroot/ijbswa/current/w32taskbar.c,v $
5 * Purpose : Functions for creating, setting and destroying the
8 * Copyright : Written by and Copyright (C) 2001-2002 members of
9 * the Privoxy team. http://www.privoxy.org/
11 * Written by and Copyright (C) 1999 Adam Lock
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.
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.
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.
32 *********************************************************************/
44 #include "w32taskbar.h"
48 #ifndef _WIN_CONSOLE /* entire file */
50 #define WM_TRAYMSG WM_USER+1
52 static HMENU g_hmenuTray;
53 static HWND g_hwndTrayX;
54 static UINT g_traycreatedmsg;
56 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
59 /*********************************************************************
61 * Function : CreateTrayWindow
63 * Description : Creates and returns the invisible window responsible
64 * for processing tray messages.
67 * 1 : hInstance = instance handle of this application
69 * Returns : Handle of the systray window.
71 *********************************************************************/
72 HWND CreateTrayWindow(HINSTANCE hInstance)
75 static const char *szWndName = "PrivoxyTrayWindow";
78 wc.lpfnWndProc = TrayProc;
81 wc.hInstance = hInstance;
86 wc.lpszClassName = szWndName;
90 /* TaskbarCreated is sent to a window when it should re-add its tray icons */
91 g_traycreatedmsg = RegisterWindowMessage("TaskbarCreated");
93 g_hwndTrayX = CreateWindow(szWndName, szWndName,
94 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
95 CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
97 ShowWindow(g_hwndTrayX, SW_HIDE);
98 UpdateWindow(g_hwndTrayX);
100 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
107 /*********************************************************************
109 * Function : TraySetIcon
111 * Description : Sets the tray icon to the specified shape.
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
118 * Returns : Same value as `Shell_NotifyIcon'.
120 *********************************************************************/
121 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
125 memset(&nid, 0, sizeof(nid));
127 nid.cbSize = sizeof(nid);
130 nid.uFlags = NIF_ICON;
131 nid.uCallbackMessage = 0;
134 return(Shell_NotifyIcon(NIM_MODIFY, &nid));
139 /*********************************************************************
141 * Function : TrayAddIcon
143 * Description : Adds a tray icon.
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
151 * Returns : Same as `Shell_NotifyIcon'.
153 *********************************************************************/
154 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
158 memset(&nid, 0, sizeof(nid));
160 nid.cbSize = sizeof(nid);
163 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
164 nid.uCallbackMessage = WM_TRAYMSG;
169 strcpy(nid.szTip, pszToolTip);
172 return(Shell_NotifyIcon(NIM_ADD, &nid));
177 /*********************************************************************
179 * Function : TrayDeleteIcon
181 * Description : Deletes a tray icon.
184 * 1 : hwnd = handle of the systray window
185 * 2 : uID = user message number to notify systray window
187 * Returns : Same as `Shell_NotifyIcon'.
189 *********************************************************************/
190 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
194 memset(&nid, 0, sizeof(nid));
196 nid.cbSize = sizeof(nid);
200 return(Shell_NotifyIcon(NIM_DELETE, &nid));
205 /*********************************************************************
207 * Function : TrayProc
209 * Description : Call back procedure processes tray messages.
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
217 * Returns : Appropriate M$ window message handler codes.
219 *********************************************************************/
220 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
233 /* UINT uID = (UINT) wParam; */
234 UINT uMouseMsg = (UINT) lParam;
236 if (uMouseMsg == WM_RBUTTONDOWN)
239 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
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);
245 else if (uMouseMsg == WM_LBUTTONDBLCLK)
254 if (msg == g_traycreatedmsg)
256 TrayAddIcon(g_hwndTrayX, 1, g_hiconApp, "Privoxy");
261 return DefWindowProc(hwnd, msg, wParam, lParam);
266 #endif /* ndef _WIN_CONSOLE - entire file */