Заставка

Программирование на старых и современных языках, а так-же дизайн

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Программирование на старых и современных языках, а так-же дизайн » Мои разработки » Простой медиаплееер axFramework v0.1a Dev-C++ 5.11


Простой медиаплееер axFramework v0.1a Dev-C++ 5.11

Сообщений 1 страница 2 из 2

1

Вот код main.cpp:

Код:
#include <windows.h>
#include <button.hpp>
#include <multimedia.hpp>
#define FILENAME	"movie.avi"
#define TITLE    "Simple Media Player"
#define BTN_PLAY	100
#define BTN_PAUSE	101
#define BTN_STOP	102

Button *btnPlay;
Button *btnPause;
Button *btnStop;
Multimedia *mplayer;
char buffer[1024];
bool isOpened;

/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
	switch(Message) {
    case WM_COMMAND:
    	if(btnPlay->isClicked(wParam)) {
        if(isOpened == false) {
        	mplayer->open();
        	mplayer->set_window();
        	isOpened = true;
        }
        
        mplayer->play_video();
        sprintf(buffer, "Playing video \''%s\'", FILENAME);
        SetWindowText(hwnd, buffer);
    	}
    	if(btnPause->isClicked(wParam)) {
        mplayer->stop();    	
        SetWindowText(hwnd, TITLE);        	
    	}
    	if(btnStop->isClicked(wParam)) {
        mplayer->stop();
        mplayer->close();
        isOpened = false;
        SetWindowText(hwnd, TITLE);        	
    	}
    break;
    case WM_CREATE:
    	isOpened = false;
    	btnPlay = new Button("&Play", 10, 10, 100, 20, hwnd, BTN_PLAY);
    	btnPause = new Button("P&ause", 120, 10, 100, 20, hwnd, BTN_PAUSE);
    	btnStop = new Button("&Stop", 230, 10, 100, 20, hwnd, BTN_STOP);
    	mplayer = new Multimedia(FILENAME, "MPEGVideo", hwnd);
    	btnPlay->show();
    	btnPause->show();
    	btnStop->show();
    break;
    
    /* Upon destruction, tell the main thread to stop */
    case WM_DESTROY: {
    	PostQuitMessage(0);
    	break;
    }
    
    /* All other messages (a lot of them) are processed using default procedures */
    default:
    	return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}

/* The 'main' function of Win32 GUI programs: this is where execution starts */
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
	WNDCLASSEX wc; /* A properties struct of our window */
	HWND hwnd; /* A 'HANDLE', hence the H, or a pointer to our window */
	MSG msg; /* A temporary location for all messages */

	/* zero out the struct and set the stuff we want to modify */
	memset(&wc,0,sizeof(wc));
	wc.cbSize     = sizeof(WNDCLASSEX);
	wc.lpfnWndProc	 = WndProc; /* This is where we will send messages to */
	wc.hInstance	 = hInstance;
	wc.hCursor     = LoadCursor(NULL, IDC_ARROW);
	
	/* White, COLOR_WINDOW is just a #define for a system color, try Ctrl+Clicking it */
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
	wc.lpszClassName = "WindowClass";
	wc.hIcon     = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
	wc.hIconSm     = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

	if(!RegisterClassEx(&wc)) {
    MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
    return 0;
	}

	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass",TITLE,WS_VISIBLE|WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, /* x */
    CW_USEDEFAULT, /* y */
    640, /* width */
    480, /* height */
    NULL,NULL,hInstance,NULL);

	if(hwnd == NULL) {
    MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
    return 0;
	}

	/*
    This is the heart of our program where all input is processed and 
    sent to WndProc. Note that GetMessage blocks code flow until it receives something, so
    this loop will not produce unreasonably high CPU usage
	*/
	while(GetMessage(&msg, NULL, 0, 0) > 0) { /* If no error is received... */
    TranslateMessage(&msg); /* Translate key codes to chars if present */
    DispatchMessage(&msg); /* Send it to WndProc */
	}
	return msg.wParam;
}

Результат работы программы можете глянуть тут:
https://cloud.mail.ru/public/Surm/zkRnmWquR

P.S.:Если вдруг не будет работать, то нужно подключить библиотеку -lwinmm в проект.

0

2

Улучшеним наш медиаплеер main.cpp, мы поменяем шрифт кнопок вместо Play, Pause, Stop будем отображать ▶ ❚❚ ▋:

Код:
Button *btnPlay;
Button *btnPause;
Button *btnStop;
Multimedia *mplayer;
char buffer[1024];
bool isOpened;
HFONT hFontMplayer;


/* This is where all the input to the window goes to */
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
	switch(Message) {
    case WM_COMMAND:
    	if(btnPlay->isClicked(wParam)) {
        if(isOpened == false) {
        	mplayer->open();
        	mplayer->set_window();
        	isOpened = true;
        }
        
        mplayer->play_video();
        sprintf(buffer, "Playing video \''%s\'", FILENAME);
        SetWindowText(hwnd, buffer);
    	}
    	if(btnPause->isClicked(wParam)) {
        mplayer->stop();    	
        SetWindowText(hwnd, TITLE);        	
    	}
    	if(btnStop->isClicked(wParam)) {
        mplayer->stop();
        mplayer->close();
        isOpened = false;
        SetWindowText(hwnd, TITLE);        	
    	}
    break;
    case WM_CREATE:
    	isOpened = false;
    	btnPlay = new Button("4", 10, 10, 40, 40, hwnd, BTN_PLAY);
    	btnPause = new Button(";", 60, 10, 40, 40, hwnd, BTN_PAUSE);
    	btnStop = new Button("<", 110, 10, 40, 40, hwnd, BTN_STOP);
    	mplayer = new Multimedia(FILENAME, "MPEGVideo", hwnd);
    	btnPlay->show();
    	btnPause->show();
    	btnStop->show();
    	
    	hFontMplayer = CreateFont(24, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE,DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY, 
VARIABLE_PITCH,TEXT("WebDings"));
            SendMessage(btnPlay->get_handle(), WM_SETFONT, (WPARAM)hFontMplayer, TRUE);
            SendMessage(btnPause->get_handle(), WM_SETFONT, (WPARAM)hFontMplayer, TRUE);
            SendMessage(btnStop->get_handle(), WM_SETFONT, (WPARAM)hFontMplayer, TRUE);
    break;
    
    /* Upon destruction, tell the main thread to stop */
    case WM_DESTROY: {
    	PostQuitMessage(0);
    	break;
    }
    
    /* All other messages (a lot of them) are processed using default procedures */
    default:
    	return DefWindowProc(hwnd, Message, wParam, lParam);
	}
	return 0;
}

Результат:
https://i.ibb.co/W3v4Nqw/result-mplayer-19-05-26-08-2021-min.jpg

0


Вы здесь » Программирование на старых и современных языках, а так-же дизайн » Мои разработки » Простой медиаплееер axFramework v0.1a Dev-C++ 5.11