// MOUSE.cpp : DLL アプリケーションのエントリ ポイントを定義します。
//

#include "stdafx.h"

BOOL APIENTRY DllMain( HANDLE, DWORD, LPVOID )
{
    return TRUE;
}

static int args_typecheck( struct ARGS *args, char *types ) // 引数のチェック
{
	struct ARGS *p;

	p = args;

	if (p == NULL) {
		if (types == NULL || types[0] == 0)
			return 1; // OK
		else
			return 0; // NG
	}

	do {
		switch ( p->type ) {
			case UFCT_ARG_INT:
				if (*types != 'i')
					return 0; // NG
				break;

			case UFCT_ARG_STRING:
				if (*types != 's')
					return 0; // NG
				break;

			case UFCT_ARG_INTS:
				if (*types != 'a')
					return 0; // NG
				break;

			case UFCT_ARG_STRINGS:
				if (*types != 'r')
					return 0; // NG
				break;
		}
		
		types++;
	} while( (p = p->next) != NULL );

	if ( *types == 0 ) // argsが終端に達したとき、typeも終端に達したか?
		return 1; // OK
	else
		return 0; // NG
}

DllExport UINT call_spi(HWND hWnd, struct ARGS *args)
{
	if ( args_typecheck( args, "si" ) ) {
		if ( _stricmp(ARG1.text, "SPI_SETDRAGWIDTH") == 0 ) {
			return SystemParametersInfo(SPI_SETDRAGWIDTH,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETDRAGHEIGHT") == 0 ) {
			return SystemParametersInfo(SPI_SETDRAGHEIGHT,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETDOUBLECLKWIDTH") == 0 ) {
			return SystemParametersInfo(SPI_SETDOUBLECLKWIDTH,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETDOUBLECLKHEIGHT") == 0 ) {
			return SystemParametersInfo(SPI_SETDOUBLECLKHEIGHT,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SetDoubleClickTime") == 0 ) {
			return SetDoubleClickTime(ARG2.integer);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETDRAGFULLWINDOWS") == 0 ) {
			return SystemParametersInfo(SPI_SETDRAGFULLWINDOWS,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETSCREENSAVETIMEOUT") == 0 ) {
			return SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETMENUDROPALIGNMENT") == 0 ) {
			return SystemParametersInfo(SPI_SETMENUDROPALIGNMENT,ARG2.integer,0,SPIF_SENDCHANGE);
		}
		else if ( _stricmp(ARG1.text, "SetCaretBlinkTime") == 0 ) {
			return SetCaretBlinkTime(ARG2.integer);
		}
		else if ( _stricmp(ARG1.text, "SPI_SETANIMATION") == 0 ) {
			ANIMATIONINFO ai;

			ai.cbSize = sizeof( ANIMATIONINFO );
			ai.iMinAnimate = (int)ARG2.integer;
            
			return SystemParametersInfo(SPI_SETANIMATION,sizeof( ANIMATIONINFO ),&ai,SPIF_SENDCHANGE);
		}
	}

	return 0;
}

DllExport UINT call_spi_setmouse(HWND hWnd, struct ARGS *args)
{
	if ( args_typecheck( args, "iii" ) ) {
		DWORD r[3];

		r[2] = ARG1.integer;
		r[0] = ARG2.integer;
		r[1] = ARG3.integer;

		return SystemParametersInfo(SPI_SETMOUSE, 0, r, SPIF_SENDCHANGE);
	}

	return 0;
}
