Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to stop a sound thread

How to stop a sound thread

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structuressecurityhelptutorial
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FlyingDancer
    wrote on last edited by
    #1

    Hi, everybody I meet a problem First DWORD WINAPI CA::ThreadFuncSound(LPVOID lpParam) { DWORD dwResult=0; Beep(800, 1000000); return 0; } ThenCreat a thread to sound which is suspended m_hThreadSound = CreateThread( NULL, // no security attributes 0, // use default stack size ThreadFuncSound, // thread function (PVOID)this, // argument to thread function CREATE_SUSPENDED|THREAD_ALL_ACCESS, // Start the thread with a suspend count of one &dwThreadId); And then Start the sound thread ResumeThread(m_hThreadSound); Sleep(100); Now I want to stop the speaker to sound. I ever used SuspendThread(m_hThreadSound) or TerminateThread(m_hThreadSound,0), but they can't work well. How can I solve this problem? Appreciate for any suggestions!

    A 1 Reply Last reply
    0
    • F FlyingDancer

      Hi, everybody I meet a problem First DWORD WINAPI CA::ThreadFuncSound(LPVOID lpParam) { DWORD dwResult=0; Beep(800, 1000000); return 0; } ThenCreat a thread to sound which is suspended m_hThreadSound = CreateThread( NULL, // no security attributes 0, // use default stack size ThreadFuncSound, // thread function (PVOID)this, // argument to thread function CREATE_SUSPENDED|THREAD_ALL_ACCESS, // Start the thread with a suspend count of one &dwThreadId); And then Start the sound thread ResumeThread(m_hThreadSound); Sleep(100); Now I want to stop the speaker to sound. I ever used SuspendThread(m_hThreadSound) or TerminateThread(m_hThreadSound,0), but they can't work well. How can I solve this problem? Appreciate for any suggestions!

      A Offline
      A Offline
      Abhishek Srivastava
      wrote on last edited by
      #2

      Hi there to terminate a thread first call GetExitCodeThread() method passing the Thread Handle to it and DWORD reference. DWORD exitcode GetExitCodeThread(m_hThreadSound, &exitcode) ; Now call TerminateThread(m_hThreadSound, exitcode); actually u were commiting mistake by passing 0 as thread exit code in ur TerminateThread line. Tell me if i solved ur prob :-D Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

      F 1 Reply Last reply
      0
      • A Abhishek Srivastava

        Hi there to terminate a thread first call GetExitCodeThread() method passing the Thread Handle to it and DWORD reference. DWORD exitcode GetExitCodeThread(m_hThreadSound, &exitcode) ; Now call TerminateThread(m_hThreadSound, exitcode); actually u were commiting mistake by passing 0 as thread exit code in ur TerminateThread line. Tell me if i solved ur prob :-D Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

        F Offline
        F Offline
        FlyingDancer
        wrote on last edited by
        #3

        Thanks But it does not work well yet. It seems that this operation can not stop the speaker's sounding. Have any other way? :confused::zzz:

        A 1 Reply Last reply
        0
        • F FlyingDancer

          Thanks But it does not work well yet. It seems that this operation can not stop the speaker's sounding. Have any other way? :confused::zzz:

          A Offline
          A Offline
          Abhishek Srivastava
          wrote on last edited by
          #4

          Sir , u have passed 1000000 as a second param in Beep method , which means u have played a sound for almost 16 mins and this will block ur thread . so instead of issuing a command for 16 mins,do it in a While loop like this while (true) { Beep(800,100); } return ; Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

          F 1 Reply Last reply
          0
          • A Abhishek Srivastava

            Sir , u have passed 1000000 as a second param in Beep method , which means u have played a sound for almost 16 mins and this will block ur thread . so instead of issuing a command for 16 mins,do it in a While loop like this while (true) { Beep(800,100); } return ; Abhishek Srivastava Software Engg (VC++) India ,Noida Mobile no 9891492921 :)

            F Offline
            F Offline
            FlyingDancer
            wrote on last edited by
            #5

            :) it is not very good for the soud souds off and on, interrupted Is it better if uninterrupted ?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups