GetZZLDisplayDlg.cpp
资源名称:p2p_vod.rar [点击查看]
上传用户:liguizhu
上传日期:2015-11-01
资源大小:2422k
文件大小:8k
源码类别:
P2P编程
开发平台:
Visual C++
- /*
- * Openmysee
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- */
- //
- #include "stdafx.h"
- #include "GetZZLDisplay.h"
- #include "GetZZLDisplayDlg.h"
- #include "GetZZL.h"
- #include ".getzzldisplaydlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- END_MESSAGE_MAP()
- // CGetZZLDisplayDlg 对话框
- CGetZZLDisplayDlg::CGetZZLDisplayDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CGetZZLDisplayDlg::IDD, pParent)
- , mstrBufferPath(_T(""))
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CGetZZLDisplayDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_FILE_LST, mLstFile);
- //DDX_Control(pDX, IDC_CHK_ALL, mbtnCheckAll);
- DDX_Text(pDX, IDC_EDT_ZZL_PATH, mstrBufferPath);
- }
- BEGIN_MESSAGE_MAP(CGetZZLDisplayDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_BN_CLICKED(IDC_BTN_ADD, OnBnClickedBtnAdd)
- ON_BN_CLICKED(IDC_BTN_START, OnBnClickedBtnStart)
- ON_BN_CLICKED(IDC_BTN_SET_BAFFER, OnBnClickedBtnSetBaffer)
- ON_BN_CLICKED(IDC_BTN_DEL, OnBnClickedBtnDel)
- ON_BN_CLICKED(IDC_BTN_STOP, OnBnClickedBtnStop)
- ON_WM_CLOSE()
- END_MESSAGE_MAP()
- // CGetZZLDisplayDlg 消息处理程序
- BOOL CGetZZLDisplayDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- //moCommander.CreateInstance();
- mLstFile.ResetContent();
- FILE* lfp = NULL;
- //甚至缓存保存的路径
- char lszBuf[1024] = {0};
- GetModuleFileName(NULL,lszBuf,1024);
- char* lszTemp = strrchr(lszBuf, '\');
- if (NULL != lszTemp)
- {
- *lszTemp = ' ';
- }
- strcat(lszBuf,"\config.dat");
- lfp = fopen(lszBuf, "r");
- if (lfp != NULL)
- {
- int liCount = 0;
- fread(&liCount, sizeof(int), 1, lfp);
- char lpTem[MAX_PATH] = {0};
- fread(lpTem, sizeof(char), liCount, lfp);
- mstrBufferPath = lpTem;
- moCommander.SetBuffer(mstrBufferPath);
- fclose(lfp);
- }
- //mLstFile.AddString("1");
- //mbtnCheckAll = 1;
- UpdateData(false);
- return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
- }
- void CGetZZLDisplayDlg::OnClose()
- {
- FILE* lfp = NULL;
- //甚至缓存读取的路径
- char lszBuf[1024] = {0};
- GetModuleFileName(NULL,lszBuf,1024);
- char* lszTemp = strrchr(lszBuf, '\');
- if (NULL != lszTemp)
- {
- *lszTemp = ' ';
- }
- strcat(lszBuf,"\config.dat");
- lfp = fopen(lszBuf, "w");
- if (lfp != NULL)
- {
- int liCount = mstrBufferPath.GetLength();
- fwrite(&liCount, sizeof(int), 1, lfp);
- fwrite((LPCTSTR)mstrBufferPath, sizeof(char), liCount, lfp);
- fclose(lfp);
- }
- CDialog::OnClose();
- }
- void CGetZZLDisplayDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CGetZZLDisplayDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- HCURSOR CGetZZLDisplayDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CGetZZLDisplayDlg::OnBnClickedBtnAdd()
- {
- CFileDialog loFileDlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT|OFN_EXPLORER|OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
- "AVI Files (*.avi)|*.avi|WAV Files(*.wav)|*.wav|WMV Files (*.wmv)|*.wmv|WMA Files (*.wma)|*.wma||", NULL,0);
- loFileDlg.m_ofn.lStructSize = sizeof(loFileDlg.m_ofn);
- loFileDlg.m_ofn.nMaxFile = 2046;
- loFileDlg.m_ofn.lpstrFile = new char[2046];
- ZeroMemory(loFileDlg.m_ofn.lpstrFile,sizeof(loFileDlg.m_ofn.lpstrFile));
- if (IDOK == loFileDlg.DoModal())
- {
- POSITION pos = loFileDlg.GetStartPosition();
- CString lstrFile;
- CString lstrFileName;
- while (pos != NULL)
- {
- lstrFile =loFileDlg.GetNextPathName(pos);
- char lszFile [MAX_PATH] = {0};
- strcpy(lszFile, (LPCTSTR)lstrFile);
- strlwr(lszFile);
- lstrFile = lszFile;
- //得到其文件名
- char* lszindex = strrchr((LPCTSTR)lstrFile, '\');
- if(lszindex != NULL)
- {
- lszindex++;
- lstrFileName = lszindex;
- }
- if (FALSE == moCommander.SetSourceFile(lstrFile, lstrFileName))
- {
- CString lstr = "文件"" + lstrFileName + ""已经在文件列表里存在";
- MessageBox((LPCTSTR)lstr, "错误",MB_OK|MB_ICONSTOP);
- continue;
- }
- mLstFile.AddString (lstrFileName);
- }
- }
- delete []loFileDlg.m_ofn.lpstrFile;
- loFileDlg.m_ofn.lpstrFile = NULL;
- }
- //开始转换
- void CGetZZLDisplayDlg::OnBnClickedBtnStart()
- {
- if (TRUE == moCommander.RunCommader(this))
- {
- GetDlgItem(IDC_BTN_ADD)->EnableWindow(FALSE);
- GetDlgItem(IDC_BTN_DEL)->EnableWindow(FALSE);
- }
- GetDlgItem(IDC_STATE_TEXT)->SetWindowText(NULL);
- }
- void CGetZZLDisplayDlg::OnBnClickedBtnStop()
- {
- moCommander.Stop();
- moCommander.SetClose();
- GetDlgItem(IDC_STATE_TEXT)->SetWindowText(NULL);
- GetDlgItem(IDC_BTN_ADD)->EnableWindow(TRUE);
- GetDlgItem(IDC_BTN_DEL)->EnableWindow(TRUE);
- }
- void CGetZZLDisplayDlg::OnBnClickedBtnDel()
- {
- int i;
- CString lstrItemText;
- if((i = mLstFile.GetCurSel()) != LB_ERR)
- {
- mLstFile.GetText(i, lstrItemText);
- moCommander.DelSourceFile(lstrItemText);
- mLstFile.DeleteString(i);
- }
- }
- void CGetZZLDisplayDlg::OnBnClickedBtnSetBaffer()
- {
- BROWSEINFO bInfo;
- TCHAR tchPath[255];
- ZeroMemory(&bInfo, sizeof(bInfo));
- bInfo.hwndOwner = m_hWnd;
- bInfo.lpszTitle = _T("所选择路径: ");
- bInfo.ulFlags = BIF_RETURNONLYFSDIRS;
- LPITEMIDLIST lpDlist;
- lpDlist = SHBrowseForFolder(&bInfo);
- if(lpDlist != NULL)
- {
- SHGetPathFromIDList(lpDlist, tchPath);
- //TRACE(tchPath);
- mstrBufferPath = tchPath;
- moCommander.SetBuffer(mstrBufferPath);
- UpdateData(false);
- }
- }