findlanabyname-20040228
[openafs.git] / src / WINNT / client_creds / trayicon.cpp
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 extern "C" {
11 #include <afs/param.h>
12 #include <afs/stds.h>
13 }
14
15 #include "afscreds.h"
16
17
18
19 /*
20  * ROUTINES ___________________________________________________________________
21  *
22  */
23
24 void ChangeTrayIcon (int nim)
25 {
26    static BOOL fAdded = FALSE;
27    static BOOL fDeleted = FALSE;
28    if ((nim == NIM_MODIFY) && (!fAdded))
29       nim = NIM_ADD;
30    if ((nim == NIM_MODIFY) && (fDeleted))
31       return;
32
33    if ((nim != NIM_DELETE) || (IsWindow (g.hMain)))
34       {
35       static HICON ICON_CREDS_YES = TaLocale_LoadIcon (IDI_CREDS_YES);
36       static HICON ICON_CREDS_NO  = TaLocale_LoadIcon (IDI_CREDS_NO);
37
38       size_t iExpired = Main_FindExpiredCreds();
39
40       NOTIFYICONDATA nid;
41       memset (&nid, 0x00, sizeof(NOTIFYICONDATA));
42       nid.cbSize = sizeof(NOTIFYICONDATA);
43       nid.hWnd = g.hMain;
44       nid.uID = 0;
45       nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
46       nid.uCallbackMessage = WM_TRAYICON;
47       lock_ObtainMutex(&g.credsLock);
48       nid.hIcon = ((g.cCreds != 0) && (iExpired == (size_t)-1)) ? ICON_CREDS_YES : ICON_CREDS_NO;
49       lock_ReleaseMutex(&g.credsLock);
50       GetString (nid.szTip, (g.fIsWinNT) ? IDS_TOOLTIP : IDS_TOOLTIP_95);
51       Shell_NotifyIcon (nim, &nid);
52       }
53
54    if (nim == NIM_ADD)
55       fAdded = TRUE;
56    if (nim == NIM_DELETE)
57       fDeleted = TRUE;
58 }
59