Audio joy v2.0.1.5

Description

Voila en fait le regroupement des 4 tuto de hier
en un seul:
Media Player Joystic Contoller

Si quelqun peut m'aider a ajouter le support pour d'autre player il sera le bienvenue

Source / Exemple :


#include <windows.h>
#include <commctrl.h>
#include <winreg.h>
#include <stdio.h>
#include <time.h>
#include "res/resource.h"

#define WIN32_LEAN_AND_MEAN
#define VC_EXTRALEAN

#define BOUTON1 1
#define BOUTON2 2
#define BOUTON3 4
#define BOUTON4 8
#define BOUTON5 16
#define BOUTON6 32
#define BOUTON7 64
#define BOUTON8 128
#define BOUTON9 256
#define BOUTON10 512

// Winamp 2.XX
#define WINAMP_SHUFFLE			40023
#define WINAMP_PREV				40044
#define WINAMP_PLAY				40045
#define WINAMP_PAUSE			40046
#define WINAMP_STOP				40047
#define WINAMP_NEXT				40048
#define WINAMP_VOLUME_UP        40058
#define WINAMP_VOLUME_DOWN      40059

//Media Player 9 (XP)
#define WMP9_PLAY				18808
#define WMP9_STOP				18809
#define WMP9_PLAY_FAST			18834
#define WMP9_PLAY_NORMAL		18835
#define WMP9_PLAY_SLOW			18836
#define WMP9_PREV				18810
#define WMP9_NEXT				18811
#define WMP9_FAST_FORWARD		18813
#define WMP9_SHUFFLE			18842
#define WMP9_REPEAT				18843
#define WMP9_VOLUME_UP			18815
#define WMP9_VOLUME_DOWN		18816
#define WMP9_VOLUME_MUTE		18817

//Media Player 8 (XP)
#define WMP8_PLAY				32808
#define WMP8_STOP				32809
#define WMP8_PREV				32810
#define WMP8_NEXT				32811
#define WMP8_SHUFFLE			32842
#define WMP8_REPEAT				32843
#define WMP8_VOLUME_UP			32815
#define WMP8_VOLUME_DOWN		32816
#define WMP8_VOLUME_MUTE		32817

//Musicmatch JukeBox 7.50
#define MMJB_PREV				32854
#define MMJB_PLAY				32856
#define MMJB_PAUSE				32857
#define MMJB_STOP				32858
#define MMJB_NEXT				32859
#define MMJB_VOLUME_UP			32864
#define MMJB_VOLUME_DOWN		32865
#define MMJB_MUTE				32866
#define MMJB_SEEK_FORWARD		32861
#define MMJB_SEEK_BACKWARD		32860
#define MMJB_SKIP_BACK_TRACKS	32862
#define MMJB_SKIP_FORWARD_TRACKS	32863

#define POWER_OFF				666
#define SCREEN_OFF				667

#define PL_WINAMP				100
#define PL_WMP8					101
#define PL_WMP9					102
#define PL_MMJB					103

#define WM_SYSTRAYMSG			13524
#define IDT_TIMER				2001

char GetPlayer[255],GetCmd[255],help[MAX_PATH];
int idplayer,randn;

NOTIFYICONDATA trayicon;
HINSTANCE Instance;
JOYCAPS JoyCaps;
HBITMAP rgn_bitmap;
HICON SysTicon_ACT,SysTicon_DESACT;
HMENU hMenuLoad,hMenu,sysmenu;
RECT Rect;
HRGN rgn;
BOOL Stop = TRUE,off = FALSE;

// [en] Structure dfor the program's options
// [fr] Structure Contenant les variable du programe
struct JOY_CONF{

	int but_01;
	int but_02;
	int but_03;
	int but_04;
	int but_05;
	int but_06;
	int but_07;
	int but_08;
	int but_09;
	int but_10;
	int wait_01;
	int wait_02;
	int wait_03;
	int wait_04;
	int wait_05;
	int wait_06;
	int wait_07;
	int wait_08;
	int wait_09;
	int wait_10;
	DWORD SavedPos_Pl;
	DWORD SavedPos_01;
	DWORD SavedPos_02;
	DWORD SavedPos_03;
	DWORD SavedPos_04;
	DWORD SavedPos_05;
	DWORD SavedPos_06;
	DWORD SavedPos_07;
	DWORD SavedPos_08;
	DWORD SavedPos_09;
	DWORD SavedPos_10;
	DWORD nb_pushed;
	DWORD nb_poweroff;

};

JOY_CONF joy_conf;

