zoukankan      html  css  js  c++  java
  • MFC框架程序实现十一

    void CDlgBaseControlDlg::OnOpenfile()
    {
     // TODO: Add your control notification handler code here
     char szFilter[]=
      "视频文件(*.avi)|*.avi|所有文件(*.*)|*.*||";
     CFileDialog dlg(TRUE,NULL,NULL,
      OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
      szFilter);
     if (IDOK!=dlg.DoModal())
     {
      return;
     }
        //显示文件路径
     m_strFilePath=dlg.GetPathName();
     UpdateData(FALSE);
     //在文件列表中显示文件名称
     CString strFileName=dlg.GetFileName();
        if(LB_ERR==m_wndFileName.FindString(-1,strFileName))
        {
      //添加数据项(文件名称),返回该数据项的索引
      int nItem=m_wndFileName.AddString(strFileName);
      //每一个文件名称对应一个文件路径
      CString *pPath=new CString;
      *pPath=m_strFilePath;
      //通过添加数据项的附加数据保存文件路径
            m_wndFileName.SetItemData(nItem,(DWORD)pPath);

     }
     //播放文件
     Play();
     
    }

    void CDlgBaseControlDlg::OnDblclkFilename()
    {
     // TODO: Add your control notification handler code here
     //获取文件名称列表中当前选择项
     int nCurSel=m_wndFileName.GetCurSel();
     if (LB_ERR==nCurSel)
     {
      return;
     }
     //播放文件,需要获取当前选择项对应的文件路径
        CString *pPath=(CString*)
      m_wndFileName.GetItemData(nCurSel);
        m_strFilePath=*pPath;
     UpdateData(FALSE);
     //MessageBox(*pPath);
     //播放文件
        Play();

    }

    void CDlgBaseControlDlg::Play()
    {
     int nRep=0;//播放次数
     //如果选中了重复播放,在组合框中选择播放次数
     //否则
     if (m_wndReplay.GetCheck())
     {
      //获取组合框中当前选择项
      int nCur=m_wndPlayCount.GetCurSel();
      switch (nCur)
      {
      case 0://无限循环
       nRep=-1;
       break;
      case 1://重复一次
       nRep=2;
       break;
      case 2://重复两次
       nRep=3;
       break;
      }
     }
     else
     {
      nRep=1;
     }
     m_wndAnimate.Open(m_strFilePath);
     m_wndAnimate.Play(0,-1,nRep);
    }

    void CDlgBaseControlDlg::OnReplay()
    {
     // TODO: Add your control notification handler code here
     if (m_wndReplay.GetCheck())
     {
      m_wndPlayCount.EnableWindow(TRUE);
     }
     else
     {
      m_wndPlayCount.EnableWindow(FALSE);
     }
    }

    void CDlgBaseControlDlg::OnPlay()
    {
     // TODO: Add your control notification handler code here
     Play();
    }

    void CDlgBaseControlDlg::OnStop()
    {
     // TODO: Add your control notification handler code here
     m_wndAnimate.Stop();
    }

    void CDlgBaseControlDlg::OnSetup()
    {
     // TODO: Add your control notification handler code here
     //获取热键
     DWORD nHotKey=m_wndHotkey.GetHotKey();
     SendMessage(WM_SETHOTKEY,nHotKey);
    }

    class CPage1 : public CPropertyPage
    {
     DECLARE_DYNCREATE(CPage1)

    public:
     CPage1();
     ~CPage1();

     enum { IDD = IDD_PAGE1 };
     UINT m_nLineWidth;
     public:
     virtual BOOL OnApply();
     protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    protected:
     afx_msg void OnChangeWidth();
     DECLARE_MESSAGE_MAP()

    };

    class CPage2 : public CPropertyPage
    {
     DECLARE_DYNCREATE(CPage2)

    public:
     CPage2();
     ~CPage2();
    public:
     COLORREF m_color;
     enum { IDD = IDD_PAGE2 };

     public:
     virtual BOOL OnApply();
     protected:
     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    protected:
     afx_msg void OnColor();
     DECLARE_MESSAGE_MAP()

    };
    IMPLEMENT_DYNCREATE(CPage1, CPropertyPage)
    CPage1::CPage1() : CPropertyPage(CPage1::IDD)
    {

     m_nLineWidth = 0;
        //在构造函数中,获取视图的线宽赋值给变量
     //1 获取当前视图
     CLabelPropView* pView=(CLabelPropView*)
     ((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
     //2将视图的值赋值给页面对话框
        m_nLineWidth=pView->m_nLineWidth;
    }

    void CPage1::DoDataExchange(CDataExchange* pDX)
    {
     CPropertyPage::DoDataExchange(pDX);
     DDX_Text(pDX, IDC_WIDTH, m_nLineWidth);
     DDV_MinMaxUInt(pDX, m_nLineWidth, 1, 25);
    }


    BEGIN_MESSAGE_MAP(CPage1, CPropertyPage)
     ON_EN_CHANGE(IDC_WIDTH, OnChangeWidth)
    END_MESSAGE_MAP()

    void CPage1::OnChangeWidth()
    {
       //首先将应用按钮设置为可用
     SetModified(TRUE);
    }

    BOOL CPage1::OnApply()
    {
     //将控件中的值设置给视图
     UpdateData(TRUE);
     //1 获取当前视图
     CLabelPropView* pView=(CLabelPropView*)
     ((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
     //2 赋值
     pView->m_nLineWidth=m_nLineWidth;
        //3 视图窗口重绘
     pView->Invalidate();
     return CPropertyPage::OnApply();
    }

    IMPLEMENT_DYNCREATE(CPage2, CPropertyPage)
    CPage2::CPage2() : CPropertyPage(CPage2::IDD)
    {
     //1 获取当前视图
     CLabelPropView* pView=(CLabelPropView*)
      ((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
     //2 赋值
     m_color=pView->m_lineColor;
    }

    CPage2::~CPage2()
    {
    }

    void CPage2::DoDataExchange(CDataExchange* pDX)
    {
     CPropertyPage::DoDataExchange(pDX);
    }


    BEGIN_MESSAGE_MAP(CPage2, CPropertyPage)
     ON_BN_CLICKED(IDC_COLOR, OnColor)
    END_MESSAGE_MAP()

    void CPage2::OnColor()
    {
     //将应用按钮设置为可用
     SetModified(TRUE);
     //打开颜色对话框
     CColorDialog dlg(m_color);
     if (IDOK!=dlg.DoModal())
     {
      return;
     }
     //将颜色对话框中的颜色值赋值给变量
        m_color=dlg.GetColor();
    }

    BOOL CPage2::OnApply()
    {
      //1 获取当前视图
     CLabelPropView* pView=(CLabelPropView*)
      ((CFrameWnd*)AfxGetMainWnd())->GetActiveView();
     //2 赋值
     pView->m_lineColor=m_color;
        //3 视图窗口重绘
     pView->Invalidate(); 
     return CPropertyPage::OnApply();
    }

    一 属性页对话框
     1类型
      标签式-常用于参数、选项等设置
      向导式-常用于引导用户通过每一步的选择和设置最终完成某种功能
     2 相关类
      CPropertypage-父类是CDialog,页面对话框
      CPropertySheet-父类是CWnd,页面对话框的容器窗口
      关系,一个CPropertySheet对象包含多了CPropertypage对象
     3 标签式
       3.1 插入页面对话框资源,定义页面对话框类
       3.2 添加CPropertySheet类的子类,定义容器窗口类
       3.3 将页面添加到容器窗口
           CPropertySheet::AddPage
       3.4 创建和显示
           CPropertySheet::DoModal
       3.5 消息
           CPropertySheet::OnApply
           CPropertySheet::OnCancel
           CPropertySheet::OnOK
       3.6 注意:
           初始时,应用按钮不可用,需要调用函数
           SetModified(TRUE)去设置
    4 向导式
       4.1 插入页面对话框资源,定义页面对话框类
       4.2 添加CPropertySheet类的子类,定义容器窗口类
       4.3 将页面添加到容器窗口
           CPropertySheet::AddPage
       4.4 设置为向导式
           CPropertySheet::SetWizardMode
       4.5 创建和显示
           CPropertySheet::DoModal
       4.6 消息
           CPropertyPage::OnSetActive      
           CPropertyPage::OnWizardNext
           CPropertyPage::OnWizardBack
           CPropertyPage::OnWizardFinish
       4.7 注意:
           4.7.1 设置页面的向导按钮
            CPropertySheet::SetWizardButtons
           4.7.2 向导页面的顺序不能随意修改 

  • 相关阅读:
    Python3笔记029
    Python3笔记028
    Python3笔记027
    Python3笔记026
    Python3笔记025
    Python3笔记024
    find the oracle logs
    asm command
    网上看到的一个朋友写的不错收藏着.
    在IBM AIX上安装Oracle RAC ,很多人都在找的东东.....
  • 原文地址:https://www.cnblogs.com/boobuy/p/2823172.html
Copyright © 2011-2022 走看看