1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
|
#include <windows.h>
#include <commctrl.h>
#include <stdio.h>
#include <stdlib.h>
#include <FMOD/fmod.h>
#include "linkedlist.h"
#include "function.h"
#include "ressource.h"
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL APIENTRY Dlgplaylist(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain (HINSTANCE hThisInstance,
HINSTANCE hPrevInstance,
LPSTR lpszArgument,
int nFunsterStil)
{
HWND hwnd; /* Fenetre Principal */
char szClassName[ ] = "MaClass";
MSG messages; /* Message envoye a l'appli */
WNDCLASSEX clWin; /* Classe de la fenetre principale */
HBRUSH monBrush = CreateSolidBrush(RGB(150,175,255));
//Construction de la classe de la fenetre
clWin.hInstance = hThisInstance;
clWin.lpszClassName = szClassName;
clWin.lpfnWndProc = WindowProcedure; /* This function is called by windows */
clWin.style = 0; /* Catch double-clicks */
clWin.cbSize = sizeof (WNDCLASSEX);
clWin.hIcon = LoadIcon(hThisInstance, MAKEINTRESOURCE(ICONE_SYSTRAY));//LoadIcon(hInst,MAKEINTRESOURCE(ICON_FPRINCIPAL)); //charge l'icône
clWin.hIconSm = LoadIcon(hThisInstance, MAKEINTRESOURCE(ICONE_SYSTRAY));//LoadIcon(hInst,MAKEINTRESOURCE(ICON_FPRINCIPAL));
clWin.hCursor = LoadCursor (NULL, IDC_ARROW);
clWin.lpszMenuName = "MENUPRINC"; /* No menu */
clWin.cbClsExtra = 0; /* No extra bytes after the window class */
clWin.cbWndExtra = 0; /* structure or the window instance */
clWin.hbrBackground = (HBRUSH)monBrush;
/* Register the window class, and if it fails quit the program */
if (!RegisterClassEx (&clWin))
return FALSE;
//Création de la fenetre
hwnd = CreateWindowEx (
0, /* Extended possibilites for variation */
szClassName, /* Classname */
"Lecteur Audio", /* Title Text */
WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX, /* default window */
CW_USEDEFAULT, /* Windows decides the position */
CW_USEDEFAULT, /* where the window ends up on the screen */
370, /* The programs width */
150, /* and height in pixels */
HWND_DESKTOP, /* The window is a child-window to desktop */
NULL, /* No menu */
hThisInstance, /* Program Instance handler */
NULL /* No Window Creation data */
);
/* Affichage de la fenetre */
ShowWindow (hwnd, nFunsterStil);
//Initialisation de FMOD
if (!FSOUND_Init(44100, 32, 0))
{
SetDlgItemText(hwnd,IDE_MUSICNAME,"Erreur lors l'initialisation de FMOD");
}
/* Run the message loop. It will run until GetMessage() returns 0 */
while (GetMessage (&messages, NULL, 0, 0))
{
/* Translate virtual-key messages into character messages */
TranslateMessage(&messages);
/* Send message to WindowProcedure */
DispatchMessage(&messages);
}
//Suppression du brush
DeleteObject(monBrush);
//Fermeture de FMOD
FSOUND_Close();
/* The program return-value is 0 - The value that PostQuitMessage() gave */
return messages.wParam;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static FSOUND_STREAM *musique = NULL;
static HWND slideBar;
static HWND verticalBar;
static unsigned int totalTime =0;
static int stopMAJ = 0;
static llist listeFile = NULL;
static int numPiste = 0;
static HINSTANCE hInst;
static int play = 1;
static HBRUSH monBrush;
static int a=0;
static HMENU sysTrayMenu;
switch(msg)
{
case WM_CREATE:
{
CREATESTRUCT *createParam = (CREATESTRUCT *)lParam;
hInst = createParam->hInstance;
HFONT NewFont;
LOGFONT lf;
HWND tmp = NULL;
ZeroMemory(&lf, sizeof(LOGFONT));
lstrcpy(lf.lfFaceName,"Comic Sans MS");
lf.lfHeight = 20;
lf.lfItalic = TRUE;
lf.lfWeight = 500;
NewFont = CreateFontIndirect(&lf);
tmp = CreateWindow("edit","attente",
WS_CHILD | WS_VISIBLE |ES_AUTOHSCROLL | ES_READONLY | ES_CENTER,10,10,330,20,hwnd,
(HMENU) IDE_MUSICNAME, hInst, NULL);
SendMessage(tmp,WM_SETFONT,(UINT)NewFont,TRUE);
verticalBar = CreateWindow(TRACKBAR_CLASS,"",
WS_CHILD | WS_VISIBLE | TBS_NOTICKS | TBS_VERT ,345,10,20,70,hwnd,
(HMENU) IDSB_VOLUME, hInst, NULL);
SendMessage(verticalBar, TBM_SETRANGE, TRUE, MAKELONG(0,255));
SendMessage(verticalBar,TBM_SETPOS,TRUE,125);
FSOUND_SetVolume(MUSIQUE_FOND, 125); //Le volume (0-255)
slideBar = CreateWindow(TRACKBAR_CLASS,"",
WS_CHILD | WS_VISIBLE | TBS_NOTICKS,10,40,330,25,hwnd,
(HMENU) IDSB_TIME, hInst, NULL);
/*slideBar = CreateWindowEx(0,PROGRESS_CLASS,"",
WS_CHILD | WS_VISIBLE | PBS_SMOOTH
,10,40,330,10,hwnd,
(HMENU) IDSB_TIME, hInst, NULL);*/
SendMessage(slideBar,PBM_SETBARCOLOR,0,RGB(150,175,255));
tmp = CreateWindow("edit","",
WS_CHILD | WS_VISIBLE | ES_READONLY | ES_LEFT,10,80,150,20,hwnd,
(HMENU) IDE_STATUS, hInst, NULL);
SendMessage(tmp,WM_SETFONT,(UINT)NewFont,TRUE);
tmp = CreateWindow("edit","",
WS_CHILD | WS_VISIBLE | ES_READONLY | ES_RIGHT,200,80,140,20,hwnd,
(HMENU) IDE_TIME, hInst, NULL);
SendMessage(tmp,WM_SETFONT,(UINT)NewFont,TRUE);
SetTimer (hwnd,ID_TIMER,1000,NULL);
monBrush = CreateSolidBrush(RGB(150,175,255));
sysTrayMenu = GetSubMenu(LoadMenu(hInst, "MENUSYSTRAY"),0);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDM_QUITTER:
SendMessage(hwnd,WM_DESTROY,0,0);
break;
case IDM_APROPOS:
a++;
break;
case IDM_OUVRIR:
{
OPENFILENAME ofn;
char szFile[MAX_PATH*5]={0};
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH*5;
ofn.nFilterIndex = 2;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER ;
ofn.lpstrTitle = "Ouvrir...";
ofn.lpstrFilter =
"Tous les fichiers (*.*)\0*.*\0Musique\0*.mp3;*.wmv;*.wma;*.ogg\00";
if (GetOpenFileName(&ofn)==TRUE)
{
listeFile = GetSelection(szFile,listeFile);
if (musique != NULL) break;
if (LoadMusicByID(listeFile,hwnd,0,&musique) == SUCCESS)
{
numPiste = 0;
totalTime = FSOUND_Stream_GetLengthMs(musique)/1000;
SendMessage(slideBar, TBM_SETRANGE, TRUE, MAKELONG(0,totalTime));
/* SendMessage(slideBar, PBM_SETRANGE, 0,
MAKELPARAM(0, totalTime));
SendMessage(slideBar, PBM_SETSTEP, (WPARAM) 1, 0);
*/
SetDlgItemText(hwnd,IDE_STATUS,"Stop");
}
}
play = 0;
}
break;
case IDM_PLAY:
if (FSOUND_GetPaused(MUSIQUE_FOND)) // Si la chanson est en pause
FSOUND_SetPaused(MUSIQUE_FOND, 0); // On enlève la pause
else FSOUND_Stream_Play(MUSIQUE_FOND,musique);
SetDlgItemText(hwnd,IDE_STATUS,"Play");
//Reglage du volume
SendMessage(hwnd,WM_VSCROLL,0,(LPARAM)verticalBar);
play = 1;
break;
case IDM_STOP:
FSOUND_Stream_Stop(musique);
SetDlgItemText(hwnd,IDE_STATUS,"Stop");
FSOUND_SetPaused(MUSIQUE_FOND, 0); // On enlève la pause
play = 0;
break;
case IDM_NEXT:
if (LoadMusicByID(listeFile,hwnd,numPiste+1,&musique) == SUCCESS)
{
numPiste++;
totalTime = FSOUND_Stream_GetLengthMs(musique)/1000;
SendMessage(slideBar, TBM_SETRANGE, TRUE, MAKELONG(0,totalTime));
FSOUND_Stream_Play(MUSIQUE_FOND,musique);
SetDlgItemText(hwnd,IDE_STATUS,"Play");
//Reglage du volume
SendMessage(hwnd,WM_VSCROLL,0,(LPARAM)verticalBar);
}
break;
case IDM_BACK:
if (LoadMusicByID(listeFile,hwnd,numPiste-1,&musique) == SUCCESS)
{
numPiste--;
totalTime = FSOUND_Stream_GetLengthMs(musique)/1000;
SendMessage(slideBar, TBM_SETRANGE, TRUE, MAKELONG(0,totalTime));
FSOUND_Stream_Play(MUSIQUE_FOND,musique);
SetDlgItemText(hwnd,IDE_STATUS,"Play");
//Reglage du volume
SendMessage(hwnd,WM_VSCROLL,0,(LPARAM)verticalBar);
}
break;
case IDM_PAUSE:
if (FSOUND_GetPaused(MUSIQUE_FOND)) // Si la chanson est en pause
{
FSOUND_SetPaused(MUSIQUE_FOND, 0); // On enlève la pause
SetDlgItemText(hwnd,IDE_STATUS,"Play");
}
else // Sinon, elle est en cours de lecture
{
FSOUND_SetPaused(MUSIQUE_FOND, 1); // On met en pause
SetDlgItemText(hwnd,IDE_STATUS,"Pause");
}
break;
case IDM_PLAYLIST:
{
//HWND hDial = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_PLAYLIST) , hwnd, (DLGPROC)Dlgplaylist,(LPARAM)listeFile);
HWND hDial = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_PLAYLIST) , hwnd, (DLGPROC)Dlgplaylist,MAKELPARAM(listeFile,hwnd));
ShowWindow (hDial, SW_NORMAL);
}
break;
case IDM_CLEARPL:
listeFile = effacerListe(listeFile);
break;
}
break;
case WM_KEYDOWN:
switch (wParam)
{
case 179 : //VK_MEDIA_PLAY_PAUSE
SendMessage(hwnd,WM_COMMAND,WPARAM(IDM_PLAY),0);
break;
case 178: //VK_MEDIA_STOP
SendMessage(hwnd,WM_COMMAND,WPARAM(IDM_STOP),0);
break;
case 177: //VK_MEDIA_PREV_TRACK
SendMessage(hwnd,WM_COMMAND,WPARAM(IDM_BACK),0);
break;
case 176: //VK_MEDIA_NEXT_TRACK
SendMessage(hwnd,WM_COMMAND,WPARAM(IDM_NEXT),0);
break;
}
break;
case WM_HSCROLL:
if ((HWND)lParam == slideBar)
{
if (LOWORD(wParam)==TB_THUMBTRACK) stopMAJ = 1;
if (LOWORD(wParam)==TB_THUMBPOSITION)
{
unsigned int position = SendMessage(slideBar,TBM_GETPOS,0,0);
FSOUND_Stream_SetTime(musique,position*1000);
stopMAJ = 0;
}
}
break;
case WM_VSCROLL:
if ((HWND)lParam == verticalBar)
{
//if (LOWORD(wParam)==TB_THUMBTRACK)
//{
char tvolume[256];
unsigned int volume = SendMessage(verticalBar,TBM_GETPOS,0,0);
FSOUND_SetVolume(MUSIQUE_FOND, volume);
sprintf(tvolume,"%d",volume);
SetDlgItemText(hwnd,IDE_STATUS,tvolume);
//}
}
break;
case WM_CTLCOLORSTATIC:
{
//On récupère un DC dessus...
HDC textDC = (HDC)wParam;
SetTextColor(textDC,RGB(200,0,125));
//Qui permet de nous donner la main sur le texte à rendre transparent
SetBkMode(textDC, TRANSPARENT);
//Et finalement on retourne une brosse pour colorer son fond. (la même
//que la fenêtre principale)
return (LRESULT)monBrush;
}
break;
case WM_TIMER:
if (musique != NULL)
{
unsigned int tempsEcoule = FSOUND_Stream_GetTime(musique)/1000;
if (!stopMAJ) SendMessage(slideBar,TBM_SETPOS,TRUE,tempsEcoule);//SendMessage(slideBar, PBM_SETPOS, tempsEcoule, 0); //
char temps[256] = {'\0'};
sprintf (temps,"%02d:%02d / %02d:%02d",tempsEcoule/60,tempsEcoule%60,totalTime/60,totalTime%60);
SetDlgItemText(hwnd,IDE_TIME,temps);
char titre[256] = {'\0'};
GetDlgItemText(hwnd,IDE_MUSICNAME,titre,255);
titre[strlen(titre)-4] = '\0';
ModifSysTray(hwnd, titre, temps);
if ((!FSOUND_IsPlaying(MUSIQUE_FOND)) && (play)) SendMessage(hwnd,WM_COMMAND,WPARAM(IDM_NEXT),0);
}
break;
case WM_DESTROY:
if (musique != NULL) FSOUND_Stream_Close(musique);
SetSysTray(hInst, hwnd, false, "");
KillTimer(hwnd,ID_TIMER);
DeleteObject(monBrush);
PostQuitMessage (0); /* send a WM_QUIT to the message queue */
break;
case WM_USER+10:
if (LoadMusicByID(listeFile,hwnd,(int)lParam,&musique) == SUCCESS)
{
numPiste = (int)lParam;
totalTime = FSOUND_Stream_GetLengthMs(musique)/1000;
SendMessage(slideBar, TBM_SETRANGE, TRUE, MAKELONG(0,totalTime));
FSOUND_Stream_Play(MUSIQUE_FOND,musique);
SetDlgItemText(hwnd,IDE_STATUS,"Play");
play = 1;
//Reglage du volume
SendMessage(hwnd,WM_VSCROLL,0,(LPARAM)verticalBar);
}
break;
case WM_SYSCOMMAND:
if(wParam == SC_CLOSE)
{
SetSysTray(hInst, hwnd, true, "Lecteur Audio");
ShowWindow(hwnd, SW_HIDE);
}
else return DefWindowProc (hwnd, msg, wParam, lParam);
break;
case MY_TRAY_MESSAGE:
switch(lParam)
{
case WM_LBUTTONDBLCLK:
SetSysTray(hInst, hwnd, false, "");
ShowWindow(hwnd, SW_RESTORE);
break;
case WM_MBUTTONDOWN:
SetSysTray(hInst, hwnd, false, "");
ShowWindow(hwnd, SW_RESTORE);
break;
case WM_RBUTTONDOWN:
case WM_CONTEXTMENU:
{
POINT pt;
GetCursorPos(&pt); //récupère la postion du curseur
SetForegroundWindow(hwnd);
TrackPopupMenuEx(sysTrayMenu, 0, pt.x, pt.y, hwnd, NULL); //Affiche le menu systray
break;
}
}
break;
default:
return DefWindowProc (hwnd, msg, wParam, lParam);
break;
}
return 0;
}
/******************** Boite de dialogue playlist ***************************/
BOOL APIENTRY Dlgplaylist(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static llist listeFichier = NULL;
static HWND hwndP = NULL;
switch (uMsg)
{
case WM_INITDIALOG:
{
listeFichier = (llist)LOWORD(lParam);
//listeFichier = (llist)lParam;
llist listFile = listeFichier;
hwndP = (HWND)HIWORD(lParam);
char *nomMusique = NULL;
if (listFile == NULL) return TRUE;
HWND listBox = GetDlgItem(hdlg,IDL_PLAYLIST);
while (listFile != NULL)
{
nomMusique = strrchr (listFile->titre,'\\')+1;
SendMessage(listBox,LB_ADDSTRING,0,(LPARAM)nomMusique);
listFile = listFile->nxtElement;
}
return TRUE;
}
case WM_COMMAND:
if(LOWORD(wParam)==IDL_PLAYLIST && HIWORD(wParam)==LBN_DBLCLK)
{
HWND listBox = GetDlgItem(hdlg,IDL_PLAYLIST);
element *nouveau = NULL;
char titre[256] = {'\0'};
char txtRch[256] = {'\0'};
int index = SendMessage(listBox,LB_GETCURSEL,0,0);
SendMessage(listBox,LB_GETTEXT,index,(LPARAM)titre);
sprintf(txtRch,"%s%s","\\",titre);
int indice = rechercherElement(listeFichier, txtRch);
nouveau = element_i(listeFichier, indice);
if (indice < 0) return TRUE;
//HWND hParent = FindWindow("MaClass","Lecteur Audio");
HWND hParent = GetParent(hdlg);
if (hParent != NULL)
SendMessage (hParent,WM_USER+10,0,LPARAM(indice));
else
MessageBox(hdlg,
(LPCTSTR)"Problème de récupération du handle de la fenetre parent",
(LPCTSTR)"titre",
MB_OK | MB_ICONWARNING);
//SendMessage(hwnd,IDE_MUSICNAME,0,(LPARAM)nomMusique);
return TRUE;
}
if(LOWORD(wParam)==IDCANCEL)
{
EndDialog(hdlg,0);
}
return TRUE;
default:
return FALSE;
}
} |
Partager