 /***************************************************************************************
 *This program is free software; you can redistribute it and/or modify					*
 * it under the terms of the GNU General Public License as published by					*
 * the Free Software Foundation; either version 2 of the License, or					*
 * (at your option) any later version.													*
 *																						*
 * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html						*
 *																						*
 *																						*	
 ****************************************************************************************
 * Authors:																			  *
 *          Marc Dukette                                                              *
 **************************************************************************************/




#include "stdafx.h"
#include "init.h"
#include "../resource.h"
#include "resource.h"
#include <commctrl.h>
#include <winuser.h>
#if (_WIN32_WCE >= 300 && !defined(HPC))
#include <aygshell.h>
#include <sipapi.h>
	#define SHCMBM_GETMENU      (WM_USER + 402)
	#define SHGetMenu( hWndMB )  ( HMENU )SendMessage( ( hWndMB ), SHCMBM_GETMENU, ( WPARAM )0, ( LPARAM )0 )
	#define CommandBar_GetMenu( hWndMB, x )		( HMENU )SendMessage( ( hWndMB ), SHCMBM_GETMENU, ( WPARAM )0, ( LPARAM )0 )
	typedef BOOL (CALLBACK* paygshell_SHCreateMenuBar)( SHMENUBARINFO *pmb );
	paygshell_SHCreateMenuBar aygshell_SHCreateMenuBar;
#endif

#ifdef GAPI
#ifdef ARM
#include "gx.h"
#endif
#endif
	
long oldproc;

UserOptions* gPlayerOptions;

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}


#define REG_BASE			L"software\\PocketMVP"
#define OPT_ROTATE			L"Rotate"
#define OPT_AUDIO			L"Audio"
#define OPT_KEEPALIVE		L"Keep Alive"
#define OPT_ALWAYSHIDE		L"Always Hide"
#define OPT_DOUBLESIZE		L"Double Size"
#define OPT_CLEANVIDEO		L"Clean Video"
#define OPT_FITTOVIEWPORT	L"Fit to Viewport"
#define OPT_VIEWPLAYLIST	L"View Playlist"
#define OPT_VIEWMEDIA		L"View Media Info"
#define OPT_MDRIVECACHING	L"Microdrive Caching"
#define OPT_CACHESIZE		L"Cache Size"
#define OPT_BRIGHTNESS		L"Brightness"
#define OPT_DROPTOLERANCE	L"DropTolerance"
#define OPT_PLAYATOPEN		L"Play at File Open"
#define OPT_SHUFFLE			L"Shuffle"
#define OPT_REPEAT			L"Repeat"
#define OPT_SHOWDROP			L"ShowDropped"
#define OPT_SLOW			L"Slow Motion Optimize"
#define OPT_PAUSEKEY		L"PauseKey"
#define OPT_STOPKEY			L"StopKey"
#define OPT_FASTKEY			L"FastKey"
#define OPT_NEXTKEY			L"NextKey"
#define OPT_PREVKEY			L"PrevKey"
#define OPT_ROTATEKEY		L"RotateKey"
#define OPT_ZOOMKEY			L"ZoomKey"
#define OPT_TOGGLEKEY		L"ToggleKey"
#define OPT_VOLUMEUPKEY		L"VolumeUpKey"
#define OPT_VOLUMEDOWNKEY	L"VolumeDownKey"
#define OPT_BRIGHTNESSUPKEY		L"BrightnessUpKey"
#define OPT_BRIGHTNESSDOWNKEY	L"BrightnessDownKey"
#define OPT_CONTROLKEY		L"ControlKey"
#define OPT_MUTEKEY			L"MuteKey"
#define OPT_NOINDEX			L"No Index"
#define OPT_EQ				L"EQ"
#define OPT_SKIN			L"Skin"
#define OPT_KEEPLASTFILE	L"KeepLastFile"
#define OPT_LASTFILE		L"LastFile"
#define OPT_LASTFILEPOS		L"LastFilePos"
#define OPT_PRESET			L"Preset"
#define OPT_EXITEDOK		L"Exited"

