1. Введение
В этой главе мы создадим программу, проигрывающую WAVE-файлы. Для начала создадим проект mysound в диалоговом режиме с использованием MFC. В начало файла mysoundDlg.cpp надо написать #include <mmsystem.h>, но это не всё, а теперь самое главное( если это не сделать, то будет ошибка при линковании ) :
1. Выберите Project -> Settings... --> C/C++ --> Code Generation и поставте Multithreaded DLL
2. Выберите Project -> Settings... --> Link --> General и поставте в поле Object/Library modules библиотеку winmm.lib( это очень важно, проверте !!! )
2. Проигрывание Wave-файла в виде ресурса
Первым делом надо создать ресурс, для этого в файле mysound.rc2 надо вписать строчку IDSOUND_CORRECT sound rescorrect.wav, где IDSOUND_CORRECT - индефикатор ресурса, sound - тип ресурса( название можно менять ), rescorrect.wav - файл ресурса. После этого в файле Resource.h надо зарегистрировать ресурс: #define IDSOUND_CORRECT 130. Число 130 не должно совпадать с другими числами.
Как только ресурс зарегистрирован можно написать в файле mysoundDlg.cpp функции проигрывания этого ресурса :
static void PlayResource(LPCTSTR lpszSound) { HRSRC hRes; // resource handle to wave file HGLOBAL hData; BOOL bOk = FALSE; if ((hRes = ::FindResource(AfxGetResourceHandle(), lpszSound, _T("sound"))) != NULL &&
(hData = ::LoadResource (AfxGetResourceHandle(), hRes)) != NULL) {
// found the resource, play it bOk = sndPlaySound((LPCTSTR)::LockResource(hData), SND_MEMORY|SND_SYNC|SND_NODEFAULT); FreeResource(hData); } if (!bOk) { AfxMessageBox("ERROR !!! Can not play the sound.
nNot find sound board !!!"); } } inline static void PlayResource(UINT nIDS) { PlayResource(MAKEINTRESOURCE(nIDS)); }
В фунции ::FindResource(AfxGetResourceHandle(), lpszSound, _T("sound")) третий параметр - тип ресурса, который был описан выше.
Теперь можно проиграть ресурс : PlayResource( IDSOUND_CORRECT );
3. Проигрывание Wave-файла с диска
Для проигрывания WAVE-файла с диска можно использовать функцию :
BOOL sndPlaySound( LPCTSTR lpszSoundName;
UINT fuOptions; ); Параметры функции:
lpszSoundName Имя файла. Если этот параметр NULL,
то проигрывание файла останавливается. fuOptions
Специальные опции для проигрывания музыки.
Они могут быть следующими:
Значение Описание
SND_SYNC Музыка играется синхронно, и функция
не возвращает указатель пока не будет конца файла.
SND_ASYNC Музыка играется асинхронно, и функция
возвращает указатель сразу после начала
проигрывания файла. Чтобы остановить проигрывание,
надо вызвать функцию SndPlaySound с параметром
lpszSoundName установленным в NULL.
SND_NODEFAULT Если файл не найден, то функция
возвращает указатель сразу и не
проигрывает стандартный звуковой эффект Windows.
SND_MEMORY Этот параметр нужен для проигрывания
Wave-файла в виде ресурса( из памяти ).
SND_LOOP Этот параметр нужен для проигрывания
Wave-файла в циклическом режиме. Также
при этом вы должны использовать влаг SND_ASYNC.
Чтобы остановить проигрывание, надо вызвать
функцию SndPlaySound с параметром
lpszSoundName установленным в NULL.
SND_NOSTOP Если музыка уже проигрывается,
то функция возврвщает FALSE.
Возвращаемое значение: Если музыка проигрывается
правильно, то функция возврвщает TRUE, иначе FALSE.
Пример использования: B
OOL bOk = sndPlaySound( "test.wav", SND_SYNC);
if (!bOk) { AfxMessageBox
("Error ! Can not play the sound. !!!"); }
Другие работы по теме:
Работа с файлами (лабораторная работа)
Лабораторная работа №2 Т е м а: Р а б о т а с ф а й л а м и. Задание: 1)Создание каталога 1-го уровня; провести проверку. 2)Создание каталога 2-го уровня в каталоге 1-го уровня; установка этого каталога.
Работа с файлами лабораторная работа
Лабораторная работа №2 Т е м а: Р а б о т а с ф а й л а м и. Задание: 1)Создание каталога 1-го уровня; провести проверку. 2)Создание каталога 2-го уровня в каталоге 1-го уровня; установка этого каталога.
When I Went To Canada Essay Research
Paper When my mom toke me and my brother to Wonder land I thought it was big. I asked could we go to the Water Park. Mummy said ok my favorite water ride was black hole it was scary. The next ride I went on the wave pool. When the song started the waves was become strong. I couldn’t take the waves because they were to high and kept pushing me.
Wave Doctors Essay Research Paper 101200THE WAVE
Wave Doctors Essay, Research Paper 10/12/00 THE WAVE DOCTORS In today’s society there are numerous different language environments that we pass through everyday. For myself, the “different” language environment is in
Sound Waves Essay Research Paper Sound is
Sound Waves Essay, Research Paper Sound is part of our everyday lives. Just like we have eyes for, we are given ears for hearing sound. We rarely take the time to think about the characteristics of sound and the ways that they are made. The basis for an understanding of sound and hearing is the physics of waves.
Sound Waves Essay Research Paper Sound WavesWaves
Sound Waves Essay, Research Paper Sound Waves Waves are disturbances that travel through a space while changing its matter. A sound wave is what allows us to hear sounds. It is created by vibrations, which are made by the movement of matter. Sound waves must travel through a solid, a liquid, or a gas. The more tight the particles, the faster the wave will travel.
Break Point Essay Research Paper Surfing the
Break Point Essay, Research Paper Surfing the breaking waves on Mayport Beach gives a feeling I will never forget. I was 12 years old when my family and I lived on the shore of a small town known as Mayport. Two consecutive years we dwelled in our cozy little beach house watching the gleaming ocean through our windows.
Poems
– Free Verse Essay, Research Paper Poem One Typography Form (free verse) The sea as calm as can be a tidal wave hits with great fury the sea gentle eases back
Alvin Toffler
– The Third Wave Essay, Research Paper In Alvin Toffler’s book, “The Third Wave,” he discusses our progression as a society. One can easily see the pattern to the mentioned waves. He describes wave one as the start of agriculture. It also marks the beginning of our culture. Wave two, marks the beginning of the Industrial Revolution, atomic destruction, and mainstream items.
The Sunset Surfer Essay Research Paper The
The Sunset Surfer Essay, Research Paper The Sunset Surfer An older man sat on his classic 9′6 with joy in his eyes, salt water in his veins, and a genuine love for his board underneath him, and the waves rolling in. He had just got off work and paddled out into the sunset for a half an hour of spiritual rejuvenation.
Tsunamis Essay Research Paper A tsunami is
Tsunamis Essay, Research Paper A tsunami is a wave train, or series of waves, generated in a body of water. Earthquakes, landslides, volcanic eruptions, explosions, and even the impact of cosmic bodies, such as meteorites, can generate tsunamis. These waves can savagely attack coastlines, causing devastating property damage and loss of life.
Tsunami Essay Research Paper TsunamiA tsunami is
Tsunami Essay, Research Paper Tsunami A tsunami is a large water wave that is generated by sesmic activity in or underlying layers known as faults. These enormous wave have historically affected many ways of life and still lie as a major factor for destruction in our coastal communities throughout the world.
The Declaration Of Sentiments V Now
’s Statement Of Purpose Essay, Research Paper The Declaration of Sentiments and NOW Both the Declaration of Sentiments and the National Organization for Women s Statement of Purpose are documents that represent women s fight for equality with men. The DOS, the first wave s list of demands for quality, came from radical women who did not have a voice within society while the Statement of Purpose shows the second wave s plan for the fight against discrimination.
Surfing Essay Research Paper Keys to becoming
Surfing Essay, Research Paper Keys to becoming a surfer h The first thing to know about surfing is that it is hard to learn how to do but is totally fun once you get the hang of it. So don’t be discouraged. Have fun, and eventually expertise will come.
Light Essay Research Paper Light is what
Light Essay, Research Paper Light is what we see. It can be thought of either as a particle, (the photon), or as a wave. The photon we can easily think of as a small dot travelling through space at the speed of light. Each photon has a particular colour or energy. But how do we think of light as a wave? For this we need to know that light is also an “Electro-magnetic field” — a combination of electric-field and magnetic-field — the same thing that causes static electricity and magnets to attract (or repel) things.
Cause And Efffect Essay Essay Research Paper
Tsunami When one thinks of all the natural disasters, that could effect the Maryland and Washington D.C. area they often think of hurricanes and snowstorms. They often forget about the possibility of a tsunami. A tsunami, often referred to as a ?tidal wave?, is a wave train, or series of waves, generated in a body of water by an impulsive disturbance that vertically displaces the water column.
Electricity Produced By Ocean Waves Essay Research
Paper Day by day we look for alterntives to the many things we do. We tend to worry about the effects we have on the enviorment and more. This is why it is important to find different ways of producing electricity without producing a huge amount of pollution.Since 1799 man has tried to use the potential power of wave energy. only recently in the last few decades has man been able rto develope devices which could harness the power oif the ocean.
Process Paper Surfing Essay Research Paper Surfing
Process Paper: Surfing Essay, Research Paper Surfing has been a sport enjoyed by hundreds of thousands of people around the world. It originated in Polynesian culture as a religious ceremony mainly practiced by the royalty. Having been introduced from the Hawaiian Islands roughly 60 years ago, it has become a common practice in virtually every coastal beach break throughout the USA and numerous places around the globe.
Surfing Essay Research Paper The intent of
Surfing Essay, Research Paper The intent of this paper is to introduce the reader to surfing. There are many things to learn about surfing such as its history, surf gear, and safety hints.
Surfing Essay Research Paper Surfing Surfing
Surfing Essay, Research Paper Surfing Surfing is a water sport that originated in what is now Hawaii. People in Hawaii were surfing before explorer Christopher Colombus sailed to the New World in 1942. Today, surfing is popular in many countries, including Australia, Brazil, France, Indonesia, Japan, Portugal, Peru, South Africa, and the United States.
SKA Essay Research Paper SKAImagine this spring
SKA! Essay, Research Paper SKA! Imagine this: spring break 1962, Jamaica. You are strolling down the streets of Kingston, enjoying the cool sea breeze and the delightful Caribbean climate.
Radio Waves Essay Research Paper Radio waves
Radio Waves Essay, Research Paper Radio waves travel at 186,000 miles per second through air. In contrast, sound waves travel at only 1/5 of a mile per second. If a modulation is made of the radio wave that exactly reproduces the amplitude and frequency characteristics of the original sound wave, then sound can be transmitted rapidly over long distances.
The Wave Essay Research Paper The wave
The Wave Essay, Research Paper The wave is about a history teacher whose name is Ben Ross. His class was starting to study the time that Hitler began making all the Jewish people stay in camps. Ben Ross could not find a way to get his class interested into this time period, so he decided to try to make a group, He would play like a Hitler type scenario and his class would be the Jewish people.
Implications Of Essay Research Paper The Wave
Implications Of Essay, Research Paper The Wave is a video about a classroom experiment gone way out. The teacher tried to answer a student s question about the likeness of the ignorance of the German public on the Nazi s actions during World War II, like the holocaust of the Jewish people. As an experiment he started an organization called the Wave, which focused on three basic statements : Strength through discipline, Strength through community, Strength through action.
Definition Essay Essay Research Paper When you
Definition Essay Essay, Research Paper When you think of surfing what comes to mind? Is it yo dude, or the beauty of a majestic wave breaking on the shore with the sun setting on the horizon? Surfers today receive very little respect for the sport, sometimes referred to as an art, that they participate in. Despite what most people think, the surfers are a rare breed let alone the soul surfer.
Magnetic Spectrum Essay Research Paper Electromagnetic SpectrumAn
Magnetic Spectrum Essay, Research Paper Electromagnetic Spectrum An electromagnetic spectrum is the spectrum in which electromagnetic waves are sent out and in which they can be detected. The spectrum of electromagnetic waves includes the following waves: microwave, radar, satellite, UHF T.V., VHF T.V., FM radio, CB radio, amateur radio, and AM radio.
Speech And You Essay Research Paper Mrs
Speech And You Essay, Research Paper Mrs. Sirof Chris Medici English 3r Per 1 From the memior of Jenn Gooley As the sun rose up that summer day on the beach of Fire Island, Jen
Photosynthesis Essay Research Paper PHOTOSYNTHSIS INFORMATION The
Photosynthesis Essay, Research Paper PHOTOSYNTHSIS INFORMATION: The Nature of Light Light behaves both as a wave phenomenon and as discrete particles of energy called photons. If we look at light as a wave phenomenon, we can assign it a wavelength (the distance from one peak of the wave to the next) and an amplitude (the distance the wave oscillates from its centerline).
It Ain
’t Easy Being A Child Essay, Research Paper I know I haven’t been an easy child, But love for you lies underneath my whims; There is no way I could be tame or mild: I need sometimes to shout and wave my
Internet PC
’s: Next Wave Or Nonsense? Essay, Research Paper Internet PC’s: Next Wave or Nonsense? Call them what you will: Internet appliances. Network terminals. The whole
Hitler Essay Research Paper Hitler came to
Hitler Essay, Research Paper Hitler came to power the legitimate way, through participating in elections. True he broke or bent a few rules and cheated and lied but probably no more than any other politician. It is common belief that had Hitler come along at another less desperate time for Germany, history would have played itself out very differently.
Tides Essay Research Paper Lunar TidesThe moon
Tides Essay, Research Paper Lunar Tides The moon, being much nearer to the earth than the sun, is the principal cause of tides. When the moon is directly over a given point on the surface of the earth, it exerts a powerful pull on the water, which therefore rises above its normal level. Water covering the portion of the earth farthest from the moon is also subject to this pull, so that another distinct dome of water is formed on the farther side of the earth providing the basis for a second wave.