// [en] Save Misc Options
// [fr] Enregistre les Options diverse
void save_sens_conf()
{
	HKEY hKey;

	RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0, NULL, 0, 0, NULL, &hKey, NULL);
	RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0, KEY_WRITE,&hKey);

	RegSetValueEx(hKey, "BOUTON_01_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_01, sizeof(joy_conf.wait_01) );
	RegSetValueEx(hKey, "BOUTON_02_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_02, sizeof(joy_conf.wait_02) );
	RegSetValueEx(hKey, "BOUTON_03_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_03, sizeof(joy_conf.wait_03) );
	RegSetValueEx(hKey, "BOUTON_04_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_04, sizeof(joy_conf.wait_04) );
	RegSetValueEx(hKey, "BOUTON_05_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_05, sizeof(joy_conf.wait_05) );
	RegSetValueEx(hKey, "BOUTON_06_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_06, sizeof(joy_conf.wait_06) );
	RegSetValueEx(hKey, "BOUTON_07_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_07, sizeof(joy_conf.wait_07) );
	RegSetValueEx(hKey, "BOUTON_08_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_08, sizeof(joy_conf.wait_08) );
	RegSetValueEx(hKey, "BOUTON_09_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_09, sizeof(joy_conf.wait_09) );
	RegSetValueEx(hKey, "BOUTON_10_SENSIBILITY", NULL, REG_DWORD, (LPBYTE)&joy_conf.wait_10, sizeof(joy_conf.wait_10) );
	RegSetValueEx(hKey, "Power-Off Protection", NULL, REG_DWORD, (LPBYTE)&joy_conf.nb_poweroff, sizeof(joy_conf.nb_poweroff) );

	RegCloseKey(hKey);
	return;
}//-------------

// [en] Load Misc Options
// [fr] Charge les Options diverse
void load_sens_conf()
{
	HKEY hKey;
	DWORD dwKeySize = 255;

	RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0, KEY_READ,&hKey);
	
	RegQueryValueEx(hKey, "BOUTON_01_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_01, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_02_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_02, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_03_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_03, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_04_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_04, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_05_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_05, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_06_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_06, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_07_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_07, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_08_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_08, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_09_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_09, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_10_SENSIBILITY", 0, NULL, (LPBYTE)&joy_conf.wait_10, &dwKeySize);
	RegQueryValueEx(hKey, "Power-Off Protection", 0, NULL, (LPBYTE)&joy_conf.nb_poweroff, &dwKeySize);
	
	RegCloseKey(hKey);
	return;
}//-------------

// [en] Save Button Options
// [fr] Enregistre la Configuration des bouttons
void save_conf()
{
	HKEY hKey;

	RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0, NULL, 0, 0, NULL, &hKey, NULL);
	RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0, KEY_WRITE,&hKey);

	RegSetValueEx(hKey, "PLAYER_ID", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_Pl, sizeof(joy_conf.SavedPos_Pl) );
	RegSetValueEx(hKey, "BOUTON_01", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_01, sizeof(joy_conf.SavedPos_01) );
	RegSetValueEx(hKey, "BOUTON_02", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_02, sizeof(joy_conf.SavedPos_02) );
	RegSetValueEx(hKey, "BOUTON_03", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_03, sizeof(joy_conf.SavedPos_03) );
	RegSetValueEx(hKey, "BOUTON_04", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_04, sizeof(joy_conf.SavedPos_04) );
	RegSetValueEx(hKey, "BOUTON_05", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_05, sizeof(joy_conf.SavedPos_05) );
	RegSetValueEx(hKey, "BOUTON_06", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_06, sizeof(joy_conf.SavedPos_06) );
	RegSetValueEx(hKey, "BOUTON_07", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_07, sizeof(joy_conf.SavedPos_07) );
	RegSetValueEx(hKey, "BOUTON_08", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_08, sizeof(joy_conf.SavedPos_08) );
	RegSetValueEx(hKey, "BOUTON_09", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_09, sizeof(joy_conf.SavedPos_09) );
	RegSetValueEx(hKey, "BOUTON_10", NULL, REG_DWORD, (LPBYTE)&joy_conf.SavedPos_10, sizeof(joy_conf.SavedPos_10) );

	RegCloseKey(hKey);
	return;
}//-------------

// [en] Load Button Options
// [fr] Charge la Configuration des bouttons
void load_conf()
{
	HKEY hKey;
	DWORD dwKeySize = 255;

	RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\PiX Design\\Audio-Joy", 0,KEY_READ,&hKey);

	RegQueryValueEx(hKey, "PLAYER_ID", 0,NULL, (LPBYTE)&joy_conf.SavedPos_Pl, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_01", 0,NULL, (LPBYTE)&joy_conf.SavedPos_01, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_02", 0,NULL, (LPBYTE)&joy_conf.SavedPos_02, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_03", 0,NULL, (LPBYTE)&joy_conf.SavedPos_03, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_04", 0,NULL, (LPBYTE)&joy_conf.SavedPos_04, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_05", 0,NULL, (LPBYTE)&joy_conf.SavedPos_05, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_06", 0,NULL, (LPBYTE)&joy_conf.SavedPos_06, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_07", 0,NULL, (LPBYTE)&joy_conf.SavedPos_07, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_08", 0,NULL, (LPBYTE)&joy_conf.SavedPos_08, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_09", 0,NULL, (LPBYTE)&joy_conf.SavedPos_09, &dwKeySize);
	RegQueryValueEx(hKey, "BOUTON_10", 0,NULL, (LPBYTE)&joy_conf.SavedPos_10, &dwKeySize);
	
	RegCloseKey(hKey);
	return;
}//-------------

// [en] Power-Off Computer
// [fr] Arreter L'ordinateur
BOOL InitPowerOff()
{
     HANDLE hToken; 
     TOKEN_PRIVILEGES tkp; 
	 if (!OpenProcessToken(GetCurrentProcess(), 
        TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) 
        return FALSE; 
     LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, 
        &tkp.Privileges[0].Luid); 

     tkp.PrivilegeCount = 1; 
     tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; 
     AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, 
        (PTOKEN_PRIVILEGES)NULL, 0); 
     if (GetLastError() != ERROR_SUCCESS) 
        return FALSE; 
	 if (!ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0)) 
        return FALSE; 

     return TRUE;
}//-------------
 

// [en] Help File Extraction
// [fr] Extraction du chichier d'aide
// Thanks to Mathieu Vidalinc for this resource extracting code
// Merci a Mathieu Vidalinc pour cette fonction.
void extract_help()
{
	char Path[MAX_PATH+1];
	GetCurrentDirectory(256,Path);
	strcat(Path, "\\Help");
	CreateDirectory(Path, NULL);

	// déclarations et initialisations
	char		m_szFilename2[MAX_PATH];
	HINSTANCE	m_hModule2	= NULL;
	char		m_szType2[MAX_PATH];
	DWORD		m_dwID2;

	DWORD dwID2			= IDR_HELP1;
	LPCSTR szType2		= "HELP";
	LPCSTR szFilename2	= strcat(Path, "\\help.chm");

	memset(m_szType2,0,sizeof m_szType2);
	memcpy(m_szType2,(void*)szType2,strlen(szType2));
	
	memset(m_szFilename2,0,sizeof m_szFilename2);
	memcpy(m_szFilename2,szFilename2,strlen(szFilename2));

	m_dwID2 = dwID2;

	// extraction de la ressource
	HRSRC	hRes2		= FindResource(m_hModule2, MAKEINTRESOURCE(m_dwID2), m_szType2);
	DWORD	dwDataSize2	= SizeofResource(m_hModule2,hRes2);
	HGLOBAL	hGlob2		= LoadResource(m_hModule2,hRes2);
	LPVOID	pData2		= LockResource(hGlob2);

	// création du fichier
	HANDLE	hFile2 = CreateFile (m_szFilename2, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if( hFile2 == INVALID_HANDLE_VALUE )
	{
		UnlockResource(hGlob2);
		FreeResource(hGlob2);	
	}

	DWORD	dwBytesWritten2 = 0;

	if( !WriteFile(hFile2,pData2,dwDataSize2,&dwBytesWritten2,NULL) 
		||
		dwBytesWritten2 != dwDataSize2)
	{
		CloseHandle(hFile2);
		UnlockResource(hGlob2);
		FreeResource(hGlob2);	
		if(DeleteFile(m_szFilename2))
			memset(m_szFilename2,0,sizeof m_szFilename2);
	}

	CloseHandle(hFile2);
	UnlockResource(hGlob2);
	FreeResource(hGlob2);
}//----------------

// [en] Make Transparent Region from a bitmap for the  splash screen
// [fr] Crée une region tranparente pour le splach screen
// Thanks to Anthraxx for this function
// Merci a Anthraxx pour cette fonction
HRGN BmpToRgn (HBITMAP hBmp, COLORREF cTransparentColor = 0)
{
	#define ALLOC_UNIT 100
    HRGN hRgn = NULL;
    if (!hBmp) return 0; // si bitmap invalide retourne
    BITMAP bm;
    GetObject(hBmp, sizeof(bm), &bm); // met les infos d'en tete du bitmap dans bm
    UINT siz=bm.bmWidth*bm.bmHeight*4; // enregistre la taille des donnes de l'image
    char *lpBmpBits=(char*)LocalAlloc(LMEM_FIXED,siz); // fait de la place pour les bits du bitmap
    GetBitmapBits(hBmp,siz,lpBmpBits); // obtient les bits de l'image dans l'espace qu'on a reservé
    bm.bmBits=lpBmpBits; // complete la strucutre bm avec les bits
    while (bm.bmWidthBytes % 4) bm.bmWidthBytes++; // bmWidthBytes doit être divisible par 4

    DWORD maxRects = ALLOC_UNIT;
    HANDLE hData = GlobalAlloc(GMEM_MOVEABLE, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects));
    RGNDATA *pData = (RGNDATA *)GlobalLock(hData);
    pData->rdh.dwSize = sizeof(RGNDATAHEADER);
    pData->rdh.iType = RDH_RECTANGLES;
    pData->rdh.nCount = pData->rdh.nRgnSize = 0;
    SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);

    BYTE *p32 = (BYTE *)bm.bmBits;
    for (int y = 0; y < bm.bmHeight; y++) // parcourt toutes les lignes de l'image, de haut en bas
    {
        for (int x = 0; x < bm.bmWidth; x++) // parcourt tous les pixels de la ligne, de gauche à droite
        {
            // Recherche une suite continue de pixels non transparents
            int x0 = x;
            long *p = (long *)(p32 + 4*x);
            while (x < bm.bmWidth)
            {
                if ((unsigned)*p==cTransparentColor)
                    break; // ce pixel est transparent
                p++;
                x++;
            }
            if (x > x0)
            {
                // ajoute les pixels (de (x0, y) à (x, y+1)) à la region en tant que rectangle
                if (pData->rdh.nCount >= maxRects)
                {
                    GlobalUnlock(hData);
                    maxRects += ALLOC_UNIT;
                    hData = GlobalReAlloc(hData, sizeof(RGNDATAHEADER) + 
                        (sizeof(RECT) * maxRects), GMEM_MOVEABLE);
                    pData = (RGNDATA *)GlobalLock(hData);
                }
                RECT *pr = (RECT *)&pData->Buffer;
                SetRect(&pr[pData->rdh.nCount], x0, y, x, y+1);
                if (x0 < pData->rdh.rcBound.left)
                    pData->rdh.rcBound.left = x0;
                if (y < pData->rdh.rcBound.top)
                    pData->rdh.rcBound.top = y;
                if (x > pData->rdh.rcBound.right)
                    pData->rdh.rcBound.right = x;
                if (y+1 > pData->rdh.rcBound.bottom)
                    pData->rdh.rcBound.bottom = y+1;
                pData->rdh.nCount++;

                // Il parait que sous Windows 98, ExtCreateRegion() ne marche pas s'il y a trop de rectangles
                // Pas de panique: on construit la region en deux fois
                if (pData->rdh.nCount == 2000)
                {
                    HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
                    if (hRgn)
                    {
                        CombineRgn(hRgn, hRgn, h, RGN_OR);
                        DeleteObject(h);
                    }
                    else
                        hRgn = h;
                    pData->rdh.nCount = 0;
                    SetRect(&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
                }
            }
        }
        // On passe à la ligne suivante
        p32 += bm.bmWidthBytes;
    }
    // On cree la region
    // (et, s'il y avait plus de 2000 rectangles, on la combine avec celle  créee precedemment)
    HRGN h = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
    if (hRgn)
    {
        CombineRgn(hRgn, hRgn, h, RGN_OR);
        DeleteObject(h);
    }
    else hRgn = h;
    LocalFree((HLOCAL)lpBmpBits);
    return hRgn;
}//----------------

// [en] Commands Sending
// [fr] Envois de commandes
int cmd( int incmd, int wait )
{
	HWND player;

	if (incmd == POWER_OFF)
	{
		MessageBeep(MB_ICONASTERISK);
		joy_conf.nb_pushed++;
		if (joy_conf.nb_pushed >= joy_conf.nb_poweroff )
		{
			Stop = TRUE;
			InitPowerOff();
		}
		Sleep(wait);
		return 1;
	}
	else if (incmd == SCREEN_OFF)
	{
		if ( off == TRUE ) off = FALSE;
		else
		{
			off = TRUE;
			SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_MONITORPOWER  , 2);
		}

		Sleep(wait);
		return 1;
	}

	else if (idplayer == PL_WINAMP)
	{
		
		player = FindWindow("Winamp v1.x", NULL);
		if (player)
		{
			SendMessage(player,WM_COMMAND,incmd,0);
			if ( off == TRUE ) SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_MONITORPOWER  , 2);
			Sleep(wait);
			return 1;
		}
		
		else 
		{
			
			MessageBox(NULL,"Winamp is not running","error",MB_ICONERROR|MB_OK);
			return 0;
		}
		
	}
	
	else if (idplayer == PL_WMP9 || idplayer == PL_WMP8)
	{
		
		player = FindWindow("WMPlayerApp",NULL);
		if (player)
		{
			SendMessage(player,WM_COMMAND,incmd,0);
			if ( off == TRUE ) SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_MONITORPOWER  , 2);
			Sleep(wait);
			return 1;
		}
		
		else 
		{
			
			MessageBox(NULL,"Media Player is not running","error",MB_ICONERROR|MB_OK);
			return 0;
		}
		
	}
	
	else if (idplayer == PL_MMJB)
	{
		
		
		player = FindWindow("MMJB:MAINWND",NULL);
		if (player)
		{
			SendMessage(player,WM_COMMAND,incmd,0);
			if ( off == TRUE ) SendMessage(GetDesktopWindow(), WM_SYSCOMMAND, SC_MONITORPOWER  , 2);
			Sleep(wait);
			return 1;
		}
		
		else 
		{
			
			MessageBox(NULL,"MusicMatch JukeBox is not running","error",MB_ICONERROR|MB_OK);
			return 0;
		}
		
	}
	
	else
	{
		return 0;
	}
		
}//----------------

// [en] Trasform char to return cmds for the selected player
// [fr] Tranformation de char en cmd pour le lecteur
int perform_cmd(char text[255])
{
	if ( !strcmp(text,"Power-Off Computer") )
			return POWER_OFF;
	if ( !strcmp(text,"Power-Off Screen") )
			return SCREEN_OFF;

	if ( idplayer == PL_WINAMP )
	{ 
		if ( !strcmp(text,"Stop") )
			return WINAMP_STOP;
			
		if ( !strcmp(text,"Shuffle") )
			return WINAMP_SHUFFLE;
		if ( !strcmp(text,"Play") )
			return WINAMP_PLAY;
		if ( !strcmp(text,"Pause") )
			return WINAMP_PAUSE;
		if ( !strcmp(text,"Previous") )
			return WINAMP_PREV;
		if ( !strcmp(text,"Next") )
			return WINAMP_NEXT;
		if ( !strcmp(text,"Increase Volume") )
			return WINAMP_VOLUME_UP;
		if ( !strcmp(text,"Decrease Volume") )
			return WINAMP_VOLUME_DOWN;

	}
		
	else if ( idplayer == PL_WMP9 )
	{
		if ( !strcmp(text,"Play") )
			return WMP9_PLAY;
		if ( !strcmp(text,"Stop") )
			return WMP9_STOP;
		if ( !strcmp(text,"Previous") )
			return WMP9_PREV;
		if ( !strcmp(text,"Next") )
			return WMP9_NEXT;
		if ( !strcmp(text,"Increase Volume") )
			return WMP9_VOLUME_UP;
		if ( !strcmp(text,"Decrease Volume") )
			return WMP9_VOLUME_DOWN;
		if ( !strcmp(text,"Mute") )
			return WMP9_VOLUME_MUTE;
		if ( !strcmp(text,"Play Fast") )
			return WMP9_PLAY_FAST;
		if ( !strcmp(text,"Play Normal") )
			return WMP9_PLAY_NORMAL;
		if ( !strcmp(text,"Play Slow") )
			return WMP9_PLAY_SLOW;
		if ( !strcmp(text,"Shuffle") )
			return WMP9_SHUFFLE;
		if ( !strcmp(text,"Repeat") )
			return WMP9_REPEAT;
	}

	else if ( idplayer == PL_WMP8 )
	{
		if ( !strcmp(text,"Play") )
			return WMP8_PLAY;
		if ( !strcmp(text,"Stop") )
			return WMP8_STOP;
		if ( !strcmp(text,"Previous") )
			return WMP8_PREV;
		if ( !strcmp(text,"Next") )
			return WMP8_NEXT;
		if ( !strcmp(text,"Increase Volume") )
			return WMP8_VOLUME_UP;
		if ( !strcmp(text,"Decrease Volume") )
			return WMP8_VOLUME_DOWN;
		if ( !strcmp(text,"Mute") )
			return WMP8_VOLUME_MUTE;
		if ( !strcmp(text,"Shuffle") )
			return WMP8_SHUFFLE;
		if ( !strcmp(text,"Repeat") )
			return WMP8_REPEAT;
	}
		
	else if ( idplayer == PL_MMJB )
	{
		if ( !strcmp(text,"Play") )
			return MMJB_PLAY;
		if ( !strcmp(text,"Pause") )
			return MMJB_PAUSE;
		if ( !strcmp(text,"Previous") )
			return MMJB_PREV;
		if ( !strcmp(text,"Next") )
			return MMJB_NEXT;
		if ( !strcmp(text,"Increase Volume") )
			return MMJB_VOLUME_UP;
		if ( !strcmp(text,"Decrease Volume") )
			return MMJB_VOLUME_DOWN;
		if ( !strcmp(text,"Stop") )
			return MMJB_STOP;
		if ( !strcmp(text,"Mute") )
			return MMJB_MUTE;
		if ( !strcmp(text,"Seek Forward") )
			return MMJB_SEEK_FORWARD;
		if ( !strcmp(text,"Seek Backward") )
			return MMJB_SEEK_BACKWARD;
		if ( !strcmp(text,"Skip Back Tracks") )
			return MMJB_SKIP_BACK_TRACKS;
		if ( !strcmp(text,"Skip Forward Tracks") )
			return MMJB_SKIP_FORWARD_TRACKS;
	}
	return 0;
}//----------------

// [en] Joystick Handling
// [fr] Gestion du Joystick
int joy_control()
{
	JOYINFOEX JoyPos; // Etat actuel et dernier état du joystick
	JOYCAPS CurJoyCaps; // Infos sur les capacités du joystick
	int RefreshTime = 20;
	
	if (joyGetDevCaps(JOYSTICKID1, &CurJoyCaps, sizeof(JOYCAPS)) == JOYERR_NOERROR)
	{

		memset(&(JoyPos.dwFlags),0,sizeof(JOYINFOEX) - sizeof(DWORD));
		joyGetPosEx(JOYSTICKID1,&JoyPos);
		
		while (!Stop)
		{
			memset(&(JoyPos.dwFlags),0,sizeof(JOYINFOEX) - sizeof(DWORD));
			JoyPos.dwFlags = JOY_RETURNBUTTONS;
			joyGetPosEx(JOYSTICKID1,&JoyPos);
			
			if (JoyPos.dwButtons & BOUTON1)
			{ cmd( joy_conf.but_01,100 + joy_conf.wait_01 ); }
			if (JoyPos.dwButtons & BOUTON2)
			{ cmd( joy_conf.but_02,100 + joy_conf.wait_02 ); }
			if (JoyPos.dwButtons & BOUTON3)
			{ cmd( joy_conf.but_03,100 + joy_conf.wait_03 ); }
			if (JoyPos.dwButtons & BOUTON4)
			{ cmd( joy_conf.but_04,100 + joy_conf.wait_04 ); }
			if (JoyPos.dwButtons & BOUTON5)
			{ cmd( joy_conf.but_05,100 + joy_conf.wait_05 ); }
			if (JoyPos.dwButtons & BOUTON6)
			{ cmd( joy_conf.but_06,100 + joy_conf.wait_06 ); }
			if (JoyPos.dwButtons & BOUTON7)
			{ cmd( joy_conf.but_07,100 + joy_conf.wait_07 ); }
			if (JoyPos.dwButtons & BOUTON8)
			{ cmd( joy_conf.but_08,100 + joy_conf.wait_08 ); }
			if (JoyPos.dwButtons & BOUTON9)
			{ cmd( joy_conf.but_09,100 + joy_conf.wait_09 ); }
			if (JoyPos.dwButtons & BOUTON10)
			{ cmd( joy_conf.but_10,100 + joy_conf.wait_10 ); }

			Sleep(RefreshTime);
		}
	}
	else
	{
		MessageBox(NULL,"Undefined Error","Error",MB_ICONERROR|MB_OK);
		return 0;
	}
	return 1;
}//----------------

// [en] Add String to ComboBox
// [fr] Ajoute les commandes aux ComboBoxs
int CB_ADD_WINAMP(HWND cb)
{
	SendMessage(cb, CB_RESETCONTENT,0,0);
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Stop");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Shuffle");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Pause");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Previous");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Next");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Increase Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Decrease Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Computer");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Screen");
	SendMessage(cb, CB_SETCURSEL,0,0);
	return 1;
}
// Idem
int CB_ADD_WMP9(HWND cb)
{
	SendMessage(cb, CB_RESETCONTENT,0,0);
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Stop");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Previous");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Next");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Increase Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Decrease Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Mute");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Shuffle");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Repeat");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play Fast");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play Normal");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play Slow");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Computer");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Screen");
	SendMessage(cb, CB_SETCURSEL,0,0);
	return 1;
}
//Idem
int CB_ADD_WMP8(HWND cb)
{
	SendMessage(cb, CB_RESETCONTENT,0,0);
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Stop");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Previous");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Next");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Increase Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Decrease Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Mute");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Shuffle");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Repeat");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Computer");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Screen");
	SendMessage(cb, CB_SETCURSEL,0,0);
	return 1;
}
// Re
int CB_ADD_MMJB(HWND cb)
{
	SendMessage(cb, CB_RESETCONTENT,0,0);
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Play");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Pause");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Previous");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Next");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Increase Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Decrease Volume");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Stop");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Mute");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Seek Forward");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Seek Backward");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Skip Back Tracks");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Skip Forward Tracks");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Computer");
	SendMessage(cb, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Power-Off Screen");
	SendMessage(cb, CB_SETCURSEL,0,0);
	return 1;
}//----------------

