UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / win32 / meter.cpp
blob8c0e13f8dabb9f5884f46924846fcc4f10079f36
1 /*
2 * Copyright (C) 2009 Adam Kropelin
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of version 2 of the GNU General
6 * Public License as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the Free
15 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
19 #include <windows.h>
20 #include <commctrl.h>
21 #include "meter.h"
23 Meter::Meter(HWND hwnd, UINT id, int warn, int critical, int level) :
24 _warn(warn),
25 _critical(critical),
26 _level(level)
28 _hwnd = GetDlgItem(hwnd, id);
31 void Meter::Set(int level)
33 if (level == _level)
34 return;
36 SendMessage(_hwnd, PBM_SETPOS, level, 0);
37 _level = level;
39 // Figure out bar color.
40 COLORREF color;
41 if (_warn > _critical)
43 // Low is critical
44 if (level > _warn)
45 color = GREEN;
46 else if (level > _critical)
47 color = YELLOW;
48 else
49 color = RED;
51 else
53 // High is critical
54 if (level >= _critical)
55 color = RED;
56 else if (level >= _warn)
57 color = YELLOW;
58 else
59 color = GREEN;
62 SendMessage(_hwnd, PBM_SETBARCOLOR, 0, color);