INIT_API void LoadOptions(UserOptions* PlayerOptions)
{
	HKEY hKey = 0;
	DWORD dwSize = 0;
	DWORD dwType = 0;
	DWORD dwTmp;
	DWORD dwDisp = 0;
	int ns;
	BOOL iPAQ=false;
#ifdef GAPI
#ifdef ARM
	GXDisplayProperties x;			
	x=GXGetDisplayProperties();
	if (x.cbxPitch>2||(x.cbxPitch<2)) iPAQ=true;
#endif
#endif
//	if (wcsstr((LPTSTR)temp,_T("iPAQ"))||(wcsstr((LPTSTR)temp,_T("Amigo")))) iPAQ=true;

//	SystemParametersInfo(SPI_GETOEMINFO,200,(void*)temp,0);

	if ( ERROR_SUCCESS == RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_BASE, 0, 0, &hKey ) )
	{
		bool bExitOk;
		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_ROTATE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			 if (iPAQ) PlayerOptions->Rotate = ( dwTmp == 0 );
			 else PlayerOptions->Rotate = ( dwTmp != 0 );
		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_AUDIO, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Audio = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_KEEPALIVE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->KeepAlive = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_ALWAYSHIDE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->AlwaysHide = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_NOINDEX, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->NoIndex = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_DOUBLESIZE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Double = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_CLEANVIDEO, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Clean = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_FITTOVIEWPORT, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->FitToViewPort = ( dwTmp != 0 );


		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_VIEWPLAYLIST, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Playlist = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_VIEWMEDIA, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Media = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_MDRIVECACHING, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Cache = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_PLAYATOPEN, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->PlayAtOpen = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_SHUFFLE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Shuffle = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_REPEAT, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Repeat = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_SHOWDROP, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->ShowDropped = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_EXITEDOK, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			bExitOk = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_KEEPLASTFILE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->KeepLastFile = ( dwTmp != 0 );

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_CACHESIZE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->CacheSize = dwTmp;
#ifdef ARM

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_BRIGHTNESS, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->Brightness = dwTmp;
#endif
		dwSize = sizeof( DWORD );
		dwTmp = 0;
		PlayerOptions->DropTolerance = 3;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_DROPTOLERANCE, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->DropTolerance = dwTmp;

		
		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_PAUSEKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->PauseKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_STOPKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->StopKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_MUTEKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->MuteKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;

		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_FASTKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->FastKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_ROTATEKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->RotateKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_ZOOMKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->ZoomKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_TOGGLEKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->ToggleKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_VOLUMEUPKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->VolumeUpKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_VOLUMEDOWNKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->VolumeDownKey = dwTmp;

#ifdef ARM
		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_BRIGHTNESSUPKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->BrightnessUpKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_BRIGHTNESSDOWNKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->BrightnessDownKey = dwTmp;
#endif

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_NEXTKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->NextKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_PREVKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->PrevKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_CONTROLKEY, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->ControlSelectKey = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_LASTFILEPOS, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->LastFilePos = dwTmp;

		dwSize = sizeof( DWORD );
		dwTmp = 0;
		if ( ERROR_SUCCESS == RegQueryValueEx( hKey, OPT_EQ, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
			 REG_DWORD == dwType )
			PlayerOptions->EnableEQ = ( dwTmp != 0 );

		for (ns=IDC_EQ0;ns<IDC_EQ10+1;ns++)
		{
			TCHAR sKey[10];
			wcscpy(sKey,_T("Eq"));
			_itow(ns-IDC_EQ0,sKey+2,10);
			dwSize = sizeof( DWORD );
			dwTmp = 0;
			if ( ERROR_SUCCESS == RegQueryValueEx( hKey, sKey, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
				 REG_DWORD == dwType )
				 PlayerOptions->Eq[ns-IDC_EQ0] = dwTmp;
		}				
		dwSize=sizeof(PlayerOptions->Skin);
		dwType=0;
		wcscpy(PlayerOptions->Skin,_T(""));
		if ( ERROR_SUCCESS != RegQueryValueEx( hKey, OPT_SKIN, 0, &dwType, ( LPBYTE )PlayerOptions->Skin, &dwSize ) )
		{
			TCHAR path[200];
			HANDLE h=GetModuleHandle(_T("PocketMVP.exe"));
			GetModuleFileName((HMODULE)h,path,200);
			LPTSTR t=wcsstr(path,_T("PocketMVP"));
			*t=0;
			wcscpy(PlayerOptions->Skin,path);
			wcscat(PlayerOptions->Skin,_T("Skins\\PocketMVP.pds"));
		}
		dwSize=sizeof(PlayerOptions->LastFile);
		dwType=0;
		if ( (!bExitOk)||(ERROR_SUCCESS != RegQueryValueEx( hKey, OPT_LASTFILE, 0, &dwType, ( LPBYTE )PlayerOptions->LastFile, &dwSize )) )
		{
			wcscpy(PlayerOptions->LastFile,_T(""));
		}
		if (!wcscmp(PlayerOptions->Skin,_T("")))
		{
			TCHAR path[200];
			HANDLE h=GetModuleHandle(_T("PocketMVP.exe"));
			GetModuleFileName((HMODULE)h,path,200);
			LPTSTR t=wcsstr(path,_T("PocketMVP."));
			*t=0;
			wcscpy(PlayerOptions->Skin,path);
			wcscat(PlayerOptions->Skin,_T("Skins\\PocketMVP.pds"));
		}


		RegCloseKey( hKey );
	}
	if ( ERROR_SUCCESS == RegCreateKeyEx( HKEY_LOCAL_MACHINE, REG_BASE, NULL, 0, 0,
		KEY_READ | KEY_WRITE | KEY_SET_VALUE,
		NULL, &hKey, &dwDisp ) )
	{
		bool ok=false;
		RegSetValueEx( hKey, OPT_EXITEDOK, 0, REG_DWORD, ( LPBYTE )&(ok), sizeof( bool ) );
	}
}


INIT_API void SaveOptions(UserOptions* PlayerOptions)
{
	HKEY hKey = 0;
	int ns;
	DWORD dwDisp = 0;
	bool iPAQ=false;
#ifdef GAPI
#ifdef ARM
	GXDisplayProperties x;			
	x=GXGetDisplayProperties();
	if (x.cbxPitch>2||(x.cbxPitch<2)) iPAQ=true;
#endif
#endif
	if ( ERROR_SUCCESS == RegCreateKeyEx( HKEY_LOCAL_MACHINE, REG_BASE, NULL, 0, 0,
		KEY_READ | KEY_WRITE | KEY_SET_VALUE,
		NULL, &hKey, &dwDisp ) )
	{
		bool bRotate;
		bool ok=true;
		if (iPAQ) bRotate=!PlayerOptions->Rotate;
		else bRotate=PlayerOptions->Rotate;
		RegSetValueEx( hKey, OPT_ROTATE, 0, REG_DWORD, ( LPBYTE )&(bRotate), sizeof( bool ) );
		RegSetValueEx( hKey, OPT_AUDIO, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Audio, sizeof( bool ) );
	
		RegSetValueEx( hKey, OPT_KEEPALIVE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->KeepAlive, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_ALWAYSHIDE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->AlwaysHide, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_NOINDEX, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->NoIndex, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_DOUBLESIZE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Double, sizeof( bool ) );
	
		RegSetValueEx( hKey, OPT_CLEANVIDEO, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Clean, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_FITTOVIEWPORT, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->FitToViewPort, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_VIEWMEDIA, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Media, sizeof( bool ) );
		
		RegSetValueEx( hKey, OPT_VIEWPLAYLIST, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Playlist, sizeof( bool ) );
	

		RegSetValueEx( hKey, OPT_MDRIVECACHING, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Cache, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_PLAYATOPEN, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->PlayAtOpen, sizeof( bool ) );
		
		RegSetValueEx( hKey, OPT_SHUFFLE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Shuffle, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_REPEAT, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Repeat, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_SHOWDROP, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->ShowDropped, sizeof( bool ) );
		
		RegSetValueEx( hKey, OPT_KEEPLASTFILE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->KeepLastFile, sizeof( bool ) );

		RegSetValueEx( hKey, OPT_CACHESIZE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->CacheSize, sizeof( DWORD ) );

#ifdef ARM
		RegSetValueEx( hKey, OPT_BRIGHTNESS, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Brightness, sizeof( DWORD ) );
#endif
		RegSetValueEx( hKey, OPT_DROPTOLERANCE, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->DropTolerance, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_PAUSEKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->PauseKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_STOPKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->StopKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_MUTEKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->MuteKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_FASTKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->FastKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_ROTATEKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->RotateKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_ZOOMKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->ZoomKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_TOGGLEKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->ToggleKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_VOLUMEUPKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->VolumeUpKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_VOLUMEDOWNKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->VolumeDownKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_VOLUMEUPKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->VolumeUpKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_VOLUMEDOWNKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->VolumeDownKey, sizeof( DWORD ) );

#ifdef ARM
		RegSetValueEx( hKey, OPT_BRIGHTNESSUPKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->BrightnessUpKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_BRIGHTNESSDOWNKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->BrightnessDownKey, sizeof( DWORD ) );
#endif
		RegSetValueEx( hKey, OPT_NEXTKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->NextKey, sizeof( DWORD ) );
		
		RegSetValueEx( hKey, OPT_PREVKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->PrevKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_CONTROLKEY, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->ControlSelectKey, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_LASTFILEPOS, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->LastFilePos, sizeof( DWORD ) );

		RegSetValueEx( hKey, OPT_EQ, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->EnableEQ, sizeof( bool ) );

		for (ns=IDC_EQ0;ns<IDC_EQ10+1;ns++)
		{
			TCHAR sKey[10];
			wcscpy(sKey,_T("Eq"));
			_itow(ns-IDC_EQ0,sKey+2,10);
			RegSetValueEx( hKey, sKey, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Eq[ns-IDC_EQ0], sizeof( DWORD ) );
//			wcscpy(sKey,PlayerOptions->Preset);
//			wcscat(sKey,_T("Eq"));
//			_itow(ns-IDC_EQ0,sKey+2,10);
//			RegSetValueEx( hKey, sKey, 0, REG_DWORD, ( LPBYTE )&PlayerOptions->Eq[ns-IDC_EQ0], sizeof( DWORD ) );
		}
//		RegSetValueEx( hKey, OPT_PRESET, 0, REG_SZ, ( LPBYTE )&PlayerOptions->Preset, sizeof( PlayerOptions->Preset ) );
		RegSetValueEx( hKey, OPT_SKIN, 0, REG_SZ, ( LPBYTE )&PlayerOptions->Skin, sizeof( PlayerOptions->Skin ) );
		RegSetValueEx( hKey, OPT_LASTFILE, 0, REG_SZ, ( LPBYTE )&PlayerOptions->LastFile, sizeof( PlayerOptions->LastFile ) );
		RegSetValueEx( hKey, OPT_EXITEDOK, 0, REG_DWORD, ( LPBYTE )&(ok), sizeof( bool ) );
		RegCloseKey( hKey );
	}

}


ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass, WNDPROC WndProc)

