This repository has been archived on 2025-11-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
ClickPlay/main.cpp
T
2021-05-16 19:48:50 +02:00

121 lines
3.7 KiB
C++

//INCLUDES
#include "EzWinAPIBuilders.h"
#include <ShlObj.h>
//#include <uxtheme.h>
//GLOBAL VARS
MSG msg;
TCHAR* openedPath;
//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);
ShowWindow(mainWindow, nCmdShow);
UpdateWindow(mainWindow);
/*SetWindowTheme(mainWindow, L" ", NULL);*/
/*NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0);
HFONT systemFont = CreateFontIndirect(&ncm.lfMessageFont);
SendMessage(mainWindow, WM_SETFONT, (WPARAM)systemFont, MAKELPARAM(TRUE, 0));*/
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);
browseButton = EzCreateButton(L"Przegl¹daj", 275, 10, 100, 30, window, NULL);
filesListCtrl = EzCreateControl(L"LISTBOX", NULL, 0, 50, 400, 425, window, WS_VISIBLE | WS_VSCROLL | WS_CHILD | ES_AUTOVSCROLL | LBS_NOTIFY);
npLabel = EzCreateLabel(L"Nic nie jest odtwarzane", 0, 475, 400, 30, window, TRUE);
playButton = EzCreateButton(L"Odtwarzaj", 75, 515, 100, 30, window, NULL);
pauseButton = EzCreateButton(L"Zatrzymaj", 195, 515, 100, 30, window, NULL);
autoPlayCheck = EzCreateButton(L"Odtwarzaj automatycznie", 80, 475, 200, 30, window, WS_CHILD | BS_CHECKBOX);
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() {
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_CREATE:
CreateControls(hwnd);
break;
case WM_COMMAND:
if ((HWND)lParam == browseButton) {
MessageBeep(MB_OK);
FolderBrowseDialog(hwnd);
}
else if ((HWND)lParam == filesListCtrl) {
MessageBeep(MB_ICONERROR);
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
}