exampledlg.cpp
来自「vc150例源码」· C++ 代码 · 共 229 行
CPP
229 行
// ExampleDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Example.h"
#include "ExampleDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExampleDlg dialog
CExampleDlg::CExampleDlg(CWnd* pParent /*=NULL*/)
: CDialog(CExampleDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CExampleDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CExampleDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExampleDlg)
DDX_Control(pDX, IDC_SLIDER1, m_Slider);
DDX_Control(pDX, IDC_Prev, m_PrevButton);
DDX_Control(pDX, IDC_Play, m_PlayButton);
DDX_Control(pDX, IDC_Pause, m_PauseButton);
DDX_Control(pDX, IDC_Open, m_OpenButton);
DDX_Control(pDX, IDC_Next, m_NextButton);
DDX_Control(pDX, IDC_EDIT1, m_FileName);
DDX_Control(pDX, IDC_Close, m_CloseButton);
DDX_Control(pDX, IDC_MMCONTROL1, m_Multimedia);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CExampleDlg, CDialog)
//{{AFX_MSG_MAP(CExampleDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_Open, OnOpen)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_Play, OnPlay)
ON_BN_CLICKED(IDC_Close, OnClose)
ON_BN_CLICKED(IDC_Next, OnNext)
ON_BN_CLICKED(IDC_Pause, OnPause)
ON_BN_CLICKED(IDC_Prev, OnPrev)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CExampleDlg message handlers
BOOL CExampleDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
this->m_PauseButton.EnableWindow(FALSE);
this->m_CloseButton.EnableWindow(FALSE);
this->m_PlayButton.EnableWindow(FALSE);
this->m_NextButton.EnableWindow(FALSE);
this->m_PrevButton.EnableWindow(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CExampleDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CExampleDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CExampleDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog OpenDlg(TRUE);
switch(this->m_MediaType)
{
case 1:
OpenDlg.m_ofn.lpstrFilter="Wave Files(*.wav)\0*.wav\0\0";
this->m_Multimedia.SetDeviceType("WaveAudio");
break;
case 2:
OpenDlg.m_ofn.lpstrFilter="AVI Files(*.avi)\0*.avi\0\0";
this->m_Multimedia.SetDeviceType("AviVideo");
break;
case 3:
OpenDlg.m_ofn.lpstrFilter="Midi Files(*.mid)\0*.mid\0\0";
this->m_Multimedia.SetDeviceType("Sequencer");
break;
case 4:
OpenDlg.m_ofn.lpstrFilter="";
this->m_Multimedia.SetDeviceType("CDAudio");
this->m_Multimedia.SetCommand("Open");
this->m_CloseButton.EnableWindow(TRUE);
this->m_PauseButton.EnableWindow(TRUE);
this->m_PlayButton.EnableWindow(TRUE);
this->m_NextButton.EnableWindow(TRUE);
this->m_PrevButton.EnableWindow(TRUE);
}
if(OpenDlg.DoModal()==IDOK)
{
this->m_Multimedia.SetFileName(OpenDlg.GetFileName());
this->m_FileName.SetWindowText(this->m_Multimedia.GetFileName());
this->m_Multimedia.SetCommand("Open");
this->m_CloseButton.EnableWindow(TRUE);
this->m_PauseButton.EnableWindow(TRUE);
this->m_PlayButton.EnableWindow(TRUE);
this->m_NextButton.EnableWindow(TRUE);
this->m_PrevButton.EnableWindow(TRUE);
}
}
void CExampleDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_MediaType=1;
}
void CExampleDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_MediaType=2;
}
void CExampleDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
m_MediaType=3;
}
void CExampleDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
m_MediaType=4;
}
void CExampleDlg::OnPlay()
{
// TODO: Add your control notification handler code here
this->m_Multimedia.SetCommand("Play");
}
BEGIN_EVENTSINK_MAP(CExampleDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CExampleDlg)
ON_EVENT(CExampleDlg, IDC_MMCONTROL1, 28 /* StatusUpdate */, OnStatusUpdateMmcontrol1, VTS_NONE)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CExampleDlg::OnStatusUpdateMmcontrol1()
{
// TODO: Add your control notification handler code here
this->m_Slider.SetRange(0,this->m_Multimedia.GetLength(),TRUE);
this->m_Slider.SetPos(this->m_Multimedia.GetPosition());
}
void CExampleDlg::OnClose()
{
// TODO: Add your control notification handler code here
this->m_Multimedia.SetCommand("Close");
this->m_CloseButton.EnableWindow(FALSE);
this->m_PauseButton.EnableWindow(FALSE);
this->m_PlayButton.EnableWindow(FALSE);
this->m_NextButton.EnableWindow(FALSE);
this->m_PrevButton.EnableWindow(FALSE);
}
void CExampleDlg::OnNext()
{
// TODO: Add your control notification handler code here
this->m_Multimedia.SetCommand("Next");
}
void CExampleDlg::OnPause()
{
// TODO: Add your control notification handler code here
this->m_Multimedia.SetCommand("Pause");
}
void CExampleDlg::OnPrev()
{
// TODO: Add your control notification handler code here
this->m_Multimedia.SetCommand("Prev");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?