{
	WNDCLASS wc1;

    wc1.style			= CS_HREDRAW | CS_VREDRAW;
    wc1.lpfnWndProc		= (WNDPROC) WndProc;
    wc1.cbClsExtra		= 0;
    wc1.cbWndExtra		= 0;
    wc1.hInstance		= hInstance;
    wc1.hIcon			= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_POCKETMVP));
    wc1.hCursor			= 0;
    wc1.hbrBackground	= (HBRUSH) GetStockObject(BLACK_BRUSH);
    wc1.lpszMenuName	= 0; //MAKEINTRESOURCE(IDM_MENU);
    wc1.lpszClassName	= szWindowClass;

	ATOM x1 = RegisterClass(&wc1);


	return  x1;
}

LRESULT CALLBACK ListProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	

	switch (message) 
	{
		case WM_KEYDOWN:
			if ((wParam>0&&(wParam<91))||(wParam>185)||(wParam>95&&(wParam<112)))
			{
				SendMessage(hWnd,CB_SETITEMDATA,SendMessage(hWnd,CB_GETCURSEL,0,0),wParam);
				SetDlgItemText(GetParent(hWnd),IDC_STATICSTATUS,_T("(Function Mapped)"));
			}
			break;
		default:
//#if _WIN32_WCE >= 300
#ifdef STRICT
			return CallWindowProc((WNDPROC)oldproc,hWnd,message,wParam,lParam);
#else
			return CallWindowProc((int (__cdecl *)(void))oldproc,hWnd,message,wParam,lParam);
#endif
			break;
	}
}



