5,530
社区成员
发帖
与我相关
我的任务
分享
#ifndef _PROCESSBAR_H_
#define _PROCESSBAR_H_
#ifdef UNICODE
#define _sprintf swprintf
#else
#define _sprintf sprintf
#endif
#define PB_GPOGRESS_TEXT_EN 0 /*定义是否在进度条上以文字的形式表示出进度*/
/*每个进度条包含的数据结构*/
typedef struct tagPB
{
double iPos; // 当前的进度
double current_pos_px_; // 当前进度条的位置 单位px
double stride_; // 进度条的步长
double iMin; // 范围的最小值
double iMax; // 范围的最大值
HDC hdcBk; // 每个进度条的背景DC,当需要画进度条的时候,先用该DC擦除进度条背景
POINT pt; // 进度条相对父窗口的位置
}PROGRESSSTRUCT, *LPPROGRESSSTRUCT;
class ProcessBar
{
public:
ProcessBar() {};
~ProcessBar() {};
static LRESULT CALLBACK ProgressBarProc(HWND hpb, UINT msg, WPARAM wParam, LPARAM lParam);
bool InitInstance(HINSTANCE hInst);
bool InitProgressBar(HINSTANCE hInst);
HWND CreateProgressBar( HINSTANCE hInst, HWND parent, int ID, int x, int y, int nWidth,
int nHeight, double range_min, double range_max,
double start_x = 0, double stride = 1.0f);
void SetProgressRange(HWND hpb, double iMin, double iMax);
void GetProgressRange(HWND hpb, double *iMin, double *iMax);
void SetProgressPos(HWND hpb/*, int iPos*/);
double GetProgressPos(HWND hpb);
void DeleteObjects(HWND hpb);
void DrawPbBk(HDC hdc, const LPRECT prect);
void DrawProgress(HDC hdc, const LPRECT prect, double progress);
void GetBkDC(HWND hpb, int iWidth, int iHeight);
void SetCurrentPos(double current_pos_px);
double GetCurrentPos(HWND hpb);
inline void SetPos(double pos)
{
pos_ = pos;
if (hprocessbar_)
{
SetProgressPos(hprocessbar_);
}
}
inline double GetPos()
{
return pos_;
}
private:
CxImage pBackGroundImage;
CxImage pForeGroundImage;
HWND hprocessbar_;
double pos_;
};
#endif
#ifndef _PLAYER_H_
#define _PLAYER_H_
#include "windows.h"
#include "string"
#include "strsafe.h"
#include "iostream"
using namespace std;
class Player
{
public:
Player(string command);
~Player();
int CreateChildProcess(HANDLE hChildStd_OUT_Wr, HANDLE hChildStd_IN_Rd);
string GetErrorInfoWithNum(int number);
inline HANDLE GetChildProcessHandle()
{
return piProcInfo_.hProcess;
}
private:
string command_;
PROCESS_INFORMATION piProcInfo_;
};
#endif
#ifndef _PLAYMANAGE_H_
#define _PLAYMANAGE_H_
#include "Player.h"
#define COMMAND_MAX_CHAR 128
#define BUFSIZE 4096
#define DEBUG
struct VideoInfo
{
int width;
int height;
double total_time_ms;
double current_time_ms_next;
double current_time_ms_last;
};
class PlayerManger
{
typedef struct VideoInfo VideoInfo_;
public:
static PlayerManger* GetInstance()
{
if (NULL == pInstance_)
{
pInstance_ = new PlayerManger();
}
return pInstance_;
}
void SetPlayFlag(bool flag)
{
is_playing_ = flag;
}
bool GetPlayFlag()
{
return is_playing_;
}
int InitPlayerManger(HWND hWnd);
void GetInfo();
string BeginToPlay();
void WriteToPipe(string write_message);
void ReadFromPipe();
string GetCurrentDirectory();
void ThreadIsExit();
inline VideoInfo_ GetVideoInfo()
{
return videoinfo_;
}
inline void SetWriteMessage(string writemessage)
{
write_message_ = writemessage;
}
inline HANDLE ChildProcess()
{
return player_->GetChildProcessHandle();
}
private:
PlayerManger();
static PlayerManger* pInstance_;
Player *player_;
bool is_playing_;
bool while_contine_;
bool is_wait_for_echo_;
VideoInfo_ videoinfo_;
string write_message_;
#ifdef DEBUG
string currentDirectory_;
#endif
// pipe
HANDLE hChildStd_IN_Rd_;
HANDLE hChildStd_IN_Wr_;
HANDLE hChildStd_OUT_Rd_;
HANDLE hChildStd_OUT_Wr_;
};
#endif
void ThreadProc(void *param)
{
int pos = 0;
double current_time_ms, total_time_ms;
while (0 == PlayerManger::GetInstance()->GetVideoInfo().total_time_ms)
{
Sleep(100);
}
current_time_ms = 0;
total_time_ms = PlayerManger::GetInstance()->GetVideoInfo().total_time_ms;
#ifdef DEBUGFILE
fs_win << "total_time_ms : " << total_time_ms << endl;
#endif // !DEBUGFILE
double stride = PROBAR_WIDTH(PlayerManger::GetInstance()->GetVideoInfo().width) / total_time_ms / 10;
while(1)
{
test.SetCurrentPos(stride);
Sleep(100);
}
}
unsigned int __stdcall ThreadFun(PVOID pData)
{
int process_pos = 0;
bool IsSetPos = true;
while (NULL == hpb)
{
Sleep(100);
}
while (IsSetPos)
{
if (MouseUpEvent == ProcessBar::isMouseListener_)
{
test.SetPos(0);
ProcessBar::isMouseListener_ = EventProcessed;
#ifdef DEBUGFILE
fs_win << "trigger monitor : MouseUpEvent !" << endl;
#endif // !DEBUGFILE
}
else if (EventProcessed == ProcessBar::isMouseListener_)
{
test.SetPos(0);
#ifdef DEBUGFILE
fs_win << "trigger monitor : EventProcessed !" << endl;
#endif // !DEBUGFILE
}
else
{
#ifdef DEBUGFILE
fs_win << " Never had the mouse-down event !" << endl;
#endif // !DEBUGFILE
if (process_pos <= 100)
{
test.SetPos(0);
}
else
{
IsSetPos = false;
}
}
Sleep(100);
}
return 0;
}