Sign me up Login
Fairyabc discussion Board Return home

No.5972 Global Website https://www.fairyabc.com/?1667 [Bookmark] [Copy] [RSS] COLG update date: Every two Tuesdays. Other news if it appears, will be presented irregularly.

Blogs

A MFC Demo in C++ Using Multimedia Control

Hot 1Viewed 1753 times2017-11-1 23:11


#include "stdafx.h"
#include "MFCDemo.h"
#include "MFCDemoDlg.h"
#include "afxdialogex.h"
#include <windows.h>  
#include <commdlg.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#endif



class CAboutDlg : public CDialogEx
{
public:
CAboutDlg();

#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_ABOUTBOX };
#endif

protected:
virtual void DoDataExchange(CDataExchange* pDX); 

protected:
DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()





CMFCDemoDlg::CMFCDemoDlg(CWnd* pParent /*=NULL*/)
: CDialogEx(IDD_MFCDEMO_DIALOG, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
//DDX_Control(pDX, IDC_COMMONDIALOG1, CCDG);
//DDX_Control(pDX, IDC_OCX1, m_player);
DDX_Control(pDX, IDC_MMCONTROL2, m_mmcontrol);
}

BEGIN_MESSAGE_MAP(CMFCDemoDlg, CDialogEx)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, &CMFCDemoDlg::OnBnClickedButton1)
END_MESSAGE_MAP()



BOOL CMFCDemoDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();



ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
BOOL bNameValid;
CString strAboutMenu;
bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
ASSERT(bNameValid);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}

SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);



return TRUE;
}

void CMFCDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialogEx::OnSysCommand(nID, lParam);
}
}


void CMFCDemoDlg::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
{
CDialogEx::OnPaint();
}
}


HCURSOR CMFCDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}

TCHAR *opendialog() {
OPENFILENAME ofn;     
TCHAR szFile[10000];  
     
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = NULL;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = _T("Media File(*.mp3, *.wav, *.mid)\0*.MP3;*.WAV;*.MID\0All File(*.*)\0*.*\0\0");
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

if (GetOpenFileName(&ofn))
{ 
return szFile;
}
return _T("\0");
}

void CMFCDemoDlg::OnBnClickedButton1()
{
CString filename;
USES_CONVERSION;
_UNICODE;
filename.Format(_T("%s"),opendialog());
if (filename!="\0")
CMFCDemoDlg::SetDlgItemTextW(IDC_STATIC2, filename);
//m_player.put_URL(filename);
m_mmcontrol.put_FileName(filename);
m_mmcontrol.put_Command(_T("open"));
}

i don't care

eggs
1

flowers

agree

funny

Friends Rank (1 people)

Comments (0 comments)

facelist doodle Doodle

You have to be logged to leave a comment Login | Sign me up

Archiver|mobile|banned|Developer Email|Account frozen|Privacy Policy|Fairyabc

GMT-4, 2024-4-19 00:03 , Processed in 0.015322 second(s), 19 queries .

Copyright © 2013-2022 Fairyabc

Powered by Discuz!
To Top