BOOL CALLBACK cfgDlg(
HWND hwndDlg, 
UINT uMsg, 
WPARAM wParam, 
LPARAM lParam )
{
	NMHDR* nm=(NMHDR*) lParam;
	switch(uMsg)
	{
	case WM_COMMAND:
		switch (HIWORD(wParam))
		{
			case CBN_SELENDOK:
				SetDlgItemText(hwndDlg,IDC_STATICSTATUS,_T("(Press Button to Map)"));
				break;			
			default:
				break;
		}
		switch (wParam)
		{
			case ID_OK:
				gPlayerOptions->Cache=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKCACHE),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->KeepAlive=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKKEEPALIVE),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->AlwaysHide=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKHIDE),BM_GETCHECK,0,0)==BST_CHECKED);

				gPlayerOptions->NoIndex=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKNOINDEX),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->PlayAtOpen=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKPLAYATOPEN),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->ShowDropped=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKDROP),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->KeepLastFile=(SendMessage(GetDlgItem(hwndDlg,IDC_CHECKREMEMBER),BM_GETCHECK,0,0)==BST_CHECKED);
				gPlayerOptions->CacheSize=SendMessage( GetDlgItem(hwndDlg,IDC_SLIDER1), TBM_GETPOS, 0,0 );
#ifdef ARM
				gPlayerOptions->Brightness=SendMessage( GetDlgItem(hwndDlg,IDC_BRIGHT), TBM_GETPOS, 0,0 );