// [en] Fill All ComboBoxes
// [fr] Replis toutes les ComboBoxs
int fill_combobox(HWND hwnd,char Player[255])
{
	if ( !strcmp(Player,"Winamp") )
	{
		idplayer = PL_WINAMP;
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO1));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO2));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO3));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO4));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO5));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO6));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO7));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO8));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO9));
		CB_ADD_WINAMP(GetDlgItem(hwnd,IDC_COMBO10));
		return 1;
	}
		
	else if ( !strcmp(Player,"Media Player 9") )
	{
		idplayer = PL_WMP9;
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO1));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO2));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO3));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO4));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO5));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO6));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO7));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO8));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO9));
		CB_ADD_WMP9(GetDlgItem(hwnd,IDC_COMBO10));
		return 1;
	}
	
	else if ( !strcmp(Player,"Media Player 8") )
	{
		idplayer = PL_WMP8;
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO1));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO2));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO3));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO4));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO5));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO6));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO7));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO8));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO9));
		CB_ADD_WMP8(GetDlgItem(hwnd,IDC_COMBO10));
		return 1;
	}
		
	else if ( !strcmp(Player,"MusicMatch JukeBox") )
	{
		idplayer = PL_MMJB;
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO1));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO2));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO3));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO4));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO5));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO6));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO7));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO8));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO9));
		CB_ADD_MMJB(GetDlgItem(hwnd,IDC_COMBO10));
		return 1;
	}
		
	else
	{
		MessageBox(NULL,"Please Choose a Player","Error",MB_ICONERROR|MB_OK);
		return 0;
	}
}//----------------

