43 Commits
Author SHA1 Message Date
mmacierzanka be95db47c0 🏁 Final commit to this repository! 2021-06-22 02:12:27 +02:00
mmacierzanka 31fab8ccf1 Revert "1.3.0 EN"
This reverts commit 200fb5c4e1.
2021-06-22 02:08:39 +02:00
mmacierzanka 200fb5c4e1 1.3.0 EN 2021-06-22 01:46:50 +02:00
mmacierzanka 2d30c7a3bf fixed index overflow 2021-06-07 20:53:30 +02:00
mmacierzanka d65b1fa3ec More keyboard shortcuts 2021-06-07 20:18:20 +02:00
mmacierzanka e4b43dbf46 More keyboard shortcuts 2021-06-07 20:15:24 +02:00
mmacierzanka ce81094a62 1.3.0 2021-06-07 20:07:55 +02:00
mmacierzanka 04b51ee5ea improvements 2021-06-07 19:34:02 +02:00
mmacierzanka 40b962250f improved search mechanism 2021-06-07 18:54:52 +02:00
mmacierzanka d633806464 Fixed LBN_SELCHANGE firing when clicking on an empty space 2021-06-07 16:07:42 +02:00
mmacierzanka bbe91b949b more secure jumping 2021-06-07 00:13:38 +02:00
mmacierzanka 981b995308 working jumping 2021-06-06 23:35:07 +02:00
mmacierzanka 40119b2e4e jump to preparing 2021-06-06 22:27:20 +02:00
mmacierzanka caaec15f31 fixed keyboard shortcuts not firing 2021-06-06 21:03:12 +02:00
mmacierzanka 873c785df9 Project configuring (post FINAL milestone) 2021-06-05 01:15:38 +02:00
mmacierzanka d372671f1b 👑👑👑 FINAL COMMIT (showcase milestone) 2021-06-04 23:13:05 +02:00
mmacierzanka f80714542d 1.2.0 - FINAL SHOWCASE VERSION 2021-06-04 16:38:00 +02:00
mmacierzanka d1fd4a6eea fixed manifest file (mistake) 2021-06-04 16:13:59 +02:00
mmacierzanka a20fad4635 modified manifest 2021-06-04 16:12:42 +02:00
mmacierzanka aefd8e6434 modified "about" screen 2021-06-04 15:49:38 +02:00
mmacierzanka 7da19e19e0 changed menu items 2021-06-04 15:40:05 +02:00
mmacierzanka d5b22fc6b2 1.1.1 - more code safety + bug fixes 2021-06-04 14:31:12 +02:00
mmacierzanka 0f39765877 removed unused x86 config 2021-06-04 13:26:12 +02:00
mmacierzanka 6a327c46f3 Cathcing player error + tweaks 2021-06-04 13:20:45 +02:00
mmacierzanka d8649831f8 1.1.0 - autoplay + folder loop + better sorting 2021-06-04 12:52:16 +02:00
mmacierzanka 4539a489a4 numeric sorting 2021-06-04 11:39:31 +02:00
mmacierzanka b66955d5b4 1.0.0 2021-06-03 23:09:25 +02:00
mmacierzanka af56fe3338 1.0.0 RC3 - fixed a bug that could make the program behave weirdly when changing directory 2021-06-03 22:19:51 +02:00
mmacierzanka d536b187ec Bug fixes + tweaks 2021-06-03 22:03:00 +02:00
mmacierzanka 699935c9f8 removed duplicate resource.h 2021-06-03 21:55:45 +02:00
mmacierzanka e463cdab73 security check 2021-06-03 20:40:06 +02:00
mmacierzanka 5b6da80ec2 fixed pause string 2021-06-03 20:28:00 +02:00
mmacierzanka f44f57150b empty dir checking 2021-06-03 20:26:06 +02:00
mmacierzanka 1a3b31ec9e rs 2021-06-03 20:08:54 +02:00
mmacierzanka a7daecd589 Finalazing... (1.0.0 RC1) 2021-06-03 20:08:44 +02:00
mmacierzanka fe27bb453c Structure rework - files array 2021-06-03 16:33:18 +02:00
mmacierzanka 7708e43b3d rs 2021-06-02 22:42:54 +02:00
mmacierzanka bf1d86772a tweaks 2021-06-02 22:42:33 +02:00
mmacierzanka 7088df85e1 search box comments 2021-06-02 22:25:46 +02:00
mmacierzanka a8622f8ea4 working search box PogU 2021-06-02 22:22:34 +02:00
mmacierzanka 1d4699a29b rs 2021-06-02 21:17:31 +02:00
mmacierzanka 87c147685b search box that crashes the program 2021-06-02 21:17:21 +02:00
mmacierzanka b32774b6f1 fixed heap overflow + minor tweaks (0.4.0) 2021-05-31 22:45:38 +02:00
9 changed files with 411 additions and 113 deletions

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
name="CompanyName.ProductName.YourApplication"
type="win32"
/>
<description>PAiPlayer - A school project that helps me learn C++</description>
<description>ClickPlay</description>
<dependency>
<dependentAssembly>
<assemblyIdentity
BIN
View File
Binary file not shown.
-6
View File
@@ -8,19 +8,13 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x64.ActiveCfg = Debug|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x64.Build.0 = Debug|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x86.ActiveCfg = Debug|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Debug|x86.Build.0 = Debug|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x64.ActiveCfg = Release|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x64.Build.0 = Release|x64
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x86.ActiveCfg = Release|Win32
{C734FDA7-262E-4202-8F4E-5E3031CB9935}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
+1 -1
View File
@@ -22,7 +22,7 @@
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{c734fda7-262e-4202-8f4e-5e3031cb9935}</ProjectGuid>
<RootNamespace>EasyAudioPlayer</RootNamespace>
<RootNamespace>ClickPlay</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>ClickPlay</ProjectName>
</PropertyGroup>
-33
View File
@@ -1,33 +0,0 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by ClickPlay.rc
//
#define IDD_CLICKPLAY_DIALOG 102
#define IDS_APP_TITLE 103
#define IDD_ABOUTBOX 103
#define IDM_ABOUT 104
#define IDM_EXIT 105
#define IDI_CLICKPLAY 107
#define IDI_SMALL 108
#define IDC_CLICKPLAY 109
#define IDR_MAINFRAME 128
#define IDC_MENU 200
#define ID_REFRESH 32775
#define ID_OPCJE_POWTARZAJ 32777
#define ID_OPCJE_ONCLICK 32778
#define ID_OPCJE_LOOP 32779
#define ID_POMOC_KBSHR 32783
#define ID_PLIK_CLOSEDIR 32786
#define IDC_STATIC -1
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32789
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+391 -64
View File
@@ -3,17 +3,25 @@
#include "resource.h"
#include <ShlObj.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cwctype>
#include <cstdlib>
#include <time.h>
//IMPORTS
using std::wstring;
using std::vector;
//CONTROL IDS
#define IDC_DIRLABEL 201
#define IDC_BROWSEBTN 202
#define IDC_LIST 203
#define IDC_NPLABEL 204
#define IDC_PLAYBTN 205
#define IDC_STOPBTN 206
#define IDC_SEARCH 204
#define IDC_SEARCHBTN 205
#define IDC_NPLABEL 206
#define IDC_PLAYBTN 207
#define IDC_STOPBTN 208
//STATIC DEFINES
#define EXT_LENGTH 2
@@ -21,10 +29,10 @@ using std::wstring;
//STRING TABLE
#define PROGRAM_NAME L"ClickPlay"
#define NOT_PLAYING_LABEL L"Nic nie jest odtwarzane"
#define NOT_PLAYING_LABEL L"-"
#define PLAY_LABEL L"Odtwarzaj"
#define PAUSE_LABEL L"Pauza"
#define NO_DIR_LOADED_LABEL L"Nie wybrano folderu"
#define NO_DIR_LOADED_LABEL L"Brak katalogu"
//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"));
@@ -33,8 +41,10 @@ MSG msg;
wstring ext[EXT_LENGTH] = { L"mp3", L"wav" };
//PATH VARS
vector<WIN32_FIND_DATA> files;
wstring path;
wstring selected;
wstring currentSearchPhrase;
__int64 selected = -1;
//STATE VARS
/*
@@ -44,15 +54,19 @@ wstring selected;
* 2 - playback paused
*/
int currentState = -1;
BOOL isOnClickPlayEnabled = TRUE;
BOOL isAutoPlayEnabled = TRUE;
BOOL isLoopEnabled = FALSE;
BOOL isQueued = FALSE;
BOOL showExtensions = FALSE;
//CONTROLS
HWND mainWindow;
HWND dirLabel;
HWND browseButton;
HWND filesListCtrl;
HWND searchBox;
HWND searchBtn;
HWND playButton;
HWND stopButton;
HWND npLabel;
@@ -60,7 +74,9 @@ HMENU menuBar;
//HOOKS
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK JumpToProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
bool alphabeticSort(WIN32_FIND_DATA a, WIN32_FIND_DATA b);
//ENTRY POINT
int WINAPI WinMain(HINSTANCE currentInst, HINSTANCE previousInst, LPSTR lpCmdLine, int nCmdShow) {
@@ -95,7 +111,7 @@ int WINAPI WinMain(HINSTANCE currentInst, HINSTANCE previousInst, LPSTR lpCmdLin
//INITIALIZE MESSAGE LOOP
while (GetMessage(&msg, NULL, 0, 0)) {
if (!TranslateAccelerator(msg.hwnd, shortcuts, &msg)) {
if (!TranslateAccelerator(mainWindow, shortcuts, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
@@ -110,9 +126,14 @@ void CreateControls(HWND window) {
SendMessage(dirLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
browseButton = CreateWindowEx(0, L"BUTTON", L"Przegl¹daj", WS_CHILD | WS_VISIBLE, 275, 10, 100, 30, window, (HMENU)IDC_BROWSEBTN, globalInstance, NULL);
SendMessage(browseButton, WM_SETFONT, (WPARAM)hFont, TRUE);
filesListCtrl = CreateWindowEx(0, L"LISTBOX", NULL, LBS_STANDARD | WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 50, 400, 425, window, (HMENU)IDC_LIST, globalInstance, NULL);
filesListCtrl = CreateWindowEx(0, L"LISTBOX", NULL, LBS_NOTIFY | LBS_DISABLENOSCROLL | WS_CHILD | WS_VISIBLE | WS_VSCROLL, 0, 50, 380, 425, window, (HMENU)IDC_LIST, globalInstance, NULL);
SendMessage(filesListCtrl, WM_SETFONT, (WPARAM)hFont, TRUE);
npLabel = CreateWindowEx(0, L"STATIC", NOT_PLAYING_LABEL, SS_CENTER | WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, -5, 460, 400, 40, window, (HMENU)IDC_NPLABEL, globalInstance, NULL);
searchBox = CreateWindowEx(0, L"EDIT", L"", WS_CHILD | WS_VISIBLE, 0, 460, 300, 25, window, (HMENU)IDC_SEARCH, globalInstance, NULL);
SendMessage(searchBox, EM_SETCUEBANNER, FALSE, (LPARAM)L"Wyszukaj pliki...");
SendMessage(searchBox, WM_SETFONT, (WPARAM)hFont, TRUE);
searchBtn = CreateWindowEx(0, L"BUTTON", L"Szukaj", WS_CHILD | WS_VISIBLE, 300, 460, 80, 25, window, (HMENU)IDC_SEARCHBTN, globalInstance, NULL);
SendMessage(searchBtn, WM_SETFONT, (WPARAM)hFont, TRUE);
npLabel = CreateWindowEx(0, L"STATIC", NOT_PLAYING_LABEL, SS_CENTER | WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE, -5, 485, 400, 25, window, (HMENU)IDC_NPLABEL, globalInstance, NULL);
SendMessage(npLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
playButton = CreateWindowEx(0, L"BUTTON", PLAY_LABEL, WS_CHILD | WS_VISIBLE, 75, 515, 100, 30, window, (HMENU)IDC_PLAYBTN, globalInstance, NULL);
SendMessage(playButton, WM_SETFONT, (WPARAM)hFont, TRUE);
@@ -134,7 +155,7 @@ int GetIndex() {
//REMOVE SELECTION
void UnloadSelection() {
mciSendString(L"close mp3", NULL, 0, mainWindow);
selected.clear();
selected = -1;
}
//LOAD SELECTION
@@ -143,27 +164,29 @@ void UnloadSelection() {
* -1 - invalid index
* -2 - file not found
* -3 - path not loaded
* -4 - file loading error
*/
int LoadSelection(int index) {
UnloadSelection();
if (index != -1) {
LRESULT selectedLength = SendMessage(filesListCtrl, LB_GETTEXTLEN, (WPARAM)index, NULL);
TCHAR* selectionBuffer = new TCHAR[selectedLength];
SendMessage(filesListCtrl, LB_GETTEXT, (WPARAM)index, (LPARAM)selectionBuffer);
if (index >= 0) {
if (!path.empty()) {
wstring fullPath = path + L"\\" + selectionBuffer;
wstring fullPath = path + L"\\" + wstring(files[index].cFileName);
WIN32_FIND_DATA fileData;
HANDLE fileExist = FindFirstFile(fullPath.c_str(), &fileData);
if (fileExist == INVALID_HANDLE_VALUE) {
MessageBox(mainWindow, L"Wskazany plik nie zosta³ odnaleziony. Upewnij siê, ¿e nie zosta³ przeniesiony lub naciœnij klawisz F5, aby pozbyæ siê niedzia³aj¹cych pozycji.", L"Nie znaleziono pliku", MB_ICONERROR);
MessageBox(mainWindow, L"Wskazany plik nie zosta³ odnaleziony. Upewnij siê, ¿e nie zosta³ przeniesiony lub usuniêty. Naciœnij klawisz F5, aby odœwie¿yæ listê i pozbyæ siê niedzia³aj¹cych pozycji.", L"Nie znaleziono pliku", MB_ICONERROR);
return -2;
}
else {
wstring fullCommandS = L"open \"" + fullPath + L"\" type mpegvideo alias mp3";
LPCWSTR fullCommand = fullCommandS.c_str();
mciSendString(fullCommand, NULL, 0, mainWindow);
selected = wstring(selectionBuffer);
if (mciSendString(fullCommand, NULL, 0, mainWindow) != 0) {
UnloadSelection();
MessageBox(mainWindow, L"Nieznany b³¹d uniemo¿liwia odtworzenie tego pliku. SprawdŸ czy plik nie jest uszkodzony.", L"B³¹d wczytywania", MB_ICONERROR);
return -4;
}
selected = index;
return 0;
}
}
@@ -178,11 +201,25 @@ int LoadSelection(int index) {
}
}
//FILL THE LIST BOX
void GenerateList(vector<WIN32_FIND_DATA> list) {
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
for (int i = 0; i < list.size(); i++) {
wstring fileName = list[i].cFileName;
if (!showExtensions) {
int dotPos = fileName.find_last_of('.');
fileName.erase(dotPos, 4);
}
SendMessage(filesListCtrl, LB_ADDSTRING, NULL, (LPARAM)fileName.c_str());
}
}
//UNLOAD DIRECTORY
void UnloadDir() {
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
path.clear();
if (!selected.empty()) {
files.clear();
if (selected != -1) {
UnloadSelection();
}
}
@@ -192,13 +229,13 @@ void UnloadDir() {
* ERROR CODES
* -1 - empty string
* -2 - invalid directory
* -3 - empty directory
*/
int LoadDir(wstring dir) {
UnloadDir();
if (!dir.empty()) {
DWORD dirA = GetFileAttributes(dir.c_str());
if (dirA & FILE_ATTRIBUTE_DIRECTORY) {
SendMessage(filesListCtrl, LB_RESETCONTENT, NULL, NULL);
for (int i = 0; i < EXT_LENGTH; i++) {
wstring findPathS = dir + L"\\*." + ext[i];
LPCWSTR findPath = findPathS.c_str();
@@ -206,10 +243,17 @@ int LoadDir(wstring dir) {
HANDLE finder = FindFirstFile(findPath, &dirData);
if (finder != INVALID_HANDLE_VALUE) {
do {
SendMessage(filesListCtrl, LB_ADDSTRING, NULL, (LPARAM)dirData.cFileName);
files.push_back(dirData);
} while (FindNextFile(finder, &dirData));
}
}
if (files.empty()) {
MessageBox(mainWindow, L"Wygl¹da na to, ¿e w tym katalogu nie ma ¿adnych plików, które mog¹ zostaæ otwarte przez program. Wybierz inny folder i spróbuj ponownie.", L"Brak plików", MB_ICONEXCLAMATION);
files.clear();
return -3;
}
std::sort(files.begin(), files.end(), alphabeticSort);
GenerateList(files);
path = dir;
return 0;
}
@@ -219,17 +263,17 @@ int LoadDir(wstring dir) {
}
}
else {
MessageBox(mainWindow, L"Nie za³adowano folderu. U¿yj przycisku PRZEGL¥DAJ, aby za³adaowaæ katalog.", L"Brak katalogu", MB_ICONERROR);
MessageBox(mainWindow, L"Nie wczytano katalogu. U¿yj przycisku PRZEGL¥DAJ, aby za³adaowaæ katalog.", L"Brak katalogu", MB_ICONERROR);
return -1;
}
}
//INITALIZE FOLDER PICKER
BOOL FolderBrowseDialog(HWND window) {
int FolderBrowseDialog(HWND window) {
BROWSEINFO dialog = { 0 };
dialog.hwndOwner = window;
dialog.ulFlags = BIF_NEWDIALOGSTYLE;
dialog.lpszTitle = L"Wybierz folder, który ma zostaæ otwarty przez program";
dialog.lpszTitle = L"Wybierz katalog, który ma zostaæ otwarty przez program...";
LPITEMIDLIST pid = SHBrowseForFolder(&dialog);
TCHAR currentPath[MAX_PATH];
if (pid != 0) {
@@ -237,20 +281,70 @@ BOOL FolderBrowseDialog(HWND window) {
if (LoadDir((wstring)currentPath) == 0) {
SetCurrentDirectory(path.c_str());
SetWindowText(dirLabel, path.c_str());
return TRUE;
return 0;
}
else {
return FALSE;
return -2;
}
}
else {
return FALSE;
return -1;
}
}
//SEARCH DIRECTORY
/*ERROR CODES
* -1 - no files found
* -2 - LoadDir error
* -3 - empty input
*/
int SearchDir(wstring phrase) {
//PERFORM CHECKING
if (path.empty()) {
return -2;
}
if (phrase == currentSearchPhrase) {
return 0;
}
//RELOAD DIR
if (LoadDir(path) != 0) {
return -2;
}
if (phrase.empty()) {
return -3;
}
vector<WIN32_FIND_DATA> results;
//GET FILES
for (int i = 0; i < files.size(); i++) {
if (wstring(files[i].cFileName).find(phrase) != wstring::npos) {
results.push_back(files[i]);
}
}
if (results.empty()) {
MessageBox(mainWindow, L"Nie znaleziono plików zawieraj¹cych wpisan¹ frazê.", L"Brak plików", MB_ICONEXCLAMATION);
currentSearchPhrase.clear();
return -1;
}
std::sort(results.begin(), results.end(), alphabeticSort);
files = results;
currentSearchPhrase = phrase;
//ADD FILTERED CONTENT
GenerateList(files);
return 0;
}
//GET SEARCH PHRASE FROM searchBox
wstring GetSearchPhrase() {
__int64 searchLength = SendMessage(searchBox, WM_GETTEXTLENGTH, 0, NULL);
TCHAR* searchPhrase = new TCHAR[searchLength + 1];
SendMessage(searchBox, WM_GETTEXT, searchLength + 1, (LPARAM)searchPhrase);
searchPhrase[(int)searchLength] = _T('\0');
return wstring(searchPhrase);
}
//MESSAGE LOOP
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
int windowId, windowEvent;
int windowId, windowEvent, randIndex;
switch (msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
@@ -266,42 +360,63 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
windowEvent = HIWORD(wParam);
switch (windowId) {
case ID_PLIK_OPENDIR:
case IDC_BROWSEBTN:
if (FolderBrowseDialog(mainWindow) == TRUE) {
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
switch (FolderBrowseDialog(mainWindow)) {
case 0:
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
break;
case -2:
SendMessage(mainWindow, STATE_CHANGE, -1, NULL);
break;
}
break;
case IDC_LIST:
if (windowEvent == LBN_SELCHANGE) {
if (currentState == 1 || currentState == 2) { currentState = 1; isQueued = TRUE; }
if (LoadSelection(GetIndex()) == 0) {
if (isAutoPlayEnabled == TRUE) {
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
if (selected != SendMessage(filesListCtrl, LB_GETCURSEL, 0, 0)) {
if (currentState == 1 || currentState == 2) { currentState = 1; isQueued = TRUE; }
if (LoadSelection(GetIndex()) == 0) {
if (isOnClickPlayEnabled == TRUE) {
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
}
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
}
break;
case IDC_SEARCHBTN:
if (SearchDir(GetSearchPhrase()) == -2) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case IDC_PLAYBTN:
switch (currentState) {
case 0:
if (LoadSelection(GetIndex()) == 0) {
case 0:
if (LoadSelection(GetIndex()) == 0) {
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case 1:
SendMessage(mainWindow, STATE_CHANGE, 2, NULL);
break;
case 2:
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
}
else {
MessageBox(mainWindow, L"Podczas odtwarzania wyst¹pi³ b³¹d", L"B³¹d odtwarzacza", MB_ICONERROR);
}
break;
case 1:
SendMessage(mainWindow, STATE_CHANGE, 2, NULL);
break;
case 2:
SendMessage(mainWindow, STATE_CHANGE, 1, NULL);
break;
break;
}
break;
case IDC_STOPBTN:
isQueued = FALSE;
SendMessage(mainWindow, MM_MCINOTIFY, 0, 0);
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
SendMessage(filesListCtrl, LB_SETCURSEL, -1, 0);
break;
case IDM_EXIT:
SendMessage(mainWindow, WM_CLOSE, NULL, NULL);
@@ -310,16 +425,23 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
DialogBox(globalInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), mainWindow, About);
break;
case ID_REFRESH:
LoadDir(path);
if (LoadDir(path) != 0) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
if (SendMessage(searchBox, WM_GETTEXTLENGTH, 0, 0) > 0) {
if (SearchDir(GetSearchPhrase()) == -2) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
}
break;
case ID_OPCJE_ONCLICK:
if (isAutoPlayEnabled) {
if (isOnClickPlayEnabled) {
CheckMenuItem(menuBar, ID_OPCJE_ONCLICK, MF_UNCHECKED);
isAutoPlayEnabled = FALSE;
isOnClickPlayEnabled = FALSE;
}
else {
CheckMenuItem(menuBar, ID_OPCJE_ONCLICK, MF_CHECKED);
isAutoPlayEnabled = TRUE;
isOnClickPlayEnabled = TRUE;
}
break;
case ID_OPCJE_LOOP:
@@ -331,19 +453,108 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
CheckMenuItem(menuBar, ID_OPCJE_LOOP, MF_CHECKED);
isLoopEnabled = TRUE;
}
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
SendMessage(filesListCtrl, LB_SETCURSEL, -1, 0);
break;
case ID_POMOC_KBSHR:
MessageBox(mainWindow, L"F1 = ekran skrótów klawiszowych\nF2 = ekran Informacje\nF5 = odœwie¿ listê plików", L"Skróty klawiszowe", MB_ICONASTERISK);
case ID_OPCJE_SHOWEXT:
if (showExtensions) {
CheckMenuItem(menuBar, ID_OPCJE_SHOWEXT, MF_UNCHECKED);
showExtensions = FALSE;
}
else {
CheckMenuItem(menuBar, ID_OPCJE_SHOWEXT, MF_CHECKED);
showExtensions = TRUE;
}
if (!path.empty() && !files.empty()) {
GenerateList(files);
if (selected != -1) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
}
}
break;
case ID_PLIK_CLOSEDIR:
SendMessage(mainWindow, STATE_CHANGE, -1, NULL);
break;
case ID_AKCJE_SRCLEAR:
currentSearchPhrase.clear();
SendMessage(searchBox, WM_SETTEXT, (WPARAM)L"", 0);
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
if (LoadDir(path) != 0) {
SendMessage(mainWindow, STATE_CHANGE, -1, 0);
}
break;
case ID_AKCJE_RANDOM:
if (currentState == 1) {
isQueued = TRUE;
}
//GET SEED
srand(time(NULL));
//LOAD AND PLAY
randIndex = rand() % files.size();
if (randIndex == selected && randIndex + 1 < files.size()) { randIndex += 1; }
if (LoadSelection(randIndex) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, randIndex, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
break;
case ID_OPCJE_AUTOPLAY:
if (isAutoPlayEnabled) {
CheckMenuItem(menuBar, ID_OPCJE_AUTOPLAY, MF_UNCHECKED);
isAutoPlayEnabled = FALSE;
}
else {
CheckMenuItem(menuBar, ID_OPCJE_AUTOPLAY, MF_CHECKED);
isAutoPlayEnabled = TRUE;
}
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
SendMessage(filesListCtrl, LB_SETCURSEL, -1, 0);
break;
case ID_AKCJE_JUMP:
DialogBox(globalInstance, MAKEINTRESOURCE(IDD_JUMPTODIALOG), mainWindow, JumpToProc);
break;
}
break;
case MM_MCINOTIFY:
if (!isQueued) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
if (isAutoPlayEnabled) {
if (selected != -1 && !(selected + 1 > files.size() - 1)) {
if (LoadSelection(selected + 1) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
else if(isLoopEnabled && selected != -1) {
if (LoadSelection(0) == 0) {
SendMessage(filesListCtrl, LB_SETCURSEL, selected, 0);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
}
else {
SendMessage(mainWindow, STATE_CHANGE, 0, 0);
}
}
else {
if (selected != -1) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
SendMessage(filesListCtrl, LB_SETCURSEL, -1, 0);
}
}
}
else {
if (selected != -1) {
UnloadSelection();
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
SendMessage(filesListCtrl, LB_SETCURSEL, -1, 0);
}
}
}
else {
isQueued = FALSE;
@@ -358,9 +569,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
EnableWindow(filesListCtrl, FALSE);
EnableWindow(playButton, FALSE);
EnableWindow(stopButton, FALSE);
EnableWindow(searchBtn, FALSE);
EnableMenuItem(menuBar, ID_REFRESH, MF_DISABLED);
EnableMenuItem(menuBar, ID_PLIK_CLOSEDIR, MF_DISABLED);
EnableMenuItem(menuBar, ID_AKCJE_RANDOM, MF_DISABLED);
EnableMenuItem(menuBar, ID_AKCJE_SRCLEAR, MF_DISABLED);
EnableMenuItem(menuBar, ID_AKCJE_JUMP, MF_DISABLED);
SetWindowText(dirLabel, NO_DIR_LOADED_LABEL);
SetWindowText(npLabel, L"-");
SetWindowText(npLabel, NOT_PLAYING_LABEL);
SetWindowText(playButton, PLAY_LABEL);
break;
case 0:
@@ -368,7 +584,12 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
EnableWindow(filesListCtrl, TRUE);
EnableWindow(playButton, TRUE);
EnableWindow(stopButton, TRUE);
EnableWindow(searchBtn, TRUE);
EnableMenuItem(menuBar, ID_REFRESH, MF_ENABLED);
EnableMenuItem(menuBar, ID_PLIK_CLOSEDIR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_RANDOM, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_SRCLEAR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_JUMP, MF_DISABLED);
SetWindowText(npLabel, NOT_PLAYING_LABEL);
SetWindowText(playButton, PLAY_LABEL);
break;
@@ -378,24 +599,36 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
break;
}
case 1:
if (!path.empty() && !selected.empty()) {
if (!path.empty() && selected != -1) {
int playerState = 0;
if (currentState == 2) {
mciSendString(L"resume mp3", NULL, 0, mainWindow);
playerState = mciSendString(L"resume mp3", NULL, 0, mainWindow);
}
else {
if (isLoopEnabled) {
mciSendString(L"play mp3 repeat", NULL, 0, mainWindow);
if (isLoopEnabled && !isAutoPlayEnabled) {
playerState = mciSendString(L"play mp3 repeat", NULL, 0, mainWindow);
}
else {
mciSendString(L"play mp3 notify", NULL, 0, mainWindow);
playerState = mciSendString(L"play mp3 notify", NULL, 0, mainWindow);
}
}
if (playerState != 0) {
MessageBox(mainWindow, L"Nie uda³o siê odtworzyæ wskazanego pliku. SprawdŸ czy plik nie jest uszkodzony.", L"B³¹d odtwarzania", MB_ICONERROR);
SendMessage(mainWindow, STATE_CHANGE, 0, NULL);
break;
}
EnableWindow(filesListCtrl, TRUE);
EnableWindow(playButton, TRUE);
EnableWindow(stopButton, TRUE);
EnableWindow(searchBtn, TRUE);
EnableMenuItem(menuBar, ID_REFRESH, MF_DISABLED);
SetWindowText(npLabel, selected.c_str());
EnableMenuItem(menuBar, ID_PLIK_CLOSEDIR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_RANDOM, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_SRCLEAR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_JUMP, MF_ENABLED);
SetWindowText(npLabel, files[selected].cFileName);
SetWindowText(playButton, PAUSE_LABEL);
break;
}
@@ -406,13 +639,18 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
case 2:
mciSendString(L"pause mp3", NULL, 0, mainWindow);
wstring pauseStringWS = selected + L" [PAUZA]";
wstring pauseStringWS = wstring(files[selected].cFileName) + L" [PAUZA]";
LPCWSTR pauseString = pauseStringWS.c_str();
EnableWindow(filesListCtrl, TRUE);
EnableWindow(playButton, TRUE);
EnableWindow(stopButton, TRUE);
EnableWindow(searchBtn, TRUE);
EnableMenuItem(menuBar, ID_REFRESH, MF_DISABLED);
EnableMenuItem(menuBar, ID_PLIK_CLOSEDIR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_RANDOM, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_SRCLEAR, MF_ENABLED);
EnableMenuItem(menuBar, ID_AKCJE_JUMP, MF_ENABLED);
SetWindowText(npLabel, pauseString);
SetWindowText(playButton, L"Wznów");
break;
@@ -425,6 +663,59 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
return NULL;
}
//JUMP TO DIALOG LOOP
INT_PTR CALLBACK JumpToProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
switch (msg) {
case WM_INITDIALOG:
SetDlgItemText(hwnd, IDC_TSMIN, L"00");
SetDlgItemText(hwnd, IDC_TSSEC, L"00");
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK) {
TCHAR* minB = new TCHAR[32];
TCHAR* secB = new TCHAR[32];
GetDlgItemText(hwnd, IDC_TSMIN, minB, 30);
GetDlgItemText(hwnd, IDC_TSSEC, secB, 30);
int min = 0;
int sec = 0;
try {
min = std::stoi(minB);
sec = std::stoi(secB);
if (!(min >= 0 && min <= 999 && sec >= 0 && sec <= 59)) {
MessageBox(mainWindow, L"Podane wartoœci s¹ niepoprawne", L"Niepoprawne wartoœci", MB_ICONEXCLAMATION);
EndDialog(hwnd, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
catch (...) {
MessageBox(mainWindow, L"Podane wartoœci s¹ niepoprawne", L"Niepoprawne wartoœci", MB_ICONEXCLAMATION);
EndDialog(hwnd, LOWORD(wParam));
return (INT_PTR)TRUE;
}
int timestamp = (((min * 60) + sec) * 1000);
isQueued = TRUE;
wstring mciCmd = L"play mp3 from " + std::to_wstring(timestamp);
mciSendString(mciCmd.c_str(), NULL, 0, mainWindow);
SendMessage(mainWindow, STATE_CHANGE, 1, 0);
EndDialog(hwnd, LOWORD(wParam));
return (INT_PTR)TRUE;
}
else if (LOWORD(wParam) == IDCANCEL) {
EndDialog(hwnd, LOWORD(wParam));
return (INT_PTR)TRUE;
}
}
return (INT_PTR)FALSE;
}
//ABOUT DIALOG LOOP
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
UNREFERENCED_PARAMETER(lParam);
@@ -440,3 +731,39 @@ INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
}
return (INT_PTR)FALSE;
}
//SORTING FUNCTION
bool alphabeticSort(WIN32_FIND_DATA a, WIN32_FIND_DATA b) {
wstring aStr = a.cFileName;
wstring bStr = b.cFileName;
wstring aBuf;
wstring bBuf;
int aNum = 0;
int bNum = 0;
for (int i = 0; i < aStr.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(aStr.at(i)))) {
aBuf += aStr.at(i);
}
else {
break;
}
}
for (int i = 0; i < bStr.size(); i++) {
if (std::isdigit(static_cast<unsigned char>(bStr.at(i)))) {
bBuf += bStr.at(i);
}
else {
break;
}
}
if (!aBuf.empty()) {
aNum = std::stoi(aBuf);
}
if (!bBuf.empty()) {
bNum = std::stoi(bBuf);
}
if (aNum != 0 || bNum != 0) {
return aNum < bNum;
}
return std::tolower(aStr.at(0)) < std::tolower(bStr.at(0));
}
+18 -8
View File
@@ -11,13 +11,23 @@
#define IDI_SMALL 108
#define IDC_CLICKPLAY 109
#define IDR_MAINFRAME 128
#define IDD_JUMPTODIALOG 130
#define IDC_MENU 200
#define IDC_SEARCHBTN 205
#define IDC_PLAYBTN 207
#define IDC_STOPBTN 208
#define IDC_TSSEC 1000
#define IDC_TSMIN 1001
#define ID_REFRESH 32775
#define ID_OPCJE_POWTARZAJ 32777
#define ID_OPCJE_ONCLICK 32778
#define ID_OPCJE_LOOP 32779
#define ID_POMOC_KBSHR 32783
#define ID_PLIK_CLOSEDIR 32786
#define ID_OPCJE_ONCLICK 32776
#define ID_OPCJE_LOOP 32777
#define ID_PLIK_CLOSEDIR 32778
#define ID_AKCJE_SRCLEAR 32779
#define ID_PLIK_OPENDIR 32780
#define ID_AKCJE_RANDOM 32781
#define ID_OPCJE_SHOWEXT 32782
#define ID_OPCJE_AUTOPLAY 32783
#define ID_AKCJE_JUMP 32784
#define IDC_STATIC -1
// Next default values for new objects
@@ -25,9 +35,9 @@
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 130
#define _APS_NEXT_COMMAND_VALUE 32789
#define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_RESOURCE_VALUE 131
#define _APS_NEXT_COMMAND_VALUE 32785
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 110
#endif
#endif