#endif
				gPlayerOptions->DropTolerance=SendMessage( GetDlgItem(hwndDlg,IDC_DROP), TBM_GETPOS, 0,0 );
				gPlayerOptions->ToggleKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)0,(LPARAM)0);
				gPlayerOptions->PauseKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)1,(LPARAM)0);
				gPlayerOptions->FastKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)2,(LPARAM)0);
				gPlayerOptions->RotateKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)3,(LPARAM)0);
				gPlayerOptions->ZoomKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)4,(LPARAM)0);
				gPlayerOptions->VolumeUpKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)5,(LPARAM)0);
				gPlayerOptions->VolumeDownKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)6,(LPARAM)0);
				gPlayerOptions->NextKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)7,(LPARAM)0);
				gPlayerOptions->PrevKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)8,(LPARAM)0);
				gPlayerOptions->ControlSelectKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)9,(LPARAM)0);
				gPlayerOptions->StopKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)10,(LPARAM)0);
				gPlayerOptions->MuteKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)11,(LPARAM)0);
#ifdef ARM
				gPlayerOptions->BrightnessUpKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)12,(LPARAM)0);
				gPlayerOptions->BrightnessDownKey=SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_GETITEMDATA,(WPARAM)13,(LPARAM)0);
#endif				
				
				SaveOptions(gPlayerOptions);
				EndDialog(hwndDlg,1);
				SetWindowLong(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),GWL_WNDPROC,(long)oldproc);
				break;
			case ID_CLEAR:
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)0,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)1,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)2,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)3,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)4,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)5,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)6,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)7,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)8,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)9,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)10,(LPARAM)0);
#ifdef ARM
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)11,(LPARAM)0);
				SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)12,(LPARAM)0);
#endif
				break;
			default:
				break;
		}
		break;
		case WM_INITDIALOG:

			oldproc=SetWindowLong(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),GWL_WNDPROC,(long)ListProc);
			SendMessage( GetDlgItem(hwndDlg,IDC_SLIDER1), TBM_SETRANGE, true, ( LPARAM )MAKELONG( 1, 12 ) );
			SendMessage( GetDlgItem(hwndDlg,IDC_SLIDER1), TBM_SETPAGESIZE, 0, 1 );
			SendMessage( GetDlgItem(hwndDlg,IDC_SLIDER1), TBM_SETPOS, true, gPlayerOptions->CacheSize);

			SendMessage( GetDlgItem(hwndDlg,IDC_BRIGHT), TBM_SETRANGE, true, ( LPARAM )MAKELONG( -100, 100 ) );
			SendMessage( GetDlgItem(hwndDlg,IDC_BRIGHT), TBM_SETPAGESIZE, 0, 10 );

			SendMessage( GetDlgItem(hwndDlg,IDC_DROP), TBM_SETRANGE, true, ( LPARAM )MAKELONG( 1, 30 ) );
			SendMessage( GetDlgItem(hwndDlg,IDC_DROP), TBM_SETPAGESIZE, 0, 1 );