// [en] Add Tray Item
// [fr] Ajoute une Icone dans le sytem tray
void AddTrayItem(HWND hWnd, char *tip, HICON hicon)
{
	int len = 0;
	char c_Tip[64];
	strncpy(c_Tip, tip, 63);
	trayicon.cbSize = sizeof(NOTIFYICONDATA);
	trayicon.hWnd = hWnd;
	trayicon.uCallbackMessage = WM_SYSTRAYMSG;
	trayicon.hIcon = hicon;
	trayicon.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
	len = strlen(c_Tip);
	if (c_Tip)
	{	
		strncpy(trayicon.szTip, c_Tip, len);
		trayicon.szTip[len] = 0;
	}
	else
	{
		trayicon.szTip[0] = 0;
	}
	Shell_NotifyIcon(NIM_ADD, &trayicon);
	Shell_NotifyIcon(NIM_MODIFY, &trayicon);

	DestroyIcon(hicon); 
}//----------------

// [en] Del Tray Item
// [fr] Enleve l'icone du System Tray
void DelTrayItem()
{
	Shell_NotifyIcon(NIM_DELETE, &trayicon);
}

LRESULT CALLBACK AboutProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_RBUTTONDOWN:
		case WM_LBUTTONDOWN:
		case WM_CLOSE:
			EndDialog(hwnd,0);
	}
	return 0;
}//-----------------

