choicepage.cpp
来自「个人计算机定时自动执行软件,是 一个值得看看的程序。」· C++ 代码 · 共 358 行
CPP
358 行
// ChoicePage.cpp : implementation file
//
#include "stdafx.h"
#include "clock.h"
#include "ChoicePage.h"
#include "Mmsystem.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CChoicePage property page
IMPLEMENT_DYNCREATE(CChoicePage, CPropertyPage)
CChoicePage::CChoicePage() : CPropertyPage(CChoicePage::IDD)
{
//{{AFX_DATA_INIT(CChoicePage)
m_playsound = FALSE;
m_mediafile = 0;
m_dofront = 0;
m_actionusing = FALSE;
m_actionmode = 0;
m_filepath = _T("");
m_wavpath = _T("");
m_donow = 0;
//}}AFX_DATA_INIT
m_isActive=FALSE;
bInit=TRUE;
}
CChoicePage::~CChoicePage()
{
}
void CChoicePage::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChoicePage)
DDX_Control(pDX, IDC_CHOICE_FRONTDOEDIT, m_cdofornt);
DDX_Control(pDX, IDC_CHOICE_FRONTDOEDITSPIN, m_front);
DDX_Check(pDX, IDC_CHOICE_PLAYSOUND, m_playsound);
DDX_Radio(pDX, IDC_CHOICE_MEDIAFILE, m_mediafile);
DDX_Text(pDX, IDC_CHOICE_FRONTDOEDIT, m_dofront);
DDV_MinMaxInt(pDX, m_dofront, 0, 60);
DDX_Check(pDX, IDC_CHOICE_ACTIONUSING, m_actionusing);
DDX_CBIndex(pDX, IDC_CHOICE_ACTION, m_actionmode);
DDX_CBString(pDX, IDC_CHOICE_PATH, m_filepath);
DDX_Text(pDX, IDC_CHOICE_WAVPATH, m_wavpath);
DDX_Radio(pDX, IDC_CHOICE_DONOW, m_donow);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CChoicePage, CPropertyPage)
//{{AFX_MSG_MAP(CChoicePage)
ON_BN_CLICKED(IDC_CHOICE_PLAYSOUND, OnPlaySound)
ON_BN_CLICKED(IDC_CHOICE_USING, OnUsing)
ON_BN_CLICKED(IDC_CHOICE_CDEDITBROWSE, OnChoiceBrowse)
ON_BN_CLICKED(IDC_CHOICE_CDEDITPLAY, OnChoicePlay)
ON_BN_CLICKED(IDC_CHOICE_PATHBROWSE, OnPathBrowse)
ON_CBN_SELCHANGE(IDC_CHOICE_ACTION, OnSelchangeChoiceAction)
ON_EN_CHANGE(IDC_CHOICE_FRONTDOEDIT, OnChangeChoiceFrontdoedit)
ON_BN_CLICKED(IDC_CHOICE_DONOW, OnChoiceDonow)
ON_BN_CLICKED(IDC_CHOICE_FRONTDO, OnChoiceFrontdo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CChoicePage message handlers
BOOL CChoicePage::OnInitDialog() //初始化
{
CPropertyPage::OnInitDialog();
UpdateData(FALSE);
m_playsound = m_mission.choice_usingsound;//启用媒体声音
m_mediafile = m_mission.choice_playsound;//播放声音选择
CString wavpath = m_mission.choice_wavpath;//wav路径
m_wavpath = wavpath;
m_actionusing = m_mission.choice_usingaction;//启用门铃任务
m_actionmode = m_mission.choice_actionmode;//动作方式
CString filepath = m_mission.choice_actionpath;//文件路径
m_filepath = filepath;
m_donow = m_mission.choice_actionhint;//执行任务前提示
m_dofront = m_mission.choice_actiontime;//执行前提示时间
OnSelchangeChoiceAction() ;
OnPlaySound();
OnUsing();
m_front.SetRange(0,60);//上下控件最大为60,最小为0
m_cdofornt.SetLimitText(2);//编辑框的限制在两位数
bInit=FALSE;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CChoicePage::OnPlaySound() //播放声音
{
UpdateData();
if(m_playsound)
{
GetDlgItem(IDC_CHOICE_MEDIAFILE)->EnableWindow();
//GetDlgItem(IDC_CHOICE_CDPLAYER)->EnableWindow();
GetDlgItem(IDC_CHOICE_CDEDIT)->EnableWindow();
GetDlgItem(IDC_CHOICE_STATIC)->EnableWindow();
GetDlgItem(IDC_CHOICE_CDEDITBROWSE)->EnableWindow();
GetDlgItem(IDC_CHOICE_CDEDITPLAY)->EnableWindow();
}
else
{
GetDlgItem(IDC_CHOICE_MEDIAFILE)->EnableWindow(false);
//GetDlgItem(IDC_CHOICE_CDPLAYER)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_CDEDIT)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_STATIC)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_CDEDITBROWSE)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_CDEDITPLAY)->EnableWindow(false);
}
}
void CChoicePage::OnUsing() //启用闹铃动作
{
UpdateData();
if(m_actionusing)
{
GetDlgItem(IDC_CHOICE_ACTIONSTATIC)->EnableWindow();
GetDlgItem(IDC_CHOICE_ACTION)->EnableWindow();
GetDlgItem(IDC_CHOICE_DONOW)->EnableWindow();
GetDlgItem(IDC_CHOICE_FRONTDO)->EnableWindow();
GetDlgItem(IDC_CHOICE_FRONTDOSTATIC)->EnableWindow();
GetDlgItem(IDC_CHOICE_PATH)->EnableWindow();
GetDlgItem(IDC_CHOICE_PATHBROWSE)->EnableWindow();
if(m_donow==0)
{
GetDlgItem(IDC_CHOICE_FRONTDOEDIT)->EnableWindow(false);
}
else
GetDlgItem(IDC_CHOICE_FRONTDOEDIT)->EnableWindow();
}
else
{
GetDlgItem(IDC_CHOICE_ACTIONSTATIC)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_ACTION)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_DONOW)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_FRONTDO)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_FRONTDOEDIT)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_FRONTDOSTATIC)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_PATH)->EnableWindow(false);
GetDlgItem(IDC_CHOICE_PATHBROWSE)->EnableWindow(false);
}
}
void CChoicePage::OnChoiceBrowse() //浏览wav
{
CFileDialog FileDialog(TRUE,"",m_wavpath,OFN_OVERWRITEPROMPT,
"Wave File(*.wav)|*.wav|All Files(*.*)|*.*||");
if (FileDialog.DoModal()==IDOK)
{
UpdateData(TRUE);
m_wavpath = FileDialog.GetPathName();
UpdateData(FALSE);
}
}
void CChoicePage::OnChoicePlay() //播放
{
BeginWaitCursor();//显示漏斗型等待光标
PlaySound(m_wavpath,NULL,SND_FILENAME);//播放声音,包含头文件#include "Mmsystem.h"
EndWaitCursor();
}
void CChoicePage::OnPathBrowse() //浏览exe
{
CFileDialog FileDialog(TRUE,"",m_filepath,OFN_OVERWRITEPROMPT,
"Execture File(*.exe)|*.exe|All Files(*.*)|*.*||");
if (FileDialog.DoModal()==IDOK)
{
UpdateData(TRUE);
m_filepath = FileDialog.GetPathName();
UpdateData(FALSE);
}
}
void CChoicePage::OnSelchangeChoiceAction()
{
UpdateData();
switch(m_actionmode)
{
case 0:
GetDlgItem(IDC_CHOICE_PATHBROWSE)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_CHOICE_PATH)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_PATHSTATIC)->ShowWindow(SW_SHOW);
break;
case 1:
GetDlgItem(IDC_CHOICE_PATHBROWSE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_CHOICE_PATH)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_PATHSTATIC)->ShowWindow(SW_HIDE);
break;
case 2:
GetDlgItem(IDC_CHOICE_PATHBROWSE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_CHOICE_PATH)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_PATHSTATIC)->ShowWindow(SW_HIDE);
break;
case 3:
GetDlgItem(IDC_CHOICE_PATHBROWSE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_CHOICE_PATH)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_PATHSTATIC)->ShowWindow(SW_HIDE);
break;
case 4:
GetDlgItem(IDC_CHOICE_PATHBROWSE)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_CHOICE_PATH)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_PATHSTATIC)->ShowWindow(SW_HIDE);
break;
}
}
void CChoicePage::ReadData(MISSION *pMission)
{
///*
if(!m_isActive)
return;
pMission->choice_usingsound = m_mission.choice_usingsound;
pMission->choice_playsound = m_mission.choice_playsound;
strcpy(pMission->choice_wavpath,m_mission.choice_wavpath);
// strcpy(pMission->choice_cdpath,m_mission.choice_cdpath);
pMission->choice_usingaction = m_mission.choice_usingaction;
pMission->choice_actionmode = m_mission.choice_actionmode;
strcpy(pMission->choice_actionpath,m_mission.choice_actionpath);
pMission->choice_actionhint = m_mission.choice_actionhint;
pMission->choice_actiontime = m_mission.choice_actiontime;
// strcpy(pMission->choice_actiontime,m_mission.choice_actiontime);
//*/
}
void CChoicePage::OnOK()
{
///*
m_isActive=TRUE;
UpdateData();
m_mission.choice_usingsound = m_playsound==0?0:1;//这里设置true=0;即check框不打勾
m_mission.choice_playsound = m_mediafile;
strcpy(m_mission.choice_wavpath,m_wavpath);
// strcpy( m_mission.choice_cdpath,m_strcdpath);//cd播放路径
m_mission.choice_usingaction = m_actionusing==0?0:1;//这里设置true=0;即check框不打勾
m_mission.choice_actionmode = m_actionmode;
strcpy(m_mission.choice_actionpath,m_filepath);
m_mission.choice_actionhint = m_donow;
m_mission.choice_actiontime = m_dofront;
//*/
CPropertyPage::OnOK();
}
void CChoicePage::SetMission(MISSION *peditmission)
{
m_playsound = peditmission->choice_usingsound;
m_mediafile = peditmission->choice_playsound;
CString str_wavpath = peditmission->choice_wavpath;
m_wavpath = str_wavpath;
// CString str_cdpath = peditmission->choice_cdpath;
// m_strcdpath = str_cdpath;
m_actionusing = peditmission->choice_usingaction;
m_actionmode = peditmission->choice_actionmode;
CString str_filepath = peditmission->choice_actionpath;
m_filepath = str_filepath;
m_donow = peditmission->choice_actionhint;
m_dofront = peditmission->choice_actiontime;
}
void CChoicePage::OnChangeChoiceFrontdoedit() //编辑框有所改变的时候
{
if(!bInit)
{
OnChangeValue(IDC_CHOICE_FRONTDOEDIT,&m_dofront);
}
}
void CChoicePage::OnChangeValue(int nID,int *pV)
{ //在数据输入后检查数据,如果数据超出范围,自动将其变为范围内的数据
UpdateData();
if(*pV>60){
*pV=60;
UpdateData(FALSE);
}
else if(*pV<0){
*pV=0;
UpdateData(FALSE);
}
}
void CChoicePage::OnChoiceDonow()
{
GetDlgItem(IDC_CHOICE_FRONTDOEDIT)->EnableWindow(false);
}
void CChoicePage::OnChoiceFrontdo()
{
GetDlgItem(IDC_CHOICE_FRONTDOEDIT)->EnableWindow();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?