#ifdef ARM
			SendMessage( GetDlgItem(hwndDlg,IDC_BRIGHT), TBM_SETPOS, true, gPlayerOptions->Brightness);
#endif			
			SendMessage( GetDlgItem(hwndDlg,IDC_DROP), TBM_SETPOS, true, gPlayerOptions->DropTolerance);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Toggle Display"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)0,(LPARAM)gPlayerOptions->ToggleKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Pause"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)1,(LPARAM)gPlayerOptions->PauseKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Fast Forward"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)2,(LPARAM)gPlayerOptions->FastKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Rotate"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)3,(LPARAM)gPlayerOptions->RotateKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Zoom"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)4,(LPARAM)gPlayerOptions->ZoomKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Volume Up"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)5,(LPARAM)gPlayerOptions->VolumeUpKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Volume Down"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)6,(LPARAM)gPlayerOptions->VolumeDownKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Next Item"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)7,(LPARAM)gPlayerOptions->NextKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Prev Item"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)8,(LPARAM)gPlayerOptions->PrevKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Control Selct"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)9,(LPARAM)gPlayerOptions->ControlSelectKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Stop"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)10,(LPARAM)gPlayerOptions->StopKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Mute"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)11,(LPARAM)gPlayerOptions->MuteKey);
#ifdef ARM
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Increase Brightness"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)12,(LPARAM)gPlayerOptions->BrightnessUpKey);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_ADDSTRING,(WPARAM)0,(LPARAM)_T("Decrease Brightness"));
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETITEMDATA,(WPARAM)13,(LPARAM)gPlayerOptions->BrightnessDownKey);
#endif
			if (gPlayerOptions->Cache)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKCACHE),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->KeepAlive)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKKEEPALIVE),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->AlwaysHide)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKHIDE),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->NoIndex)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKNOINDEX),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->PlayAtOpen)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKPLAYATOPEN),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->ShowDropped)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKDROP),BM_SETCHECK,BST_CHECKED,0);
			if (gPlayerOptions->KeepLastFile)
				SendMessage(GetDlgItem(hwndDlg,IDC_CHECKREMEMBER),BM_SETCHECK,BST_CHECKED,0);
			SendMessage(GetDlgItem(hwndDlg,IDC_CBOFUNCTIONS),CB_SETCURSEL,(WPARAM)0,(LPARAM)0);
			break;
		default:
			break;
	}
	return 0;
}

BOOL CALLBACK eqDlg(
HWND hwndDlg, 
UINT uMsg, 
WPARAM wParam, 
LPARAM lParam )
{
	NMHDR* nm=(NMHDR*) lParam;
	int ns;
	switch(uMsg)
	{
	case WM_COMMAND:
		switch (wParam)
		{
/*			case CBN_SELCHANGE:
				{
					int ns;
					for (ns=IDC_EQ0;ns<IDC_EQ10+1;ns++)
					{
						TCHAR sKey[10];
						wcscpy(sKey,_T("Eq"));
						_itow(ns-IDC_EQ0,sKey+2,10);
						dwSize = sizeof( DWORD );
						dwTmp = 0;
						if ( ERROR_SUCCESS == RegQueryValueEx( hKey, sKey, 0, &dwType, ( LPBYTE )&dwTmp, &dwSize ) &&
							 REG_DWORD == dwType )
							 PlayerOptions->Eq[ns-IDC_EQ0] = dwTmp;
					}	
				}
				break;*/
			case IDRESET:
				for (ns=IDC_EQ0;ns<IDC_EQ10+1;ns++)
				{
					SendMessage( GetDlgItem(hwndDlg,ns), TBM_SETPOS, true, 0);
				}
				break;
			case IDOK:
				for (ns=IDC_EQ0;ns<IDC_EQ9+1;ns++)
				{
					gPlayerOptions->Eq[ns-IDC_EQ0]=(SendMessage( GetDlgItem(hwndDlg,ns), TBM_GETPOS, 0,0 )*-1);
				}
				//GetDlgItemText(hwndDlg,IDC_PRESET,&gPlayerOptions->Preset,50);
				gPlayerOptions->Eq[IDC_EQ10-IDC_EQ0]=(SendMessage( GetDlgItem(hwndDlg,IDC_EQ10), TBM_GETPOS, 0,0 ));
				SaveOptions(gPlayerOptions);
				EndDialog(hwndDlg,1);
				break;
			default:
				break;
		}
		break;
		case WM_INITDIALOG:
			for (ns=IDC_EQ0;ns<IDC_EQ9+1;ns++)
			{
				SendMessage( GetDlgItem(hwndDlg,ns), TBM_SETRANGE, true, ( LPARAM )MAKELONG( -20, 20 ) );
				SendMessage( GetDlgItem(hwndDlg,ns), TBM_SETPAGESIZE, 0, 1 );
				SendMessage( GetDlgItem(hwndDlg,ns), TBM_SETPOS, true, gPlayerOptions->Eq[ns-IDC_EQ0]*-1);
			}
			SendMessage( GetDlgItem(hwndDlg,IDC_EQ10), TBM_SETRANGE, true, ( LPARAM )MAKELONG( -20, 20 ) );
			SendMessage( GetDlgItem(hwndDlg,IDC_EQ10), TBM_SETPAGESIZE, 0, 1 );
			SendMessage( GetDlgItem(hwndDlg,IDC_EQ10), TBM_SETPOS, true, gPlayerOptions->Eq[IDC_EQ10-IDC_EQ0]);
			break;
		default:
			break;
	}
	return 0;
}


