Archived
making functions universal
This commit is contained in:
1 parent
4636780eb2
commit
b80e177a11
3 files changed
+68
-44
No files matched your search
Binary file not shown.
+4
-2
@@ -12,8 +12,10 @@
|
|||||||
#define IDI_SMALL 108
|
#define IDI_SMALL 108
|
||||||
#define IDC_EASYAUDIOPLAYER 109
|
#define IDC_EASYAUDIOPLAYER 109
|
||||||
#define IDR_MAINFRAME 128
|
#define IDR_MAINFRAME 128
|
||||||
|
#define IDC_MENU 200
|
||||||
|
#define ID_PLIK_OD32774 32774
|
||||||
|
#define ID_REFRESH 32775
|
||||||
#define IDC_STATIC -1
|
#define IDC_STATIC -1
|
||||||
#define IDC_MENU 200
|
|
||||||
|
|
||||||
// Next default values for new objects
|
// Next default values for new objects
|
||||||
//
|
//
|
||||||
@@ -21,7 +23,7 @@
|
|||||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
#define _APS_NO_MFC 1
|
#define _APS_NO_MFC 1
|
||||||
#define _APS_NEXT_RESOURCE_VALUE 129
|
#define _APS_NEXT_RESOURCE_VALUE 129
|
||||||
#define _APS_NEXT_COMMAND_VALUE 32774
|
#define _APS_NEXT_COMMAND_VALUE 32776
|
||||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||||
#define _APS_NEXT_SYMED_VALUE 110
|
#define _APS_NEXT_SYMED_VALUE 110
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -16,13 +16,19 @@ using std::wstring;
|
|||||||
#define NOT_PLAYING_LABEL L"Nic nie jest odtwarzane"
|
#define NOT_PLAYING_LABEL L"Nic nie jest odtwarzane"
|
||||||
#define PLAY_LABEL L"Odtwarzaj"
|
#define PLAY_LABEL L"Odtwarzaj"
|
||||||
#define PAUSE_LABEL L"Pauza"
|
#define PAUSE_LABEL L"Pauza"
|
||||||
|
#define EXT_LENGTH 2
|
||||||
|
|
||||||
//GLOBAL VARS
|
//GLOBAL VARS
|
||||||
HFONT hFont = CreateFont(18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Segoe UI"));
|
HFONT hFont = CreateFont(18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Segoe UI"));
|
||||||
HINSTANCE globalInstance;
|
HINSTANCE globalInstance;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
|
wstring ext[EXT_LENGTH] = { L"mp3", L"wav" };
|
||||||
|
|
||||||
|
//PATH VARS
|
||||||
TCHAR path[MAX_PATH] = { NULL };
|
TCHAR path[MAX_PATH] = { NULL };
|
||||||
TCHAR* selectedItemName = NULL;
|
TCHAR* selected = NULL;
|
||||||
|
|
||||||
|
//STATE VARS
|
||||||
BOOL isAutoPlayEnabled = TRUE;
|
BOOL isAutoPlayEnabled = TRUE;
|
||||||
BOOL isPlaying = FALSE;
|
BOOL isPlaying = FALSE;
|
||||||
BOOL isPaused = FALSE;
|
BOOL isPaused = FALSE;
|
||||||
@@ -72,42 +78,38 @@ void CreateControls(HWND window) {
|
|||||||
SendMessage(browseButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(browseButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
filesListCtrl = CreateWindowEx(0, L"LISTBOX", NULL, LBS_STANDARD | WS_CHILD | WS_VISIBLE, 0, 50, 400, 425, window, (HMENU)IDC_LIST, NULL, NULL);
|
filesListCtrl = CreateWindowEx(0, L"LISTBOX", NULL, LBS_STANDARD | WS_CHILD | WS_VISIBLE, 0, 50, 400, 425, window, (HMENU)IDC_LIST, NULL, NULL);
|
||||||
SendMessage(filesListCtrl, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(filesListCtrl, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
npLabel = EzCreateLabel(NOT_PLAYING_LABEL, 0, 460, 400, 30, window, SS_CENTER | WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE);
|
EnableWindow(filesListCtrl, FALSE);
|
||||||
|
npLabel = EzCreateLabel(NOT_PLAYING_LABEL, -5, 460, 400, 30, window, SS_CENTER | WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE);
|
||||||
SendMessage(npLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(npLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
playButton = EzCreateButton(PLAY_LABEL, 75, 515, 100, 30, window, NULL);
|
playButton = EzCreateButton(PLAY_LABEL, 75, 515, 100, 30, window, NULL);
|
||||||
SendMessage(playButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(playButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
stopButton = EzCreateButton(L"Zatrzymaj", 195, 515, 100, 30, window, NULL);
|
stopButton = EzCreateButton(L"Zatrzymaj", 195, 515, 100, 30, window, NULL);
|
||||||
SendMessage(stopButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(stopButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
autoPlayCheck = CreateWindowEx(NULL, L"BUTTON", L"Odtwarzaj automatycznie", BS_CHECKBOX | WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE, 115, 485, 170, 30, window, NULL, NULL, NULL);
|
autoPlayCheck = CreateWindowEx(NULL, L"BUTTON", L"Odtwarzaj automatycznie", BS_CHECKBOX | WS_VISIBLE | WS_CHILD | SS_CENTER | SS_CENTERIMAGE, 105, 485, 170, 30, window, NULL, NULL, NULL);
|
||||||
SendMessage(autoPlayCheck, BM_SETCHECK, BST_CHECKED, NULL);
|
SendMessage(autoPlayCheck, BM_SETCHECK, BST_CHECKED, NULL);
|
||||||
SendMessage(autoPlayCheck, WM_SETFONT, (WPARAM)hFont, TRUE);
|
SendMessage(autoPlayCheck, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||||
filesListScroll = CreateWindowEx(0, L"SCROLLBAR", NULL, WS_CHILD | WS_VISIBLE | SBS_VERT, 300, 50, 50, 425, NULL, NULL, NULL, NULL);
|
filesListScroll = CreateWindowEx(0, L"SCROLLBAR", NULL, WS_CHILD | WS_VISIBLE | SBS_VERT, 300, 50, 50, 425, NULL, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
void GetFiles(TCHAR* inputPath) {
|
void GetFiles(TCHAR* path, wstring ext) {
|
||||||
wstring findPathS = wstring(inputPath) + L"\\*.mp3";
|
if (path[0] != NULL) {
|
||||||
LPCWSTR findPath = findPathS.c_str();
|
wstringstream findPathStream;
|
||||||
WIN32_FIND_DATA data;
|
findPathStream << wstring(path);
|
||||||
HANDLE hFind = FindFirstFile(findPath, &data);
|
findPathStream << L"\\*.";
|
||||||
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
|
findPathStream << ext;
|
||||||
|
wstring findPathS = findPathStream.str();
|
||||||
|
LPCWSTR findPath = findPathS.c_str();
|
||||||
|
WIN32_FIND_DATA data;
|
||||||
|
HANDLE hFind = FindFirstFile(findPath, &data);
|
||||||
|
|
||||||
if (hFind != INVALID_HANDLE_VALUE) {
|
if (hFind != INVALID_HANDLE_VALUE) {
|
||||||
do {
|
do {
|
||||||
SendMessage(filesListCtrl, LB_ADDSTRING, NULL, (LPARAM)data.cFileName);
|
SendMessage(filesListCtrl, LB_ADDSTRING, NULL, (LPARAM)data.cFileName);
|
||||||
} while (FindNextFile(hFind, &data));
|
} while (FindNextFile(hFind, &data));
|
||||||
RECT listWindow;
|
EnableWindow(filesListCtrl, TRUE);
|
||||||
GetClientRect(filesListCtrl, &listWindow);
|
}
|
||||||
SCROLLINFO si;
|
|
||||||
ZeroMemory(&si, sizeof(si));
|
|
||||||
si.cbSize = sizeof(SCROLLINFO);
|
|
||||||
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
|
|
||||||
si.nMin = 0;
|
|
||||||
si.nMax = 1000;
|
|
||||||
si.nPage = listWindow.bottom;
|
|
||||||
si.nPos = 0;
|
|
||||||
SetScrollInfo(filesListCtrl, SB_VERT, &si, TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void FolderBrowseDialog(HWND window) {
|
BOOL FolderBrowseDialog(HWND window) {
|
||||||
BROWSEINFO dialog = { 0 };
|
BROWSEINFO dialog = { 0 };
|
||||||
dialog.hwndOwner = window;
|
dialog.hwndOwner = window;
|
||||||
dialog.ulFlags = BIF_NEWDIALOGSTYLE;
|
dialog.ulFlags = BIF_NEWDIALOGSTYLE;
|
||||||
@@ -117,7 +119,10 @@ void FolderBrowseDialog(HWND window) {
|
|||||||
SHGetPathFromIDList(pid, path);
|
SHGetPathFromIDList(pid, path);
|
||||||
SetCurrentDirectory(path);
|
SetCurrentDirectory(path);
|
||||||
SetWindowText(dirLabel, path);
|
SetWindowText(dirLabel, path);
|
||||||
GetFiles(path);
|
return TRUE;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void StopSound() {
|
void StopSound() {
|
||||||
@@ -127,17 +132,18 @@ void StopSound() {
|
|||||||
SetWindowText(npLabel, NOT_PLAYING_LABEL);
|
SetWindowText(npLabel, NOT_PLAYING_LABEL);
|
||||||
EnableWindow(filesListCtrl, TRUE);
|
EnableWindow(filesListCtrl, TRUE);
|
||||||
SetWindowText(playButton, PLAY_LABEL);
|
SetWindowText(playButton, PLAY_LABEL);
|
||||||
|
EnableMenuItem(menuBar, ID_REFRESH, MF_ENABLED);
|
||||||
|
|
||||||
//CLOSE FILE
|
//CLOSE FILE
|
||||||
mciSendString(L"close mp3", NULL, 0, NULL);
|
mciSendString(L"close mp3", NULL, 0, NULL);
|
||||||
}
|
}
|
||||||
void PlaySelected() {
|
void Play(TCHAR* path, TCHAR* fileName) {
|
||||||
if (path != NULL && selectedItemName != NULL) {
|
if (path[0] != NULL && selected != NULL) {
|
||||||
//STOP PREVIOUS PLAYBACKS
|
//STOP PREVIOUS PLAYBACKS
|
||||||
StopSound();
|
StopSound();
|
||||||
|
|
||||||
//GET PATH
|
//GET PATH
|
||||||
wstring fullPath = wstring(path) + L"\\" + wstring(selectedItemName);
|
wstring fullPath = wstring(path) + L"\\" + wstring(selected);
|
||||||
WIN32_FIND_DATA fileData;
|
WIN32_FIND_DATA fileData;
|
||||||
HANDLE fileExist = FindFirstFile(fullPath.c_str(), &fileData);
|
HANDLE fileExist = FindFirstFile(fullPath.c_str(), &fileData);
|
||||||
if (fileExist == INVALID_HANDLE_VALUE) {
|
if (fileExist == INVALID_HANDLE_VALUE) {
|
||||||
@@ -156,9 +162,10 @@ void PlaySelected() {
|
|||||||
//PREPARE TO PLAY
|
//PREPARE TO PLAY
|
||||||
isPlaying = TRUE;
|
isPlaying = TRUE;
|
||||||
isPaused = FALSE;
|
isPaused = FALSE;
|
||||||
SetWindowText(npLabel, selectedItemName);
|
SetWindowText(npLabel, selected);
|
||||||
EnableWindow(filesListCtrl, FALSE);
|
EnableWindow(filesListCtrl, FALSE);
|
||||||
SetWindowText(playButton, PAUSE_LABEL);
|
SetWindowText(playButton, PAUSE_LABEL);
|
||||||
|
EnableMenuItem(menuBar, ID_REFRESH, MF_DISABLED);
|
||||||
|
|
||||||
//PLAY THE SOUND
|
//PLAY THE SOUND
|
||||||
mciSendString(fullCommand, NULL, 0, NULL);
|
mciSendString(fullCommand, NULL, 0, NULL);
|
||||||
@@ -169,11 +176,11 @@ void PlaySelected() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void PauseToggle() {
|
void PauseToggle(BOOL state) {
|
||||||
if (isPaused == TRUE) {
|
if (state == TRUE) {
|
||||||
//PREPARE TO RESUME
|
//PREPARE TO RESUME
|
||||||
isPaused = FALSE;
|
isPaused = FALSE;
|
||||||
SetWindowText(npLabel, selectedItemName);
|
SetWindowText(npLabel, selected);
|
||||||
SetWindowText(playButton, PAUSE_LABEL);
|
SetWindowText(playButton, PAUSE_LABEL);
|
||||||
|
|
||||||
//UNPAUSE
|
//UNPAUSE
|
||||||
@@ -183,7 +190,7 @@ void PauseToggle() {
|
|||||||
//PREPARE TO PAUSE
|
//PREPARE TO PAUSE
|
||||||
isPaused = TRUE;
|
isPaused = TRUE;
|
||||||
wstringstream pauseStringS;
|
wstringstream pauseStringS;
|
||||||
pauseStringS << wstring(selectedItemName);
|
pauseStringS << wstring(selected);
|
||||||
pauseStringS << " [PAUZA]";
|
pauseStringS << " [PAUZA]";
|
||||||
wstring pauseStringWS = pauseStringS.str();
|
wstring pauseStringWS = pauseStringS.str();
|
||||||
LPCWSTR pauseString = pauseStringWS.c_str();
|
LPCWSTR pauseString = pauseStringWS.c_str();
|
||||||
@@ -220,20 +227,25 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (selectedItemIndex != -1) {
|
if (selectedItemIndex != -1) {
|
||||||
LRESULT selectedItemNameLength = SendMessage(filesListCtrl, LB_GETTEXTLEN, (WPARAM)selectedItemIndex, NULL);
|
LRESULT selectedLength = SendMessage(filesListCtrl, LB_GETTEXTLEN, (WPARAM)selectedItemIndex, NULL);
|
||||||
selectedItemName = new TCHAR[selectedItemNameLength];
|
selected = new TCHAR[selectedLength];
|
||||||
SendMessage(filesListCtrl, LB_GETTEXT, (WPARAM)selectedItemIndex, (LPARAM)selectedItemName);
|
SendMessage(filesListCtrl, LB_GETTEXT, (WPARAM)selectedItemIndex, (LPARAM)selected);
|
||||||
}
|
}
|
||||||
if (isAutoPlayEnabled == TRUE) {
|
if (isAutoPlayEnabled == TRUE) {
|
||||||
PlaySelected();
|
Play(path, selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (windowEvent == LBN_SELCANCEL) {
|
if (windowEvent == LBN_SELCANCEL) {
|
||||||
selectedItemName = NULL;
|
selected = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((HWND)lParam == browseButton) {
|
if ((HWND)lParam == browseButton) {
|
||||||
FolderBrowseDialog(hwnd);
|
if (FolderBrowseDialog(mainWindow) == TRUE) {
|
||||||
|
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
|
||||||
|
for (int i = 0; i < EXT_LENGTH; i++) {
|
||||||
|
GetFiles(path, ext[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if ((HWND)lParam == autoPlayCheck) {
|
else if ((HWND)lParam == autoPlayCheck) {
|
||||||
if (isAutoPlayEnabled) {
|
if (isAutoPlayEnabled) {
|
||||||
@@ -250,10 +262,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
}
|
}
|
||||||
else if ((HWND)lParam == playButton) {
|
else if ((HWND)lParam == playButton) {
|
||||||
if (isPlaying == FALSE) {
|
if (isPlaying == FALSE) {
|
||||||
PlaySelected();
|
Play(path, selected);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PauseToggle();
|
PauseToggle(isPaused);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,6 +276,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|||||||
case IDM_ABOUT:
|
case IDM_ABOUT:
|
||||||
DialogBox(globalInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), mainWindow, About);
|
DialogBox(globalInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), mainWindow, About);
|
||||||
break;
|
break;
|
||||||
|
case ID_REFRESH:
|
||||||
|
if (path[0] != NULL) {
|
||||||
|
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
|
||||||
|
for (int i = 0; i < EXT_LENGTH; i++) {
|
||||||
|
GetFiles(path, ext[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MessageBox(mainWindow, L"Nie za³adowano folderu. Naciœnij przycisk PRZEGL¥DAJ, aby wczytaæ katalog.", L"Brak katalogu", MB_ICONERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MM_MCINOTIFY:
|
case MM_MCINOTIFY:
|
||||||
|
|||||||
Reference in new issue
Block a user