refactored a bit more to clean up WinMain()
git-svn-id: http://apu.dw.local/svnusers/JoshHoltrop/pppc/trunk@49 8131a0b2-b21c-1c47-bd6a-f003126495bd
This commit is contained in:
parent
05ff66a313
commit
6714dab3e2
112
pppc.cc
112
pppc.cc
@ -11,11 +11,7 @@
|
||||
#include "pppc.h"
|
||||
using namespace std;
|
||||
|
||||
#define APP_NAME "Parallel Port Power Controller"
|
||||
#define WM_ICON_NOTIFY (WM_APP + 42)
|
||||
|
||||
LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
void addMenuItem(HMENU hMenu, CHAR * itemstr, WORD id);
|
||||
static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
int WinMain(
|
||||
HINSTANCE hInstance,
|
||||
@ -23,57 +19,25 @@ int WinMain(
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
/* parse command line into an array like sane operating systems supply */
|
||||
vector<string> args = parseCmdLine(lpCmdLine);
|
||||
|
||||
PPPC myPPPC(hInstance);
|
||||
|
||||
BOOL bRet;
|
||||
MSG msg;
|
||||
bool running = true;
|
||||
while(running)
|
||||
const char * config_file = NULL;
|
||||
/* process command line arguments */
|
||||
for (int sz = args.size(), i = 0; i < sz; i++)
|
||||
{
|
||||
bRet = GetMessage(&msg, NULL, 0, 0);
|
||||
if (bRet == -1 || bRet == 0)
|
||||
if (args[i][0] != '-')
|
||||
{
|
||||
break;
|
||||
}
|
||||
switch (msg.message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
case WM_DESTROY:
|
||||
case WM_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
case WM_WTSSESSION_CHANGE:
|
||||
if (msg.wParam == WTS_SESSION_LOGON
|
||||
|| msg.wParam == WTS_SESSION_UNLOCK)
|
||||
{
|
||||
pport_write(0xFF);
|
||||
}
|
||||
if (msg.wParam == WTS_SESSION_LOGOFF
|
||||
|| msg.wParam == WTS_SESSION_LOCK)
|
||||
{
|
||||
pport_write(0x0);
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(msg.wParam)) /* menu entry index */
|
||||
{
|
||||
case 0: /* exit */
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
config_file = args[i].c_str();
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
PPPC myPPPC(hInstance, config_file);
|
||||
|
||||
return myPPPC.mainLoop();
|
||||
}
|
||||
|
||||
LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
static LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
switch (message)
|
||||
{
|
||||
@ -82,10 +46,10 @@ LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_CREATE:
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
DestroyWindow(hWnd);
|
||||
::DestroyWindow(hWnd);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
::PostQuitMessage(0);
|
||||
break;
|
||||
case WM_ICON_NOTIFY:
|
||||
if (wParam == 0)
|
||||
@ -102,7 +66,7 @@ LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
// BUGFIX: See "PRB: Menus for Notification Icons Don't Work Correctly"
|
||||
::PostMessage(hWnd, WM_NULL, 0, 0);
|
||||
|
||||
DestroyMenu(hMenu);
|
||||
::DestroyMenu(hMenu);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -185,6 +149,54 @@ PPPC::PPPC(HINSTANCE hInstance, const char * config_file)
|
||||
|
||||
}
|
||||
|
||||
BOOL PPPC::mainLoop()
|
||||
{
|
||||
BOOL bRet;
|
||||
MSG msg;
|
||||
bool running = true;
|
||||
while(running)
|
||||
{
|
||||
bRet = GetMessage(&msg, NULL, 0, 0);
|
||||
if (bRet == -1 || bRet == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
switch (msg.message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
break;
|
||||
case WM_CLOSE:
|
||||
case WM_DESTROY:
|
||||
case WM_QUIT:
|
||||
running = false;
|
||||
break;
|
||||
case WM_WTSSESSION_CHANGE:
|
||||
if (msg.wParam == WTS_SESSION_LOGON
|
||||
|| msg.wParam == WTS_SESSION_UNLOCK)
|
||||
{
|
||||
pport_write(0xFF);
|
||||
}
|
||||
if (msg.wParam == WTS_SESSION_LOGOFF
|
||||
|| msg.wParam == WTS_SESSION_LOCK)
|
||||
{
|
||||
pport_write(0x0);
|
||||
}
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(msg.wParam)) /* menu entry index */
|
||||
{
|
||||
case 0: /* exit */
|
||||
running = false;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
PPPC::~PPPC()
|
||||
{
|
||||
/* delete the tray icon */
|
||||
|
7
pppc.h
7
pppc.h
@ -2,15 +2,22 @@
|
||||
#ifndef PPPC_H
|
||||
#define PPPC_H
|
||||
|
||||
#define APP_NAME "Parallel Port Power Controller"
|
||||
#define WM_ICON_NOTIFY (WM_APP + 42)
|
||||
|
||||
class PPPC
|
||||
{
|
||||
public:
|
||||
PPPC(HINSTANCE hInstance, const char * config_file = NULL);
|
||||
~PPPC();
|
||||
BOOL mainLoop();
|
||||
|
||||
protected:
|
||||
HWND m_hWnd;
|
||||
NOTIFYICONDATA m_nid;
|
||||
};
|
||||
|
||||
/* non class-member functions */
|
||||
void addMenuItem(HMENU hMenu, CHAR * itemstr, WORD id);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user