//---------------------------------------------------------------------------
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused

#include <windows.h>
#include <shlobj.h>
#include <stdio.h>

#include <windows.h>
#include <shlobj.h>

HANDLE ATKACPIhandle;

int CtrlACPI(int code, int hasArg, int arg)
{
	long bytes = 0;
	long inbuf[5];
	struct cmbuf {
		short cmds[2];
		long cm2;
	} cbuf;
	long outbuf[192];
	int ret;

	cbuf.cmds[0] = 0;
	cbuf.cmds[1] = 4;
	cbuf.cm2 = arg;
	inbuf[0] = 2;
	inbuf[1] = code;
	inbuf[2] = hasArg;
	inbuf[3] = 8 * hasArg;
	inbuf[4] = (long)&cbuf;

	ret = DeviceIoControl(ATKACPIhandle, 0x222404, inbuf, sizeof(inbuf),
		outbuf, sizeof(outbuf), (unsigned long*)&bytes, NULL);
	return ret;
}

WNDCLASS wndclass;

LRESULT CALLBACK wndproc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	int ret;
	switch(uMsg) {
	case WM_DESTROY:
		PostQuitMessage(0);
		ret = 0;
		break;
	default:
		ret = DefWindowProc(hwnd,uMsg,wParam,lParam);
		break;
	}
	return ret;
}

int main(HINSTANCE hInstance, HINSTANCE hPrevInst, PSTR cmdLine,
	int iCmdShow)
{
	FILETIME stamp = {0};
	long old = -1, count;
	HWND hwnd;
	HKEY UnreadMailKey;
	HANDLE KeyEvent;

	wndclass.hInstance = hInstance;
	wndclass.lpszClassName = "hyc";
	wndclass.lpfnWndProc = wndproc;

	do {

		if (RegisterClass(&wndclass) == 0 ) break;

		hwnd = CreateWindow("hyc", "hyc", WS_OVERLAPPEDWINDOW,
			CW_USEDEFAULT, CW_USEDEFAULT,
			CW_USEDEFAULT, CW_USEDEFAULT,
			NULL, NULL, wndclass.hInstance, NULL);

		if (!hwnd) break;

		ATKACPIhandle = CreateFile("\\\\.\\ATKACPI",
			GENERIC_READ|GENERIC_WRITE,
			FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
			0, NULL);

		if (!ATKACPIhandle) break;

		for (;;) {
    		CtrlACPI(0x44454c57, 1, 1);
    		CtrlACPI(0x44454c4d, 1, 1);
            Sleep(100);
    		CtrlACPI(0x44454c57, 1, 0);
    		CtrlACPI(0x44454c4d, 1, 0);
            Sleep(100);
			}
	} while(0);
return(0);
}