//[en] Parse Msg From About Dialog
//[fr] Traitement des Message de la fenetre A propos
LRESULT CALLBACK SplashProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_INITDIALOG:
			SendDlgItemMessage(hwnd, IDC_IMG, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)rgn_bitmap );
			rgn = BmpToRgn (rgn_bitmap,0x00FF00FF );

			SetWindowRgn(hwnd, rgn, TRUE);
			GetWindowRect(hwnd,&Rect);
			SetWindowPos(hwnd,HWND_TOPMOST,GetSystemMetrics(SM_CXSCREEN)/2-(Rect.right-Rect.left)/2,
				GetSystemMetrics(SM_CYSCREEN)/2-(Rect.bottom-Rect.top)/2,0,0,SWP_NOSIZE); 

			SetTimer(hwnd, IDT_TIMER, 1000, (TIMERPROC)NULL );
			break;

		case WM_TIMER:
			switch (wParam)
			{
				case IDT_TIMER:
					EndDialog(hwnd, FALSE);
					return 0;
			}
			break;

		case WM_CLOSE:
			EndDialog(hwnd,FALSE);
			break;
	}
	return 0;
}//-----------------

// [en] Parse Msg From Conf Dialog
// [fr] Traitement des Message de la fenetre de config
LRESULT CALLBACK ConfProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{

		case WM_CLOSE:
			EndDialog(hwnd,0);
			break;
		case WM_INITDIALOG:
			GetWindowRect(hwnd,&Rect);
			SetWindowPos(hwnd,HWND_TOPMOST,GetSystemMetrics(SM_CXSCREEN)/2-(Rect.right-Rect.left)/2,
				GetSystemMetrics(SM_CYSCREEN)/2-(Rect.bottom-Rect.top)/2,0,0,SWP_NOSIZE);
			
			SendDlgItemMessage( hwnd,IDC_SLIDER1, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER2, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER3, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER4, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER5, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER6, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER7, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER8, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER9, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));
			SendDlgItemMessage( hwnd,IDC_SLIDER10, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 400));

			SendMessage(hwnd,WM_COMMAND,IDC_LOAD_CONF,0);
			
			SetWindowText(GetDlgItem(hwnd,IDC_JOYINFO),JoyCaps.szPname);
			if ( JoyCaps.wNumButtons < 5 )
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER5),FALSE);	}
			if ( JoyCaps.wNumButtons < 6 )
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER6),FALSE);	}
			if ( JoyCaps.wNumButtons < 7 )
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER7),FALSE);	}
			if ( JoyCaps.wNumButtons < 8 )
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER8),FALSE);	}
			if ( JoyCaps.wNumButtons < 9 )
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER9),FALSE);	}
			if ( JoyCaps.wNumButtons < 10)
			{	EnableWindow(GetDlgItem(hwnd,IDC_SLIDER10),FALSE);	}	
			break;

		case WM_COMMAND:
			switch( wParam )
			{
				case IDC_SAVE_CONF:
					joy_conf.wait_01 = SendDlgItemMessage( hwnd, IDC_SLIDER1, TBM_GETPOS, 0, 0 ); 
					joy_conf.wait_02 = SendDlgItemMessage( hwnd, IDC_SLIDER2, TBM_GETPOS, 0, 0 );
					joy_conf.wait_03 = SendDlgItemMessage( hwnd, IDC_SLIDER3, TBM_GETPOS, 0, 0 );
					joy_conf.wait_04 = SendDlgItemMessage( hwnd, IDC_SLIDER4, TBM_GETPOS, 0, 0 );
					joy_conf.wait_05 = SendDlgItemMessage( hwnd, IDC_SLIDER5, TBM_GETPOS, 0, 0 );
					joy_conf.wait_06 = SendDlgItemMessage( hwnd, IDC_SLIDER6, TBM_GETPOS, 0, 0 );
					joy_conf.wait_07 = SendDlgItemMessage( hwnd, IDC_SLIDER7, TBM_GETPOS, 0, 0 );
					joy_conf.wait_08 = SendDlgItemMessage( hwnd, IDC_SLIDER8, TBM_GETPOS, 0, 0 );
					joy_conf.wait_09 = SendDlgItemMessage( hwnd, IDC_SLIDER9, TBM_GETPOS, 0, 0 );
					joy_conf.wait_10 = SendDlgItemMessage( hwnd, IDC_SLIDER10, TBM_GETPOS, 0, 0 );
					joy_conf.nb_poweroff = GetDlgItemInt( hwnd, IDC_POFFP, NULL, TRUE );
					save_sens_conf();
					break;
				case IDC_LOAD_CONF:
					load_sens_conf();
					SendDlgItemMessage( hwnd, IDC_SLIDER1, TBM_SETPOS, TRUE, joy_conf.wait_01 );
					SendDlgItemMessage( hwnd, IDC_SLIDER2, TBM_SETPOS, TRUE, joy_conf.wait_02 );
					SendDlgItemMessage( hwnd, IDC_SLIDER3, TBM_SETPOS, TRUE, joy_conf.wait_03 );
					SendDlgItemMessage( hwnd, IDC_SLIDER4, TBM_SETPOS, TRUE, joy_conf.wait_04 );
					SendDlgItemMessage( hwnd, IDC_SLIDER5, TBM_SETPOS, TRUE, joy_conf.wait_05 );
					SendDlgItemMessage( hwnd, IDC_SLIDER6, TBM_SETPOS, TRUE, joy_conf.wait_06 );
					SendDlgItemMessage( hwnd, IDC_SLIDER7, TBM_SETPOS, TRUE, joy_conf.wait_07 );
					SendDlgItemMessage( hwnd, IDC_SLIDER8, TBM_SETPOS, TRUE, joy_conf.wait_08 );
					SendDlgItemMessage( hwnd, IDC_SLIDER9, TBM_SETPOS, TRUE, joy_conf.wait_09 );
					SendDlgItemMessage( hwnd, IDC_SLIDER10, TBM_SETPOS, TRUE, joy_conf.wait_10 );
					SetDlgItemInt( hwnd, IDC_POFFP, joy_conf.nb_poweroff, TRUE );
					break;
			}

	}
	return 0;
}//-----------------

