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. MFC worker thread and message Queues

MFC worker thread and message Queues

Scheduled Pinned Locked Moved C / C++ / MFC
c++designlearning
6 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.
  • K Offline
    K Offline
    Kevin Behilo
    wrote on last edited by
    #1

    Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin

    T K 2 Replies Last reply
    0
    • K Kevin Behilo

      Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      GetMessage will hang if you don't have a message waiting. Are you using PostThreadMessage to post a message to that thread? If so, make sure you are doing that properly. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

      K 1 Reply Last reply
      0
      • T Tim Smith

        GetMessage will hang if you don't have a message waiting. Are you using PostThreadMessage to post a message to that thread? If so, make sure you are doing that properly. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

        K Offline
        K Offline
        Kevin Behilo
        wrote on last edited by
        #3

        Tim, I’ve been writing server apps w/o a GUI so bear with me on my next question. Why would the GUI hang if a message queue has been created on an independent worker thread? I’m beginning to believe that a queue has not been created because the call to PeekMessage returns FALSE. -Kevin

        K 1 Reply Last reply
        0
        • K Kevin Behilo

          Tim, I’ve been writing server apps w/o a GUI so bear with me on my next question. Why would the GUI hang if a message queue has been created on an independent worker thread? I’m beginning to believe that a queue has not been created because the call to PeekMessage returns FALSE. -Kevin

          K Offline
          K Offline
          Kevin Behilo
          wrote on last edited by
          #4

          I figured out why the GUI was hanging. A mistake not related to the Message Queue. But I still can't get the Message Q to work. Is there any reason why the scheme in my first post would not work? Is the thread ID that I get from the CWinThread valid to use in: PostThreadMessage(pThread->m_nThreadID, 1,1,1); :confused: Thanks, Kevin

          T 1 Reply Last reply
          0
          • K Kevin Behilo

            I figured out why the GUI was hanging. A mistake not related to the Message Queue. But I still can't get the Message Q to work. Is there any reason why the scheme in my first post would not work? Is the thread ID that I get from the CWinThread valid to use in: PostThreadMessage(pThread->m_nThreadID, 1,1,1); :confused: Thanks, Kevin

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #5

            Without more example code, I have no idea. Tim Smith I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?

            1 Reply Last reply
            0
            • K Kevin Behilo

              Hi, When I’m not using MFC and starting worker threads with _beginthreadex I can give them message queues by calling: PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); and then later on in the thread use GetMessage. I can do this without a window which is pretty cool. I tried putting PeekMessage into the ThreadFunc of a CWinThread derived class but it fails and, of course, the later call to GetMessage causes the program to hang. Before I start pounding my head against the wall I figured I would ask here to see if anybody would know why this would fail and if it is possible to workaround (without creating a window and using a UI thread). Thanks, -Kevin

              K Offline
              K Offline
              Kevin Behilo
              wrote on last edited by
              #6

              I gave up on trying to create a message queue in an MFC worker thread by calling PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE); There is a good article by Joseph M. Newcomer titled "Using User-Interface Threads" which describes what I wanted to do using UI Threads. I still would like to know why i can't create the message queue, though! -Kevin

              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