Сообщение было отмечено kek_lol как решение
Решение
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
| // Dlg.cpp : implementation file
//
#include "stdafx.h"
#include <vfw.h>
#include "PlayMP3.h"
#include "Dlg.h"
#pragma comment(lib,"vfw32.lib")
#pragma comment(lib,"winmm.lib")
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlg dialog
CDlg::CDlg(CWnd* pParent /*=NULL*/)
: CDialog(CDlg::IDD, pParent)
, m_Filename(_T(""))
, m_cwtThread(NULL)
{
//{{AFX_DATA_INIT(CDlg)
// 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 CDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlg, CDialog)
//{{AFX_MSG_MAP(CDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlg message handlers
BOOL CDlg::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
char svDir[MAX_PATH];
GetCurrentDirectory(MAX_PATH-1, svDir);
m_Filename.Format( _T("%s\\test1.mp3" ), svDir);
HRSRC hResInfo=FindResource(AfxGetResourceHandle(),
MAKEINTRESOURCE(ID_MP3), _T("RT_RCDATA") );
if( hResInfo ) {
HGLOBAL hData=LoadResource(AfxGetResourceHandle(), hResInfo);
if( hData ) {
void* pSrc=LockResource(hData);
if( pSrc ) {
void* lpBuffer=malloc((size_t)SizeofResource(AfxGetResourceHandle(),
hResInfo));
if( lpBuffer ) {
memcpy(lpBuffer, (const void*)pSrc,
(size_t)SizeofResource(AfxGetResourceHandle(), hResInfo));
HANDLE hFile=CreateFile(m_Filename, GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if( INVALID_HANDLE_VALUE!=hFile ) {
DWORD dwNumberOfBytesWritten;
WriteFile(hFile,
lpBuffer, ((size_t)SizeofResource(AfxGetResourceHandle(),
hResInfo)), &dwNumberOfBytesWritten, NULL);
CloseHandle(hFile);
} else {
MessageBox( _T("Cannot upload MP3"), _T("Error"),
MB_OK | MB_ICONSTOP | MB_SETFOREGROUND | MB_TOPMOST);
free(lpBuffer);
exit(0);
}
free(lpBuffer);
}
}
}
}
SetDlgItemText(IDOK,_T("Play"));
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 CDlg::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 CDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CDlg::OnBnClickedOk()
{
static BOOL Busy;
GetDlgItem(IDOK)->EnableWindow(FALSE);
SetDlgItemText(IDOK,_T("Wait..."));
if( TRUE==Busy ) {
CString strCmd;
strCmd.Format(_T("stop "%s""), m_Filename);
mciSendString(strCmd, NULL, 0, 0);
strCmd.Format(_T("close "%s""), m_Filename);
mciSendString(strCmd, NULL, 0, 0);
if(NULL!=m_cwtThread) {
WaitForSingleObject(m_cwtThread->m_hThread,INFINITE);
m_cwtThread=NULL;
}
SetDlgItemText(IDOK,_T("Play"));
Busy=FALSE;
} else {
m_cwtThread=AfxBeginThread(ThreadEntry, this);
m_cwtThread->m_bAutoDelete=TRUE;
m_cwtThread->SetThreadPriority(THREAD_PRIORITY_LOWEST);
if( NULL==m_cwtThread ) {
AfxMessageBox( _T("Cannot create thread") );
AfxGetApp()->m_pMainWnd->SendMessage(WM_CLOSE);
return;
}
SetDlgItemText(IDOK,_T("Stop"));
Busy=TRUE;
}
GetDlgItem(IDOK)->EnableWindow(TRUE);
}
UINT ThreadEntry(LPVOID pParam)
{
CDlg* pThis=(CDlg*)pParam;
CString strCmd;
strCmd.Format(_T("open "%s" type mpegvideo alias mp3"), pThis->m_Filename);
mciSendString(strCmd, NULL, 0, 0);
strCmd.Format(_T("play "%s" repeat"), pThis->m_Filename);
mciSendString(strCmd, NULL, 0, 0);
return 0;
} |
|
rc
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
| //Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Russian resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
#ifdef _WIN32
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
#pragma code_page(1251)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"#define _AFX_NO_SPLITTER_RESOURCES\r\n"
"#define _AFX_NO_OLE_RESOURCES\r\n"
"#define _AFX_NO_TRACKER_RESOURCES\r\n"
"#define _AFX_NO_PROPERTY_RESOURCES\r\n"
"\r\n"
"#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n"
"#ifdef _WIN32\r\n"
"LANGUAGE 9, 1\r\n"
"#pragma code_page(1252)\r\n"
"#endif //_WIN32\r\n"
"#include ""res\\PlayMP3.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
"#include ""afxres.rc"" // Standard components\r\n"
"#endif\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDR_MAINFRAME ICON DISCARDABLE "res\\PlayMP3.ico"
/////////////////////////////////////////////////////////////////////////////
//
// RT_RCDATA
//
ID_MP3 RT_RCDATA "res\\Van_Halen_1986.mp3"
#endif // Russian resources
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_PLAYMP3_DIALOG DIALOGEX 0, 0, 320, 200
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_APPWINDOW
CAPTION "PlayMP3"
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,260,7,50,14
PUSHBUTTON "Cancel",IDCANCEL,260,23,50,14
LTEXT "TODO: Place dialog controls here.",IDC_STATIC,50,90,200,
8
END
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904B0"
BEGIN
VALUE "CompanyName", "\0"
VALUE "FileDescription", "PlayMP3 MFC Application\0"
VALUE "FileVersion", "1, 0, 0, 1\0"
VALUE "InternalName", "PlayMP3\0"
VALUE "LegalCopyright", "Copyright (C) 2017\0"
VALUE "LegalTrademarks", "\0"
VALUE "OriginalFilename", "PlayMP3.EXE\0"
VALUE "ProductName", "PlayMP3 Application\0"
VALUE "ProductVersion", "1, 0, 0, 1\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_PLAYMP3_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 313
TOPMARGIN, 7
BOTTOMMARGIN, 193
END
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
#define _AFX_NO_SPLITTER_RESOURCES
#define _AFX_NO_OLE_RESOURCES
#define _AFX_NO_TRACKER_RESOURCES
#define _AFX_NO_PROPERTY_RESOURCES
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE 9, 1
#pragma code_page(1252)
#endif //_WIN32
#include "res\PlayMP3.rc2" // non-Microsoft Visual C++ edited resources
#include "afxres.rc" // Standard components
#endif
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED |
|
PlayMP3.zip
0
|