// [en]  Parse Msg From Main Dialog
// [fr] Traitement des Message de la fenetre principale
LRESULT CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch(msg)
	{
		case WM_CLOSE:
			if ( Stop == TRUE )
				AddTrayItem(hwnd,"Joystick Input Disabled",SysTicon_DESACT);
			else 
				AddTrayItem(hwnd,"Joystick Input Enabled",SysTicon_ACT);
			ShowWindow(hwnd, SW_HIDE);	
			break;
		
		case WM_INITDIALOG:
			load_sens_conf();

			sysmenu = GetSystemMenu(hwnd,FALSE);
			AppendMenu(sysmenu,MF_SEPARATOR,NULL,NULL);
			AppendMenu(sysmenu,MF_STRING, ID_SYSTRAY_ABOUT, "About");
			AppendMenu(sysmenu,MF_STRING, AJ_CLOSE, "Close");
			AppendMenu(sysmenu,MF_SEPARATOR,NULL,NULL);
			AppendMenu(sysmenu,MF_STRING, IDC_CONTROL, "Start Joy Capture");
			AppendMenu(sysmenu,MF_STRING, IDC_STOP, "Stop Joy Capture");

			// [en] Centering Window
			// [fr] Centrage de La fenetre
			GetWindowRect(hwnd,&Rect);
			SetWindowPos(hwnd,HWND_TOPMOST,GetSystemMetrics(SM_CXSCREEN)/2-(Rect.right-Rect.left)/2,
				GetSystemMetrics(SM_CYSCREEN)/2-(Rect.bottom-Rect.top)/2,0,0,SWP_NOSIZE);
			// [en] Fill Player Selection Combo Boxes
			SendDlgItemMessage( hwnd,IDC_PLAYER, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Winamp" );
			SendDlgItemMessage( hwnd,IDC_PLAYER, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Media Player 9" );
			SendDlgItemMessage( hwnd,IDC_PLAYER, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"Media Player 8" );
			SendDlgItemMessage( hwnd,IDC_PLAYER, CB_ADDSTRING, 0, (LPARAM)(LPCTSTR)"MusicMatch JukeBox" );
			SendMessage( hwnd,WM_COMMAND,IDC_LOAD,0);

			// [en] Setting Icon
			SendMessage(hwnd,WM_SETICON,ICON_BIG|ICON_SMALL,(LPARAM)SysTicon_DESACT);
			SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)SysTicon_DESACT);

			// [en] Checking Joy Capture Disabled
			CheckMenuItem(hMenu,IDC_STOP,MF_CHECKED);
			CheckMenuItem(sysmenu,IDC_STOP,MF_CHECKED);
			EnableWindow(GetDlgItem(hwnd,IDC_STOP),FALSE);

			AddTrayItem(hwnd,"Joystick Input Disabled",SysTicon_DESACT);

			// [en] if NumButtons less than ten disabling unused buttons
			if (joyGetDevCaps(JOYSTICKID1, &JoyCaps, sizeof(JOYCAPS)) == JOYERR_NOERROR )
			{
			if ( JoyCaps.wNumButtons < 5 )
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO5),FALSE);
			if ( JoyCaps.wNumButtons < 6 )
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO6),FALSE);
			if ( JoyCaps.wNumButtons < 7 )
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO7),FALSE);
			if ( JoyCaps.wNumButtons < 8 )
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO8),FALSE);
			if ( JoyCaps.wNumButtons < 9 )
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO9),FALSE);
			if ( JoyCaps.wNumButtons < 10)
				EnableWindow(GetDlgItem(hwnd,IDC_COMBO10),FALSE);
			}
			else 
			{
				// [en\fr] héhé bad boy :-)
				MessageBox(hwnd,"No Joystick found or Joystick Error","Error",MB_ICONERROR|MB_OK);
				PostQuitMessage(0);
			
			}
			joy_conf.nb_pushed = 0;
			break;
			
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		
		case WM_SYSCOMMAND:
		case WM_COMMAND:
			switch( (LOWORD(wParam)) )
			{
				case IDC_COMBO1:
				case IDC_COMBO2:
				case IDC_COMBO3:
				case IDC_COMBO4:
				case IDC_COMBO5:
				case IDC_COMBO6:
				case IDC_COMBO7:
				case IDC_COMBO8:
				case IDC_COMBO9:
				case IDC_COMBO10:
					switch ( HIWORD(wParam) )
					{
						case CBN_SELCHANGE:
							SendMessage(hwnd,WM_COMMAND,IDC_STOP,0);
					}
					break;

				case IDC_PLAYER:
					switch ( HIWORD(wParam) )
					{
						case CBN_SELCHANGE:
							SendMessage(hwnd,WM_COMMAND,IDC_STOP,0);
							GetWindowText(GetDlgItem(hwnd,IDC_PLAYER),GetPlayer,255);
							fill_combobox(hwnd,GetPlayer);
					}
					break;

				case ID_SYSTRAY_HELP:
					extract_help();
					GetCurrentDirectory(256,help);
					strcat(help,"\\help\\help.chm");
								
					if ( ShellExecute(NULL,NULL,help,NULL,NULL,SW_SHOW) <= (HINSTANCE)32 )
					{
						MessageBox(NULL,"Error, Can't open help.chm","Error",100);
					}
					break;

				case ID_SYSTRAY_ABOUT:
					DialogBox(Instance,MAKEINTRESOURCE(IDD_ABOUT),hwnd,(DLGPROC)AboutProc);
					break;

				case AJ_CLOSE:
					DelTrayItem();
					EndDialog(hwnd,0);
					break;

				case IDC_CONF_SENS:
					DialogBox(Instance,MAKEINTRESOURCE(IDD_CONF),hwnd,(DLGPROC)ConfProc);
					break;
				
				case IDC_STOP:
					SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)SysTicon_DESACT);
					SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)SysTicon_DESACT);
					AddTrayItem(hwnd,"Joystick Input Disabled",SysTicon_DESACT);
					CheckMenuItem(hMenu,IDC_CONTROL,MF_UNCHECKED);
					CheckMenuItem(hMenu,IDC_STOP,MF_CHECKED);
					CheckMenuItem(sysmenu,IDC_CONTROL,MF_UNCHECKED);
					CheckMenuItem(sysmenu,IDC_STOP,MF_CHECKED);
					EnableWindow(GetDlgItem(hwnd,IDC_CONTROL),TRUE);
					EnableWindow(GetDlgItem(hwnd,IDC_STOP),FALSE);
					joy_conf.nb_pushed = 0;
					Stop = TRUE;
					break;
				
				case IDC_LOAD:
					load_conf();
					
					SendMessage(GetDlgItem(hwnd,IDC_PLAYER),CB_SETCURSEL,joy_conf.SavedPos_Pl,0);
					GetWindowText(GetDlgItem(hwnd,IDC_PLAYER),GetPlayer,255);
					
					if ( !strcmp(GetPlayer,"Media Player 9") )
						idplayer = PL_WMP9;
					else if ( !strcmp(GetPlayer,"Media Player 8") )
						idplayer = PL_WMP8;
					else if ( !strcmp(GetPlayer,"MusicMatch JukeBox") )
						idplayer = PL_MMJB;
					else if ( !strcmp(GetPlayer,"Winamp") )
						idplayer = PL_WINAMP;
					fill_combobox(hwnd,GetPlayer);
					
					SendDlgItemMessage( hwnd,IDC_COMBO1,CB_SETCURSEL,joy_conf.SavedPos_01,0);
					SendDlgItemMessage( hwnd,IDC_COMBO2,CB_SETCURSEL,joy_conf.SavedPos_02,0);
					SendDlgItemMessage( hwnd,IDC_COMBO3,CB_SETCURSEL,joy_conf.SavedPos_03,0);
					SendDlgItemMessage( hwnd,IDC_COMBO4,CB_SETCURSEL,joy_conf.SavedPos_04,0);
					SendDlgItemMessage( hwnd,IDC_COMBO5,CB_SETCURSEL,joy_conf.SavedPos_05,0);
					SendDlgItemMessage( hwnd,IDC_COMBO6,CB_SETCURSEL,joy_conf.SavedPos_06,0);
					SendDlgItemMessage( hwnd,IDC_COMBO7,CB_SETCURSEL,joy_conf.SavedPos_07,0);
					SendDlgItemMessage( hwnd,IDC_COMBO8,CB_SETCURSEL,joy_conf.SavedPos_08,0);
					SendDlgItemMessage( hwnd,IDC_COMBO9,CB_SETCURSEL,joy_conf.SavedPos_09,0);
					SendDlgItemMessage( hwnd,IDC_COMBO10,CB_SETCURSEL,joy_conf.SavedPos_10,0);
					break;
				
				case IDC_SAVE:
					if( idplayer  )
					{
						joy_conf.SavedPos_Pl = SendDlgItemMessage( hwnd,IDC_PLAYER,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_01 = SendDlgItemMessage( hwnd,IDC_COMBO1,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_02 = SendDlgItemMessage( hwnd,IDC_COMBO2,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_03 = SendDlgItemMessage( hwnd,IDC_COMBO3,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_04 = SendDlgItemMessage( hwnd,IDC_COMBO4,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_05 = SendDlgItemMessage( hwnd,IDC_COMBO5,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_06 = SendDlgItemMessage( hwnd,IDC_COMBO6,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_07 = SendDlgItemMessage( hwnd,IDC_COMBO7,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_08 = SendDlgItemMessage( hwnd,IDC_COMBO8,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_09 = SendDlgItemMessage( hwnd,IDC_COMBO9,CB_GETCURSEL,0,0);
						joy_conf.SavedPos_10 = SendDlgItemMessage( hwnd,IDC_COMBO10,CB_GETCURSEL,0,0);
						save_conf();
					}
					break;
				
				case IDC_CONTROL:
					if( idplayer  )
					{
						SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)SysTicon_ACT);
						SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)SysTicon_ACT);
						AddTrayItem(hwnd,"Joystick Input Enabled",SysTicon_ACT);

						CheckMenuItem(hMenu,IDC_CONTROL,MF_CHECKED);
						CheckMenuItem(sysmenu,IDC_CONTROL,MF_CHECKED);
						CheckMenuItem(hMenu,IDC_STOP,MF_UNCHECKED);
						CheckMenuItem(sysmenu,IDC_STOP,MF_UNCHECKED);

						EnableWindow(GetDlgItem(hwnd,IDC_CONTROL),FALSE);
						EnableWindow(GetDlgItem(hwnd,IDC_STOP),TRUE);

						GetDlgItemText(hwnd,IDC_COMBO1,GetCmd,255);
						joy_conf.but_01 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO2,GetCmd,255);
						joy_conf.but_02 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO3,GetCmd,255);
						joy_conf.but_03 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO4,GetCmd,255);
						joy_conf.but_04 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO5,GetCmd,255);
						joy_conf.but_05 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO6,GetCmd,255);
						joy_conf.but_06 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO7,GetCmd,255);
						joy_conf.but_07 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO8,GetCmd,255);
						joy_conf.but_08 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO9,GetCmd,255);
						joy_conf.but_09 = perform_cmd(GetCmd);
						GetDlgItemText(hwnd,IDC_COMBO10,GetCmd,255);
						joy_conf.but_10 = perform_cmd(GetCmd);
					}
					else 
					{
						MessageBox(NULL,"Please Choose a Player","Error",MB_ICONERROR|MB_OK);
						break;
					}
					Stop = FALSE;
					// [fr] Creation d'un Thread sur la fontion joy_control() afin de ne pas
						// bloquer l'execution du programme
					CreateThread( (LPSECURITY_ATTRIBUTES)NULL,(DWORD)0,
					(LPTHREAD_START_ROUTINE)joy_control,(LPVOID)0,(DWORD)0,(LPDWORD)0 );
					break;
		}
		break;

		case WM_SYSTRAYMSG:
			if ((UINT)lParam == WM_LBUTTONDBLCLK)
			{
				ShowWindow(hwnd, SW_SHOW);
				Sleep(100);
			}
			else if ((UINT)lParam == WM_RBUTTONDOWN)
			{	// [fr] Un petit menu contextuelle sur l'icone pour faire + pro
				POINT lpPoint;
				GetCursorPos(&lpPoint);
				TrackPopupMenuEx(hMenu,TPM_HORIZONTAL|TPM_VERTICAL,lpPoint.x,lpPoint.y,hwnd,NULL);
			}
			break;
	}
	return 0;
}//----------------

// [en] Application Entry Point
// [fr] Debut de L'aplication
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Instance = hInstance;
	
	SysTicon_ACT = LoadIcon( hInstance,MAKEINTRESOURCE(IDI_ICON2) );
	SysTicon_DESACT = LoadIcon( hInstance,MAKEINTRESOURCE(IDI_ICON1) );
	
	hMenuLoad = LoadMenu(hInstance, MAKEINTRESOURCE(IDM_CONTEXT_MENU));
	hMenu = GetSubMenu(hMenuLoad, 0);
	
	srand( (unsigned)time( NULL ) );
	randn =  rand();
	randn = randn %= 3;

	//random Splash
	if ( randn == 0 )
		rgn_bitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP1));
	if ( randn == 1 )
		rgn_bitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP2));
	if ( randn == 2 )
		rgn_bitmap = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_BITMAP3));

	DialogBox(hInstance,MAKEINTRESOURCE(IDD_SPLASH),NULL,(DLGPROC)SplashProc);
	DialogBox(hInstance,MAKEINTRESOURCE(IDD_MAIN),NULL,(DLGPROC)DialogProc);
	return 0;
}

Conclusion :


C'est tout :-)

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.