added capability to update menu items and add/remove checkmarks, will be useful when we start processing mode changes

git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@59 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
joshholtrop 2009-08-25 19:22:31 +00:00
parent 119f5a74b6
commit 5097674f3b
2 changed files with 45 additions and 3 deletions

40
pppc.cc
View File

@ -17,6 +17,8 @@ using namespace std;
(((var) >> (position)) & 0x1) (((var) >> (position)) & 0x1)
static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
const char * PPPC::ConfigEntryCaptions[3] =
{"Auto", "Manual: Off", "Manual: On"};
static HMENU g_popupMenu; static HMENU g_popupMenu;
@ -110,6 +112,26 @@ HMENU addMenuSubMenu(HMENU hMenu, const CHAR * itemstr, WORD id)
return submenu; return submenu;
} }
void updateMenuInfo(HMENU hMenu, int index, const CHAR * itemstr, WORD id, bool checked)
{
MENUITEMINFO mii;
memset(&mii, 0, sizeof(mii));
mii.cbSize = sizeof(mii);
mii.fMask = MIIM_STRING | MIIM_ID;
if (checked)
{
mii.fMask |= MIIM_STATE;
mii.fState = MFS_CHECKED;
}
mii.wID = id;
mii.dwTypeData = (CHAR *) itemstr;
mii.cch = strlen(mii.dwTypeData);
if (::SetMenuItemInfo(hMenu, index, TRUE, &mii) == 0)
{
cerr << "Warning: InsertMenuItem(): " << GetLastError() << endl;
}
}
PPPC::PPPC(HINSTANCE hInstance, const char * config_file) PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
{ {
m_pins = 0u; m_pins = 0u;
@ -168,9 +190,12 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
HMENU submenu = addMenuSubMenu(m_popupMenu, HMENU submenu = addMenuSubMenu(m_popupMenu,
m_config.entries[i].name.c_str(), m_config.entries[i].name.c_str(),
(config_id << 8)); (config_id << 8));
addMenuItem(submenu, "Auto", (config_id << 8) | 0x1); addMenuItem(submenu, ConfigEntryCaptions[0], (config_id << 8) | 0x1);
addMenuItem(submenu, "Manual: Off", (config_id << 8) | 0x2); addMenuItem(submenu, ConfigEntryCaptions[1], (config_id << 8) | 0x2);
addMenuItem(submenu, "Manual: On", (config_id << 8) | 0x3); addMenuItem(submenu, ConfigEntryCaptions[2], (config_id << 8) | 0x3);
m_menus.push_back(submenu);
m_modes.push_back(AUTO);
updateConfigMenus(i);
} }
/* Create the notify icon data */ /* Create the notify icon data */
@ -193,6 +218,15 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
session_notification_enable(m_hWnd); session_notification_enable(m_hWnd);
} }
void PPPC::updateConfigMenus(int i)
{
for (int index = 0; index < 3; index++)
{
updateMenuInfo(m_menus[i], index, ConfigEntryCaptions[index],
(((i + 1) << 8) | (index + 1)), index == m_modes[i]);
}
}
BOOL PPPC::mainLoop() BOOL PPPC::mainLoop()
{ {
BOOL bRet; BOOL bRet;

8
pppc.h
View File

@ -3,6 +3,7 @@
#define PPPC_H #define PPPC_H
#include "Config.h" #include "Config.h"
#include <vector>
#define APP_NAME "Parallel Port Power Controller" #define APP_NAME "Parallel Port Power Controller"
#define WM_ICON_NOTIFY (WM_APP + 42) #define WM_ICON_NOTIFY (WM_APP + 42)
@ -10,6 +11,9 @@
class PPPC class PPPC
{ {
public: public:
enum ConfigEntryMode { AUTO, MANUAL_OFF, MANUAL_ON };
static const char * ConfigEntryCaptions[3];
PPPC(HINSTANCE hInstance, const char * config_file = NULL); PPPC(HINSTANCE hInstance, const char * config_file = NULL);
~PPPC(); ~PPPC();
BOOL mainLoop(); BOOL mainLoop();
@ -20,6 +24,7 @@ class PPPC
void event_lock(); void event_lock();
void event_unlock(); void event_unlock();
void update_pins(); void update_pins();
void updateConfigMenus(int i);
Config m_config; Config m_config;
HWND m_hWnd; HWND m_hWnd;
@ -27,10 +32,13 @@ class PPPC
unsigned char m_pins; unsigned char m_pins;
unsigned char m_previous_pins; unsigned char m_previous_pins;
HMENU m_popupMenu; HMENU m_popupMenu;
std::vector<HMENU> m_menus;
std::vector<ConfigEntryMode> m_modes;
}; };
/* non class-member functions */ /* non class-member functions */
void addMenuItem(HMENU hMenu, const CHAR * itemstr, WORD id); void addMenuItem(HMENU hMenu, const CHAR * itemstr, WORD id);
HMENU addMenuSubMenu(HMENU hMenu, const CHAR * itemstr, WORD id); HMENU addMenuSubMenu(HMENU hMenu, const CHAR * itemstr, WORD id);
void updateMenuInfo(HMENU hMenu, int index, const CHAR * itemstr, WORD id, bool checked);
#endif #endif