Archived
making functions universal
This commit is contained in:
1 parent
4636780eb2
commit
b80e177a11
3 files changed
+61
-37
No files matched your search
Binary file not shown.
+4
-2
@@ -12,8 +12,10 @@
|
||||
#define IDI_SMALL 108
|
||||
#define IDC_EASYAUDIOPLAYER 109
|
||||
#define IDR_MAINFRAME 128
|
||||
#define IDC_STATIC -1
|
||||
#define IDC_MENU 200
|
||||
#define ID_PLIK_OD32774 32774
|
||||
#define ID_REFRESH 32775
|
||||
#define IDC_STATIC -1
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
@@ -21,7 +23,7 @@
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#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_SYMED_VALUE 110
|
||||
#endif
|
||||
|
||||
@@ -16,13 +16,19 @@ using std::wstring;
|
||||
#define NOT_PLAYING_LABEL L"Nic nie jest odtwarzane"
|
||||
#define PLAY_LABEL L"Odtwarzaj"
|
||||
#define PAUSE_LABEL L"Pauza"
|
||||
#define EXT_LENGTH 2
|
||||
|
||||
//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"));
|
||||
HINSTANCE globalInstance;
|
||||
MSG msg;
|
||||
wstring ext[EXT_LENGTH] = { L"mp3", L"wav" };
|
||||
|
||||
//PATH VARS
|
||||
TCHAR path[MAX_PATH] = { NULL };
|
||||
TCHAR* selectedItemName = NULL;
|
||||
TCHAR* selected = NULL;
|
||||
|
||||
//STATE VARS
|
||||
BOOL isAutoPlayEnabled = TRUE;
|
||||
BOOL isPlaying = FALSE;
|
||||
BOOL isPaused = FALSE;
|
||||
@@ -72,42 +78,38 @@ void CreateControls(HWND window) {
|
||||
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);
|
||||
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);
|
||||
playButton = EzCreateButton(PLAY_LABEL, 75, 515, 100, 30, window, NULL);
|
||||
SendMessage(playButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||
stopButton = EzCreateButton(L"Zatrzymaj", 195, 515, 100, 30, window, NULL);
|
||||
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, 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);
|
||||
}
|
||||
void GetFiles(TCHAR* inputPath) {
|
||||
wstring findPathS = wstring(inputPath) + L"\\*.mp3";
|
||||
void GetFiles(TCHAR* path, wstring ext) {
|
||||
if (path[0] != NULL) {
|
||||
wstringstream findPathStream;
|
||||
findPathStream << wstring(path);
|
||||
findPathStream << L"\\*.";
|
||||
findPathStream << ext;
|
||||
wstring findPathS = findPathStream.str();
|
||||
LPCWSTR findPath = findPathS.c_str();
|
||||
WIN32_FIND_DATA data;
|
||||
HANDLE hFind = FindFirstFile(findPath, &data);
|
||||
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
|
||||
|
||||
if (hFind != INVALID_HANDLE_VALUE) {
|
||||
do {
|
||||
SendMessage(filesListCtrl, LB_ADDSTRING, NULL, (LPARAM)data.cFileName);
|
||||
} while (FindNextFile(hFind, &data));
|
||||
RECT listWindow;
|
||||
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);
|
||||
EnableWindow(filesListCtrl, TRUE);
|
||||
}
|
||||
}
|
||||
void FolderBrowseDialog(HWND window) {
|
||||
}
|
||||
BOOL FolderBrowseDialog(HWND window) {
|
||||
BROWSEINFO dialog = { 0 };
|
||||
dialog.hwndOwner = window;
|
||||
dialog.ulFlags = BIF_NEWDIALOGSTYLE;
|
||||
@@ -117,7 +119,10 @@ void FolderBrowseDialog(HWND window) {
|
||||
SHGetPathFromIDList(pid, path);
|
||||
SetCurrentDirectory(path);
|
||||
SetWindowText(dirLabel, path);
|
||||
GetFiles(path);
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
void StopSound() {
|
||||
@@ -127,17 +132,18 @@ void StopSound() {
|
||||
SetWindowText(npLabel, NOT_PLAYING_LABEL);
|
||||
EnableWindow(filesListCtrl, TRUE);
|
||||
SetWindowText(playButton, PLAY_LABEL);
|
||||
EnableMenuItem(menuBar, ID_REFRESH, MF_ENABLED);
|
||||
|
||||
//CLOSE FILE
|
||||
mciSendString(L"close mp3", NULL, 0, NULL);
|
||||
}
|
||||
void PlaySelected() {
|
||||
if (path != NULL && selectedItemName != NULL) {
|
||||
void Play(TCHAR* path, TCHAR* fileName) {
|
||||
if (path[0] != NULL && selected != NULL) {
|
||||
//STOP PREVIOUS PLAYBACKS
|
||||
StopSound();
|
||||
|
||||
//GET PATH
|
||||
wstring fullPath = wstring(path) + L"\\" + wstring(selectedItemName);
|
||||
wstring fullPath = wstring(path) + L"\\" + wstring(selected);
|
||||
WIN32_FIND_DATA fileData;
|
||||
HANDLE fileExist = FindFirstFile(fullPath.c_str(), &fileData);
|
||||
if (fileExist == INVALID_HANDLE_VALUE) {
|
||||
@@ -156,9 +162,10 @@ void PlaySelected() {
|
||||
//PREPARE TO PLAY
|
||||
isPlaying = TRUE;
|
||||
isPaused = FALSE;
|
||||
SetWindowText(npLabel, selectedItemName);
|
||||
SetWindowText(npLabel, selected);
|
||||
EnableWindow(filesListCtrl, FALSE);
|
||||
SetWindowText(playButton, PAUSE_LABEL);
|
||||
EnableMenuItem(menuBar, ID_REFRESH, MF_DISABLED);
|
||||
|
||||
//PLAY THE SOUND
|
||||
mciSendString(fullCommand, NULL, 0, NULL);
|
||||
@@ -169,11 +176,11 @@ void PlaySelected() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
void PauseToggle() {
|
||||
if (isPaused == TRUE) {
|
||||
void PauseToggle(BOOL state) {
|
||||
if (state == TRUE) {
|
||||
//PREPARE TO RESUME
|
||||
isPaused = FALSE;
|
||||
SetWindowText(npLabel, selectedItemName);
|
||||
SetWindowText(npLabel, selected);
|
||||
SetWindowText(playButton, PAUSE_LABEL);
|
||||
|
||||
//UNPAUSE
|
||||
@@ -183,7 +190,7 @@ void PauseToggle() {
|
||||
//PREPARE TO PAUSE
|
||||
isPaused = TRUE;
|
||||
wstringstream pauseStringS;
|
||||
pauseStringS << wstring(selectedItemName);
|
||||
pauseStringS << wstring(selected);
|
||||
pauseStringS << " [PAUZA]";
|
||||
wstring pauseStringWS = pauseStringS.str();
|
||||
LPCWSTR pauseString = pauseStringWS.c_str();
|
||||
@@ -220,20 +227,25 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
}
|
||||
}
|
||||
if (selectedItemIndex != -1) {
|
||||
LRESULT selectedItemNameLength = SendMessage(filesListCtrl, LB_GETTEXTLEN, (WPARAM)selectedItemIndex, NULL);
|
||||
selectedItemName = new TCHAR[selectedItemNameLength];
|
||||
SendMessage(filesListCtrl, LB_GETTEXT, (WPARAM)selectedItemIndex, (LPARAM)selectedItemName);
|
||||
LRESULT selectedLength = SendMessage(filesListCtrl, LB_GETTEXTLEN, (WPARAM)selectedItemIndex, NULL);
|
||||
selected = new TCHAR[selectedLength];
|
||||
SendMessage(filesListCtrl, LB_GETTEXT, (WPARAM)selectedItemIndex, (LPARAM)selected);
|
||||
}
|
||||
if (isAutoPlayEnabled == TRUE) {
|
||||
PlaySelected();
|
||||
Play(path, selected);
|
||||
}
|
||||
}
|
||||
if (windowEvent == LBN_SELCANCEL) {
|
||||
selectedItemName = NULL;
|
||||
selected = NULL;
|
||||
}
|
||||
}
|
||||
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) {
|
||||
if (isAutoPlayEnabled) {
|
||||
@@ -250,10 +262,10 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
}
|
||||
else if ((HWND)lParam == playButton) {
|
||||
if (isPlaying == FALSE) {
|
||||
PlaySelected();
|
||||
Play(path, selected);
|
||||
}
|
||||
else {
|
||||
PauseToggle();
|
||||
PauseToggle(isPaused);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,6 +276,16 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
||||
case IDM_ABOUT:
|
||||
DialogBox(globalInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), mainWindow, About);
|
||||
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;
|
||||
case MM_MCINOTIFY:
|
||||
|
||||
Reference in new issue
Block a user