BOOL CALLBACK jmpDlg(
HWND hwndDlg, 
UINT uMsg, 
WPARAM wParam, 
LPARAM lParam )
{
	int initsec;
	int seconds;
	int h, m, s;
	TCHAR hr[3],min[3],sec[3];
	switch(uMsg)
	{
	case WM_COMMAND:
		switch (wParam)
		{
			case IDCANCEL:
				EndDialog(hwndDlg,-1);
				break;
			case IDOK:
				GetDlgItemText(hwndDlg,IDC_EDITHR,hr,3);
				GetDlgItemText(hwndDlg,IDC_EDITMIN,min,3);
				GetDlgItemText(hwndDlg,IDC_EDITSEC,sec,3);
				h=_wtoi(hr);
				m=_wtoi(min);
				s=_wtoi(sec);
				if (s>59||(m>59))
				{
					MessageBox(hwndDlg,_T("Invalid Time"),_T(""),MB_OK);
				}
				else
				{
					seconds=h*3600 + m*60 + s;
					EndDialog(hwndDlg,seconds);
				}
				break;
			default:
				break;
		}
		break;
		case WM_INITDIALOG:
			initsec=(int)lParam;
			h=initsec/3600;
			m=(initsec-h*3600)/60;
			s=initsec-(h*3600+m*60);
			wcscpy(hr,_T("00"));
			wcscpy(min,_T("00"));
			wcscpy(sec,_T("00"));
			_itow(h,h<10?hr+1:hr,10);
			_itow(m,m<10?min+1:min,10);
			_itow(s,s<10?sec+1:sec,10);
			SetDlgItemText(hwndDlg,IDC_EDITHR,hr);
			SetDlgItemText(hwndDlg,IDC_EDITMIN,min);
			SetDlgItemText(hwndDlg,IDC_EDITSEC,sec);
			SetFocus(GetDlgItem(hwndDlg,IDC_EDITHR));
			SendDlgItemMessage(hwndDlg,IDC_EDITHR,EM_SETLIMITTEXT,2,0);
			SendDlgItemMessage(hwndDlg,IDC_EDITMIN,EM_SETLIMITTEXT,2,0);
			SendDlgItemMessage(hwndDlg,IDC_EDITSEC,EM_SETLIMITTEXT,2,0);
			break;
		default:
			break;
	}
	return 0;
}

INIT_API void Configure(HINSTANCE hDll, HINSTANCE hInstance, HWND Parent,UserOptions* PlayerOptions)
{
	HINSTANCE hDLL=GetModuleHandle(_T("Init.dll"));
	gPlayerOptions=PlayerOptions;
#ifndef HPC
	DialogBox(hDLL,MAKEINTRESOURCE(IDD_DLGCONFIG),Parent,cfgDlg);
#else
	DialogBox(hDLL,MAKEINTRESOURCE(IDD_DLGCONFIGHPC),Parent,cfgDlg);
#endif
}

