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. Visual C++/MFC Thread Question

Visual C++/MFC Thread Question

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialhelpquestion
8 Posts 6 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.
  • S Offline
    S Offline
    suzie100
    wrote on last edited by
    #1

    Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..

    A K E R 4 Replies Last reply
    0
    • S suzie100

      Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..

      A Offline
      A Offline
      Achim Klein
      wrote on last edited by
      #2

      I could mail you a simple examlpe. It popups message dialogs after a specified time span. Abortion is also included...

      1 Reply Last reply
      0
      • S suzie100

        Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..

        K Offline
        K Offline
        koothkeeper
        wrote on last edited by
        #3

        Here is a useful link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/\_mfc\_afxbeginthread.asp Try something like this to get you started: INT MyThread( LPVOID ptr ); int main( int argc, char** argv ) { CWinThread* T; DWORD dwWait; T = AfxBeginThread( MyThread, NULL ); dwWait = WaitForSingleObject( T->m_hThread, INFINITE ); return 0; } /* main() */ INT MyThread( LPVOID ptr ) { AfxMessageBox( "Hello, world!" ); return 0; }

        1 Reply Last reply
        0
        • S suzie100

          Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..

          E Offline
          E Offline
          Eytukan
          wrote on last edited by
          #4

          create a worker thread.. UINT ClassName ::Thread1(LPVOID lp) { ClassName *cn = (ClassName*)lp; cn->Thread1(); } //// define the functionality inside the thread void ClassName::Thread1() { while(1) { AfxMessageBox("In thread"); Sleep(millisec); } } in the function, Anyfun() { CWinThread *cwt; cwt=AfxBeginThread(Thread1,this); } you can suspend the thread by cwt->SuspendThread(); resume by cwt->ResumeThread(); ExitInstance() will delete it Regards, V

          E 1 Reply Last reply
          0
          • E Eytukan

            create a worker thread.. UINT ClassName ::Thread1(LPVOID lp) { ClassName *cn = (ClassName*)lp; cn->Thread1(); } //// define the functionality inside the thread void ClassName::Thread1() { while(1) { AfxMessageBox("In thread"); Sleep(millisec); } } in the function, Anyfun() { CWinThread *cwt; cwt=AfxBeginThread(Thread1,this); } you can suspend the thread by cwt->SuspendThread(); resume by cwt->ResumeThread(); ExitInstance() will delete it Regards, V

            E Offline
            E Offline
            Eytukan
            wrote on last edited by
            #5

            to have a better look on a Thread... click on [View Thread] Below!!:laugh: jus fr fun, V............v

            T 1 Reply Last reply
            0
            • E Eytukan

              to have a better look on a Thread... click on [View Thread] Below!!:laugh: jus fr fun, V............v

              T Offline
              T Offline
              ThatsAlok
              wrote on last edited by
              #6

              Vivekuniq wrote: click on [View Thread] Below!! I have Clicked [View Thread] and................... I got nothing............:->

              "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

              cheers, Alok Gupta VC Forum Q&A :- I/ IV

              1 Reply Last reply
              0
              • S suzie100

                Hi I am trying to learn MFC and Visual C++ while working on a project. I want to do a simple task in a function. It is when the function is called I need to spawn a separate thread, pop up a message box in that thread and when the user presses OK or Cancel in that message Box, kill the spawned thread and pass control back to the main thread. I am clueless how to do this. A simple code example will really help. Thanks a Ton..

                R Offline
                R Offline
                Ravi Bhavnani
                wrote on last edited by
                #7

                This[^] article may help.  Specifically, the section titled "Responding to user input while performing a long task". /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                S 1 Reply Last reply
                0
                • R Ravi Bhavnani

                  This[^] article may help.  Specifically, the section titled "Responding to user input while performing a long task". /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

                  S Offline
                  S Offline
                  suzie100
                  wrote on last edited by
                  #8

                  Thanks for all the help. I could accomplish what I wanted to do with all your help. Thank Again

                  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