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
| #include <windows.h>
#include <commctrl.h>
#include <time.h>
#include "header1.h"
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
// winMAIN
{
FSOUND_Init(44100, 32, 0);
FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);
FSOUND_SetDriver(0);
srand(time(NULL));
DialogBox(hinstance, "Dialog5", NULL, (DLGPROC)Dialog5Proc);
}
/******************************************************************************/
BOOL APIENTRY Dialog5Proc(HWND hDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
static HANDLES handles;
static MUSICDATA data = {0, 0, "", "", 255, 0, 0, 0, "", "", ""};
static FSOUND_STREAM *music = NULL;
static int curs = 0, i;
switch (uMsg)
{
case WM_INITDIALOG:
initDialog(hDlg, &handles, &data);
break;
case WM_HSCROLL:
ifScrolling(hDlg, &handles, &data, music);
break;
case WM_TIMER:
everyTimer(hDlg, &handles, &data, music);
break;
case WM_CTLCOLORSTATIC:
{
HDC hdc = reinterpret_cast< HDC >(wParam);
HWND hStatic = reinterpret_cast< HWND >(lParam);
SetBkMode(hdc, TRANSPARENT); //Pour le texte
RECT r, rClient;
//Retrouver les coordonnées du contrôle dans la fenêtre
GetClientRect(hStatic, &rClient);
GetWindowRect(hStatic, &r);
MapWindowPoints(HWND_DESKTOP, hWnd, reinterpret_cast< LPPOINT >(&r), 2);
//Copier la portion du bitmap dans le contrôle:
BitBlt(hdc, 0, 0, rClient.right, rClient.bottom, hDCMemoire, r.left, r.top, SRCCOPY);
HBRUSH hBrush = GetStockBrush(NULL_BRUSH);
lrRetour = reinterpret_cast< LRESULT >(hBrush);
}
break;
case WM_PAINT :
{
HBITMAP hBmp;
HDC hdc;
PAINTSTRUCT ps;
hBmp=LoadImage(NULL,"equalizer.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
hdc = BeginPaint(hDlg, &ps);
DrawState(hdc,NULL,NULL,(long)hBmp,NULL,10,10,0,0,DST_BITMAP);
EndPaint(hDlg, &ps);
DeleteObject(hBmp);
return 0;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
quit(hDlg);
break;
case ID_BROWSE:
{
OPENFILENAME ofn;
CHAR szFile[5000]={0};
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hDlg;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 2998;
ofn.lpstrFilter = "Mpeg layer 3\0*.mp3\0";
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_ALLOWMULTISELECT | OFN_EXPLORER;
if (GetOpenFileName(&ofn)==TRUE)
{
loadSongs(&data, szFile, handles.hList);
EnableWindow(GetDlgItem(hDlg, ID_TBTIME), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_PLAY), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_NEXT), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_STOP), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_SAVE_P), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_CLEAR), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_MODE), TRUE);
}
break;
}
case ID_STOP:
FSOUND_StopSound(0);
SetDlgItemInt(hDlg, ID_TELAPSEDTIME, 0, FALSE);
EnableWindow(GetDlgItem(hDlg, ID_TBTIME), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_TELAPSEDTIME), FALSE);
break;
case ID_CLEAR:
clearPlaylist(&data, handles.hList);
SetDlgItemInt(hDlg, ID_TELAPSEDTIME, 0, FALSE);
EnableWindow(GetDlgItem(hDlg, ID_TELAPSEDTIME), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_TBTIME), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_PLAY), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_NEXT), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_STOP), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_SAVE_P), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_CLEAR), FALSE);
EnableWindow(GetDlgItem(hDlg, ID_MODE), FALSE);
break;
case ID_SAVE_P:
{
if(data.numberItems != 0)
{
OPENFILENAME ofn2;
CHAR szFile2[1000]= "";
ZeroMemory(&ofn2, sizeof(OPENFILENAME));
ofn2.lStructSize = sizeof(OPENFILENAME);
ofn2.hwndOwner = hDlg;
ofn2.lpstrFile = szFile2;
ofn2.nMaxFile = 1000;
ofn2.lpstrFilter = "Mp3 Playlist\0*.m3P\0";
ofn2.nFilterIndex = 1;
ofn2.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
if(GetSaveFileName(&ofn2)==TRUE)
{
strcat(szFile2, ".m3P");
if(savePlaylist(&data, szFile2)==EXIT_SUCCESS)
MessageBox(0, "Playlist successfully saved.", "Saved.", MB_OK);
}
}
else
MessageBox(0, "No songs loaded.", "Nothing to save", MB_OK | MB_ICONWARNING);
break;
}
case ID_OPEN_P:
{
OPENFILENAME ofn;
CHAR szFile[1000]= "";
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hDlg;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 1000;
ofn.lpstrFilter = "Mp3 Playlist\0*.m3P\0";
ofn.nFilterIndex = 1;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
if(GetOpenFileName(&ofn)==TRUE)
{
if(openPlaylist(&data, szFile, handles.hList, hDlg)==EXIT_SUCCESS)
{
MessageBox(0, "Playlist successfully opened.", "Opened", MB_OK);
EnableWindow(GetDlgItem(hDlg, ID_TBTIME), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_PLAY), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_NEXT), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_STOP), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_SAVE_P), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_CLEAR), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_MODE), TRUE);
}
}
}
break;
case ID_PLAY:
{
EnableWindow(GetDlgItem(hDlg, ID_TELAPSEDTIME), TRUE);
EnableWindow(GetDlgItem(hDlg, ID_TBTIME), TRUE);
curs = SendDlgItemMessage(hDlg, ID_LBPATH, LB_GETCURSEL, 0, 0);
music = FSOUND_Stream_Open(data.path[curs+1], 0, 0, 0);
data.elapsedT = 0;
FSOUND_Stream_Play(0, music);
FSOUND_SetVolume(0, data.vol);
data.playing = curs+1;
data.totalT = (FSOUND_Stream_GetLengthMs(music))/1000;
SendMessage(handles.hTimeTB, TBM_SETRANGE,FALSE, MAKELONG(0, data.totalT));
break;
}
case ID_NEXT:
{
data.mode = SendDlgItemMessage(hDlg, ID_MODE, CB_GETCURSEL, 0, 0);
if(data.mode == 1)
{
data.playing += 1;
data.playing = (rand() % (data.numberItems - 0 + 1)) + 0;
}
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), TRUE);
if(data.playing != data.numberItems)
{
EnableWindow(GetDlgItem(hDlg, ID_NEXT), TRUE);
FSOUND_StopSound(0);
music = FSOUND_Stream_Open(data.path[data.playing+1], 0, 0, 0);
data.elapsedT = 0;
FSOUND_Stream_Play(0, music);
FSOUND_SetVolume(0, data.vol);
data.playing++;
data.totalT = (FSOUND_Stream_GetLengthMs(music))/1000;
SendMessage(handles.hList, LB_SETCURSEL, data.playing-1, 0);
SendMessage(handles.hTimeTB, TBM_SETRANGE,FALSE, MAKELONG(0, data.totalT));
}
else
EnableWindow(GetDlgItem(hDlg, ID_NEXT), FALSE);
break;
}
case ID_PREVIOUS:
{
data.mode = SendDlgItemMessage(hDlg, ID_MODE, CB_GETCURSEL, 0, 0);
if(data.mode == 1)
{
data.playing -= 1;
data.playing = (rand() % (data.numberItems - 0 + 1)) + 0;
}
EnableWindow(GetDlgItem(hDlg, ID_NEXT), TRUE);
if(data.playing != 1)
{
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), TRUE);
FSOUND_StopSound(0);
music = FSOUND_Stream_Open(data.path[data.playing-1], 0, 0, 0);
data.elapsedT = 0;
FSOUND_Stream_Play(0, music);
FSOUND_SetVolume(0,data.vol);
data.playing--;
data.totalT = (FSOUND_Stream_GetLengthMs(music))/1000;
SendMessage(handles.hList, LB_SETCURSEL, data.playing-1, 0);
SendMessage(handles.hTimeTB, TBM_SETRANGE,FALSE, MAKELONG(0, data.totalT));
}
else
EnableWindow(GetDlgItem(hDlg, ID_PREVIOUS), FALSE);
break;
}
}
break;
default:
return FALSE;
}
} |
Partager