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. Multithreading

Multithreading

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
5 Posts 3 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.
  • A Offline
    A Offline
    AslFunky
    wrote on last edited by
    #1

    Hi guys, i am new to multithreading in MFC. I have gone through many of the examples posted on CodeProject, but i am still not satisfied. What i want to know is that, suppose i have my window, and i want to create a thread which, say, takes care of all the keyboard inputs, another thread which takes care of all the mouse inputs. So far whatever examples and tutorials i have gone through first create a new window using a thread and then control all the operations. I want my parent window to have a thread to do all those stuff. Can anyone help me out. :)Thanx in advance!:) AslFunky

    G F 2 Replies Last reply
    0
    • A AslFunky

      Hi guys, i am new to multithreading in MFC. I have gone through many of the examples posted on CodeProject, but i am still not satisfied. What i want to know is that, suppose i have my window, and i want to create a thread which, say, takes care of all the keyboard inputs, another thread which takes care of all the mouse inputs. So far whatever examples and tutorials i have gone through first create a new window using a thread and then control all the operations. I want my parent window to have a thread to do all those stuff. Can anyone help me out. :)Thanx in advance!:) AslFunky

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      With MFC, all GUI interactions must take place on the UI thread; this is inherent to the MFC architecture. You can, however, have separate worker threads that do the actual work associated with keyboard and mouse actions. The UI thread detects a keyboard and/or mouse action and starts a worker thread. The worker thread does its thing, and the posts messages back to the UI thread as necessary. AslFunky wrote: i want to create a thread which, say, takes care of all the keyboard inputs, another thread which takes care of all the mouse inputs This statement sounds like you want to make a general change in how Windows applications work. I think you would be better off learning how to use the Windows input model, rather than trying to subvert it.


      Software Zen: delete this;

      A 1 Reply Last reply
      0
      • A AslFunky

        Hi guys, i am new to multithreading in MFC. I have gone through many of the examples posted on CodeProject, but i am still not satisfied. What i want to know is that, suppose i have my window, and i want to create a thread which, say, takes care of all the keyboard inputs, another thread which takes care of all the mouse inputs. So far whatever examples and tutorials i have gone through first create a new window using a thread and then control all the operations. I want my parent window to have a thread to do all those stuff. Can anyone help me out. :)Thanx in advance!:) AslFunky

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

        Hi. The easist way is use AfxBeginThread (threadproc,hwnd,threadpriority) threadproc : threadfunction with form UINT threadproc(void* para) { //here do any thing return true } hwnd:this is the para parameter on threadproc function threadpriority:may be 1-THREAD_PRIORITY_NORMAL 2-THREAD_PRIORITY_LOWEST . AfxBeginThread return CWinThread object this object can be use to suspend and kill the thread u can use many thread with the above story If this not help u contact me on faroq_tam2004@yahoo.com to get sample MFC program describe MFC MThreading bye. On Earth nothing impossible, while your mind running. Faroqtam

        1 Reply Last reply
        0
        • G Gary R Wheeler

          With MFC, all GUI interactions must take place on the UI thread; this is inherent to the MFC architecture. You can, however, have separate worker threads that do the actual work associated with keyboard and mouse actions. The UI thread detects a keyboard and/or mouse action and starts a worker thread. The worker thread does its thing, and the posts messages back to the UI thread as necessary. AslFunky wrote: i want to create a thread which, say, takes care of all the keyboard inputs, another thread which takes care of all the mouse inputs This statement sounds like you want to make a general change in how Windows applications work. I think you would be better off learning how to use the Windows input model, rather than trying to subvert it.


          Software Zen: delete this;

          A Offline
          A Offline
          AslFunky
          wrote on last edited by
          #4

          Hi thanx for replying,;) Is it necessary to do my stuff in a worker thread? Actually i am a little nervous in creating a worker thread. i always have one confusion, how will i assign any job to a function which is not a member of my class. I mean, how will this function UINT threadproc(void* para) be able to access the members of my class when it is not a member of my class. Can you please elaborate on this point. Thanx in advance. AslFunky

          G 1 Reply Last reply
          0
          • A AslFunky

            Hi thanx for replying,;) Is it necessary to do my stuff in a worker thread? Actually i am a little nervous in creating a worker thread. i always have one confusion, how will i assign any job to a function which is not a member of my class. I mean, how will this function UINT threadproc(void* para) be able to access the members of my class when it is not a member of my class. Can you please elaborate on this point. Thanx in advance. AslFunky

            G Offline
            G Offline
            Gary R Wheeler
            wrote on last edited by
            #5

            AslFunky wrote: Is it necessary to do my stuff in a worker thread? That depends on what you need to do. If the process takes a lot of time, you don't want to block the user interface while the process runs. That sort of thing is something you can put in a worker thread. AslFunky wrote: I mean, how will this function UINT threadproc(void* para) be able to access the members of my class when it is not a member of my class. I always use something like the following:

            class Stuff {
            //...
            static UINT ThreadStart(LPVOID parameter);
            UINT Thread();
            };
            UINT Stuff::ThreadStart(LPVOID parameter)
            {
            Stuff *_this = (Stuff *)parameter;
            return _this->Thread();
            }
            UINT Stuff::Thread()
            {
            //...
            }
            //...
            AfxBeginThread(ThreadStart,(LPVOID)this);

            The static member function matches the prototype required by AfxBeginThread(). You use the parameter to pass a pointer to an instance of your class. In my example, I passed the this pointer, which means I'm starting the thread from another member function of the class. The function that does the actual work of the thread is called Thread(), and since it is a member function, it can access other members of the Stuff class.


            Software Zen: delete this;

            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