1 const char w32taskbar_rcs[] = "$Id: w32taskbar.c,v 1.3 2001/05/22 18:56:28 oes 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 the SourceForge
10 * IJBSWA team. http://ijbswa.sourceforge.net
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.3 2001/05/22 18:56:28 oes
38 * Revision 1.2 2001/05/20 15:07:54 jongfoster
39 * File is now ignored if _WIN_CONSOLE is defined.
41 * Revision 1.1.1.1 2001/05/15 13:59:08 oes
42 * Initial import of version 2.9.3 source tree
45 *********************************************************************/
54 #include "w32taskbar.h"
58 const char w32taskbar_h_rcs[] = W32TASKBAR_H_VERSION;
60 #ifndef _WIN_CONSOLE /* entire file */
62 #define WM_TRAYMSG WM_USER+1
64 static HMENU g_hmenuTray;
65 static HWND g_hwndTrayX;
67 static LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
70 /*********************************************************************
72 * Function : CreateTrayWindow
74 * Description : Creates and returns the invisible window responsible for processing tray messages.
77 * 1 : hInstance = instance handle of this application
79 * Returns : Handle of the systray window.
81 *********************************************************************/
82 HWND CreateTrayWindow(HINSTANCE hInstance)
85 static const char *szWndName = "JunkbusterTrayWindow";
88 wc.lpfnWndProc = TrayProc;
91 wc.hInstance = hInstance;
96 wc.lpszClassName = szWndName;
100 g_hwndTrayX = CreateWindow(szWndName, szWndName,
101 WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
102 CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
104 ShowWindow(g_hwndTrayX, SW_HIDE);
105 UpdateWindow(g_hwndTrayX);
107 g_hmenuTray = LoadMenu(hInstance, MAKEINTRESOURCE(IDR_TRAYMENU));
114 /*********************************************************************
116 * Function : TraySetIcon
118 * Description : Sets the tray icon to the specified shape.
121 * 1 : hwnd = handle of the systray window
122 * 2 : uID = user message number to notify systray window
123 * 3 : hicon = set the current icon to this handle
125 * Returns : Same value as `Shell_NotifyIcon'.
127 *********************************************************************/
128 BOOL TraySetIcon(HWND hwnd, UINT uID, HICON hicon)
132 memset(&nid, 0, sizeof(nid));
134 nid.cbSize = sizeof(nid);
137 nid.uFlags = NIF_ICON;
138 nid.uCallbackMessage = 0;
141 return( Shell_NotifyIcon(NIM_MODIFY, &nid) );
146 /*********************************************************************
148 * Function : TrayAddIcon
150 * Description : Adds a tray icon.
153 * 1 : hwnd = handle of the systray window
154 * 2 : uID = user message number to notify systray window
155 * 3 : hicon = handle of icon to add to systray window
156 * 4 : pszToolTip = tool tip when mouse hovers over systray window
158 * Returns : Same as `Shell_NotifyIcon'.
160 *********************************************************************/
161 BOOL TrayAddIcon(HWND hwnd, UINT uID, HICON hicon, const char *pszToolTip)
165 memset(&nid, 0, sizeof(nid));
167 nid.cbSize = sizeof(nid);
170 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
171 nid.uCallbackMessage = WM_TRAYMSG;
176 strcpy(nid.szTip, pszToolTip);
179 return( Shell_NotifyIcon(NIM_ADD, &nid) );
184 /*********************************************************************
186 * Function : TrayDeleteIcon
188 * Description : Deletes a tray icon.
191 * 1 : hwnd = handle of the systray window
192 * 2 : uID = user message number to notify systray window
194 * Returns : Same as `Shell_NotifyIcon'.
196 *********************************************************************/
197 BOOL TrayDeleteIcon(HWND hwnd, UINT uID)
201 memset(&nid, 0, sizeof(nid));
203 nid.cbSize = sizeof(nid);
207 return( Shell_NotifyIcon(NIM_DELETE, &nid) );
212 /*********************************************************************
214 * Function : TrayProc
216 * Description : Call back procedure processes tray messages.
219 * 1 : hwnd = handle of the systray window
220 * 2 : msg = message number
221 * 3 : wParam = first param for this message
222 * 4 : lParam = next param for this message
224 * Returns : Appropriate M$ window message handler codes.
226 *********************************************************************/
227 LRESULT CALLBACK TrayProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
240 /* UINT uID = (UINT) wParam; */
241 UINT uMouseMsg = (UINT) lParam;
243 if (uMouseMsg == WM_RBUTTONDOWN)
246 HMENU hmenu = GetSubMenu(g_hmenuTray,0);
248 SetForegroundWindow(g_hwndLogFrame);
249 TrackPopupMenu(hmenu, TPM_LEFTALIGN | TPM_TOPALIGN, pt.x, pt.y, 0, g_hwndLogFrame, NULL);
250 PostMessage(g_hwndLogFrame, WM_NULL, 0, 0 ) ;
252 else if (uMouseMsg == WM_LBUTTONDBLCLK)
264 return DefWindowProc(hwnd, msg, wParam, lParam);
269 #endif /* ndef _WIN_CONSOLE - entire file */