INIT_API int JumpTo(HWND Parent, int position)
{
	HINSTANCE hDLL=GetModuleHandle(_T("Init.dll"));
	return DialogBoxParam(hDLL,MAKEINTRESOURCE(IDD_DIALOGJUMP),Parent,jmpDlg,position);
}



INIT_API void Equalizer(HINSTANCE hDll, HINSTANCE hInstance, HWND Parent,UserOptions* PlayerOptions)
{
	HINSTANCE hDLL=GetModuleHandle(_T("Init.dll"));
	gPlayerOptions=PlayerOptions;
	DialogBox(hDLL,MAKEINTRESOURCE(IDD_DLGEQ),Parent,eqDlg);
}

INIT_API HWND ExternalInit(HINSTANCE hDll, HINSTANCE hInstance, int nCmdShow,UserOptions* PlayerOptions, HWND* hwndcb,WNDPROC WndProc, LPTSTR* ToolTips)
{
	HWND	hWnd,hwndCB;
	TCHAR	szTitle[200];			// The title bar text
	TCHAR	szWindowClass[200];		// The window class name

	LoadString(hInstance, IDC_POCKETMVP, szWindowClass, 200);
	MyRegisterClass(hInstance, szWindowClass,WndProc);

	LoadString(hInstance, IDS_APP_TITLE, szTitle, 200);
	
	if (FindWindow(szWindowClass, szTitle))
	{
	    SetForegroundWindow(FindWindow(szWindowClass, szTitle));
		if (FindWindow(_T("OpenDialog"), _T("Open File"))){
		   SetForegroundWindow(FindWindow(_T("OpenDialog"), _T("Open File")));
		}
	   return FALSE;
	}

	hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
	if (!hWnd)
	{	
		return FALSE;
	}

	ShowWindow(hWnd, nCmdShow);
	UpdateWindow(hWnd);
	HINSTANCE hInst=hInstance;
	HMENU hMenu;

#if (_WIN32_WCE >= 300 && !defined(HPC))
			//Create the PocketPC compatible menubar.
			HANDLE ha=LoadLibrary(_T("aygshell.dll"));
			if (ha!=NULL)
			{
				aygshell_SHCreateMenuBar=(paygshell_SHCreateMenuBar)GetProcAddress((HINSTANCE)ha,_T("SHCreateMenuBar"));
			}
			SHMENUBARINFO sMbi;
			memset( &sMbi, 0, sizeof ( SHMENUBARINFO ) );
			sMbi.cbSize = sizeof( sMbi );
			sMbi.hwndParent = hWnd;
			sMbi.dwFlags = SHCMBF_HIDESIPBUTTON;
			sMbi.nToolBarId = IDR_MENUBAR1;
			sMbi.hInstRes = hInst;
			sMbi.nBmpId = 0;
			sMbi.cBmpImages = 0;

			if ( aygshell_SHCreateMenuBar( &sMbi ) )
			{
				hwndCB = sMbi.hwndMB;
			}
#else
			hwndCB = CommandBar_Create(hInst, hWnd, 1);			
			CommandBar_InsertMenubar(hwndCB, hInst, IDM_MENU, 0);
#endif
	if (hwndCB)
		CommandBar_Show(hwndCB, TRUE);
	hMenu=CommandBar_GetMenu(hwndCB,0);

	//CheckMenuItem( hMenu, IDM_AUDIO, PlayerOptions->Audio?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_CLEAN, PlayerOptions->Clean?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_SHUFFLE, PlayerOptions->Shuffle?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_REPEAT, PlayerOptions->Repeat?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_VIEWMEDIA, PlayerOptions->Media?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_VIEWPLAYLIST, PlayerOptions->Playlist?MF_CHECKED:MF_UNCHECKED );
	CheckMenuItem( hMenu, IDM_FITTOVIEW, PlayerOptions->FitToViewPort?MF_CHECKED:MF_UNCHECKED );

	*hwndcb=hwndCB;
	return hWnd;
}

// This is the constructor of a class that has been exported.
// see Dynamic.h for the class definition
CDynamic::CDynamic()
{ 
	return; 
}

