Archived
144 lines
4.9 KiB
C++
144 lines
4.9 KiB
C++
//INCLUDES
|
|
#include "EzWinAPIBuilders.h"
|
|
#include <ShlObj.h>
|
|
#include <debugapi.h>
|
|
#define IDC_LIST 1
|
|
|
|
//GLOBAL VARS
|
|
MSG msg;
|
|
TCHAR* openedPath;
|
|
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"));
|
|
bool isAutoPlayEnabled = true;
|
|
|
|
//CONTROLS
|
|
HWND dirLabel;
|
|
HWND browseButton;
|
|
HWND filesListCtrl;
|
|
HWND filesListScroll;
|
|
HWND playButton;
|
|
HWND pauseButton;
|
|
HWND npLabel;
|
|
HWND autoPlayCheck;
|
|
|
|
//HOOKS
|
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
|
|
|
//EXECUTION PART
|
|
int WINAPI WinMain(HINSTANCE currentInst, HINSTANCE previousInst, LPSTR lpCmdLine, int nCmdShow) {
|
|
WNDCLASSEX windowClass = EzCreateClass(L"Easy Audio Player", WndProc, currentInst, IDI_ERROR, IDC_ARROW);
|
|
if (!RegisterClassEx(&windowClass)) {
|
|
return 1;
|
|
}
|
|
HWND mainWindow = EzCreateWindow(windowClass,currentInst,L"Easy Audio Player", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, 400, 600, NULL);
|
|
SendMessage(mainWindow, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
ShowWindow(mainWindow, nCmdShow);
|
|
UpdateWindow(mainWindow);
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0)) {
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
return msg.wParam;
|
|
|
|
return 0;
|
|
}
|
|
void CreateControls(HWND window) {
|
|
dirLabel = EzCreateLabel(L"Nie wybrano folderu", 10, 10, 250, 30, window, FALSE);
|
|
SendMessage(dirLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
browseButton = EzCreateButton(L"Przegl¹daj", 275, 10, 100, 30, window, NULL);
|
|
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(L"Nic nie jest odtwarzane", 0, 460, 400, 30, window, SS_CENTER | WS_CHILD | WS_VISIBLE | SS_CENTERIMAGE);
|
|
SendMessage(npLabel, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
playButton = EzCreateButton(L"Odtwarzaj", 75, 515, 100, 30, window, NULL);
|
|
SendMessage(playButton, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
pauseButton = EzCreateButton(L"Zatrzymaj", 195, 515, 100, 30, window, NULL);
|
|
SendMessage(pauseButton, 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);
|
|
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* path) {
|
|
openedPath = path;
|
|
path = lstrcat(path, L"\\*.mp3");
|
|
WIN32_FIND_DATA data;
|
|
HANDLE hFind = FindFirstFile(path, &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);
|
|
}
|
|
}
|
|
void 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";
|
|
LPITEMIDLIST pid = SHBrowseForFolder(&dialog);
|
|
TCHAR path[MAX_PATH];
|
|
if (pid != 0) {
|
|
SHGetPathFromIDList(pid, path);
|
|
SetCurrentDirectory(path);
|
|
SetWindowText(dirLabel, path);
|
|
GetFiles(path);
|
|
}
|
|
}
|
|
void PlaySound() {
|
|
mciSendStringW(L"open D:\\grzan\\Music\\NIE.mp3 type mpegvideo alias mp3", NULL, 0, NULL);
|
|
mciSendStringW(L"play mp3 wait", NULL, 0, NULL);
|
|
mciSendStringW(L"close mp3", NULL, 0, NULL);
|
|
}
|
|
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|
int windowId, windowEvent;
|
|
switch (msg) {
|
|
case WM_CLOSE:
|
|
DestroyWindow(hwnd);
|
|
break;
|
|
case WM_DESTROY:
|
|
PostQuitMessage(0);
|
|
break;
|
|
case WM_CREATE:
|
|
CreateControls(hwnd);
|
|
break;
|
|
case WM_COMMAND:
|
|
windowId = LOWORD(wParam);
|
|
windowEvent = HIWORD(wParam);
|
|
if (windowId == IDC_LIST) {
|
|
if (windowEvent == LBN_SELCHANGE) {
|
|
PlaySound();
|
|
}
|
|
}
|
|
if ((HWND)lParam == browseButton) {
|
|
MessageBeep(MB_OK);
|
|
FolderBrowseDialog(hwnd);
|
|
}
|
|
else if ((HWND)lParam == autoPlayCheck) {
|
|
if (isAutoPlayEnabled) {
|
|
SendMessage(autoPlayCheck, BM_SETCHECK, BST_UNCHECKED, NULL);
|
|
isAutoPlayEnabled = false;
|
|
}
|
|
else {
|
|
SendMessage(autoPlayCheck, BM_SETCHECK, BST_CHECKED, NULL);
|
|
isAutoPlayEnabled = true;
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
}
|
|
} |