1 // This file has been adapted to the Win32 version of Apcupsd
2 // by Kern E. Sibbald. Many thanks to ATT and James Weatherall,
3 // the original author, for providing an excellent template.
5 // Rewrite/Refactoring by Adam Kropelin
7 // Copyright (2007) Adam D. Kropelin
8 // Copyright (2000) Kern E. Sibbald
11 // This class handles creation of a system-tray icon & menu
19 #include "winevents.h"
20 #include "winconfig.h"
25 // Forward declarations
29 // The tray menu class itself
33 upsMenu(HINSTANCE appinst
, MonitorConfig
&mcfg
, BalloonMgr
*balmgr
,
34 InstanceManager
*instmgr
);
38 void Reconfigure(const MonitorConfig
&mcfg
);
45 void UpdateTrayIcon();
46 void SendTrayMsg(DWORD msg
);
48 // Message handler for the tray window
49 static LRESULT CALLBACK
WndProc(
50 HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
51 LRESULT
WndProcess(HWND hwnd
, UINT iMsg
, WPARAM wParam
, LPARAM lParam
);
53 // Fetch UPS status info
54 bool FetchStatus(int &battstat
, astring
&statstr
, astring
&upsname
);
56 // Thread to poll for UPS status changes
57 static DWORD WINAPI
StatusPollThread(LPVOID param
);
59 HWND _hwnd
; // Window handle
60 HMENU _hmenu
; // Menu handle
61 HMENU _hsubmenu
; // Submenu handle
62 StatMgr
*_statmgr
; // Manager for UPS stats
63 HANDLE _thread
; // Handle to status polling thread
64 HANDLE _wait
; // Handle to wait mutex
65 astring _upsname
; // Cache UPS name
66 astring _laststatus
; // Cache previous status string
67 BalloonMgr
*_balmgr
; // Balloon tip manager
68 UINT _tbcreated_msg
; // Id of TaskbarCreated message
69 HINSTANCE _appinst
; // Application instance handle
70 MonitorConfig _config
; // Configuration (host, port, etc.)
71 bool _runthread
; // Run the poll thread?
72 amutex _mutex
; // Lock to protect statmgr
75 InstanceManager
*_instmgr
;
77 // Dialogs for About, Status, Config, and Events