/****************************************************************************
* LEDMeter - Utility for driving an array of LEDs on the parallel port *
* Copyright (C) 2001 Ryan J. Myers <borisian@planetquake.com> *
* *
* This library is free software; you can redistribute it and/or modify *
* it under the terms of the GNU Lesser General Public License as published *
* by the Free Software Foundation; either version 2.1 of the License, or *
* (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, but *
* is supplied WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
* General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with this library; if not, write to the Free Software *
* Foundation, Inc at 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
* or download it at
http://www.gnu.org/copyleft/lesser.html. *
****************************************************************************
* $Id: main.c,v 1.2 2001/06/12 16:07:54 rmyers Exp $ *
* Entry point to the program *
****************************************************************************/
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include "win9x.h"
#include "winnt.h"
#include "window.h"
#include "update.h"
#include "parallel.h"
#include "registry.h"
static char *pcFirstPort = NULL;
void portCallback(const char *pcPortName)
{
if (NULL == pcFirstPort)
{
pcFirstPort = _strdup(pcPortName);
}
}
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, char *pcCmdLine, int iCmdShow)
{
HANDLE hMutex;
HWND hMain, hDlg;
MSG msg;
// LOWEST PRIORITY POSSIBLE, or we end up inflating the value!
SetPriorityClass(GetCurrentProcess(), IDLE_PRIORITY_CLASS);
// First off, are we the first instance? Create a mutex object, and if
// we succeed and GetLastError() returns ERROR_ALREADY_EXISTS, then we
// know to trigger visibility on the existing process's configuration
// window.
if (NULL == (hMutex = CreateMutex(NULL, FALSE, "!!!LEDMeter!!!")))
{
MessageBox(NULL, "Could not create mutex object!", "LEDMeter", MB_OK | MB_ICONERROR);
return 0;
}
else
{
if (ERROR_ALREADY_EXISTS == GetLastError())
{
if (NULL != (hMain = FindWindow("LEDMeter", "LEDMeter Poll Window")))
{
SendMessage(hMain, WM_USER, 0, 0);
}
return 0;
}
}
// Start up the monitor.
if (1 == IsNT())
{
if (0 != LoadMeters())
{
MessageBox(NULL, "Could not start PDH monitor!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_mutex;
}
}
else
{
if (0 != LoadCPUUsage())
{
MessageBox(NULL, "Could not start CPU monitor!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_mutex;
}
if (0 != LoadMemUsage())
{
MessageBox(NULL, "Could not start memory monitor!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_meter;
}
}
// If a port name was specified on the command line, use it without
// question, otherwise enumerate parallel ports on the system and use
// the first one found (if any).
if (strlen(pcCmdLine) > 0)
{
pcFirstPort = _strdup(pcCmdLine);
}
else
{
parEnumPorts(portCallback);
if (NULL == pcFirstPort)
{
MessageBox(NULL, "No parallel port found on the system!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_meter;
}
}
// Open the port.
if (0 != parOpenPort(pcFirstPort))
{
MessageBox(NULL, "Could not open parallel port!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_meter;
}
// Load settings.
if (0 != LoadSettings())
{
MessageBox(NULL, "Could not load settings from the Registry!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_par;
}
// Create the window system and start the message loop.
if (0 != CreateConfigWindow(hInst, &hMain, &hDlg))
{
MessageBox(NULL, "Could not create background window!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_par;
}
while (0 == ReadyToQuit())
{
if (0 != PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (0 == GetMessage(&msg, NULL, 0, 0))
{
break;// WM_QUIT recieved... we won't get here though.
}
if (!IsDialogMessage(hDlg, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
if ((1 != Configuring()) && (0 != UpdateLEDs()))
{
MessageBox(NULL, "Could not update LEDs!", "LEDMeter", MB_OK | MB_ICONERROR);
goto exit_par;
}
}
// If we've exited under normal circumstances, save settings.
SaveSettings();
// Close the port.
exit_par:
parClosePort();
free(pcFirstPort);
// Stop monitoring.
exit_meter:
if (1 == IsNT())
{
UnloadMeters();
}
else
{
UnloadCPUUsage();
UnloadMemUsage();
}
// Free the mutex. (This is actually done for us when the program exits,
// but it's good practice to clean up after yourself anyways.)
exit_mutex:
CloseHandle(hMutex);
return 0;
}
volgens mij zit hier ergens de fout.