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. Grabbing messages while busy

Grabbing messages while busy

Scheduled Pinned Locked Moved C / C++ / MFC
c++helplearning
6 Posts 5 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.
  • E Offline
    E Offline
    Ernesto D
    wrote on last edited by
    #1

    Hi all, my app has a very time consuming function where all files on the computer are ennumerated, and ibe put a "cancel" button on the dialog so the user can cancel the ongoing operation, but (of course) the app doesnt process its messages while the ennumeration is running, so it never sees the user pressing the cancel button. I know im supposed to implement some code inside the time consuming function so the app has a chance to get and process its messages, but i dont know exacly what functions to call. BTW, the app is a WTL - dialog based app (not MFC). Any help would be much appreciated.

    C E 2 Replies Last reply
    0
    • E Ernesto D

      Hi all, my app has a very time consuming function where all files on the computer are ennumerated, and ibe put a "cancel" button on the dialog so the user can cancel the ongoing operation, but (of course) the app doesnt process its messages while the ennumeration is running, so it never sees the user pressing the cancel button. I know im supposed to implement some code inside the time consuming function so the app has a chance to get and process its messages, but i dont know exacly what functions to call. BTW, the app is a WTL - dialog based app (not MFC). Any help would be much appreciated.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Ernesto D. wrote: I know im supposed to implement some code inside the time consuming function so the app has a chance to get and process its messages, but i dont know exacly what functions to call. You're supposed to do the work in a worker thread, which will leave your UI thread responsive. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      L 1 Reply Last reply
      0
      • C Christian Graus

        Ernesto D. wrote: I know im supposed to implement some code inside the time consuming function so the app has a chance to get and process its messages, but i dont know exacly what functions to call. You're supposed to do the work in a worker thread, which will leave your UI thread responsive. :-) Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

        L Offline
        L Offline
        l a u r e n
        wrote on last edited by
        #3

        or ... worst case scenario (if ur allergic to multi-threading) you should use PeakMessage() etc to see if anythings waiting but thats bad and we dont do lazy bad things here do we? :rolleyes:


        "there is no spoon"
        biz stuff   about me

        T 1 Reply Last reply
        0
        • E Ernesto D

          Hi all, my app has a very time consuming function where all files on the computer are ennumerated, and ibe put a "cancel" button on the dialog so the user can cancel the ongoing operation, but (of course) the app doesnt process its messages while the ennumeration is running, so it never sees the user pressing the cancel button. I know im supposed to implement some code inside the time consuming function so the app has a chance to get and process its messages, but i dont know exacly what functions to call. BTW, the app is a WTL - dialog based app (not MFC). Any help would be much appreciated.

          E Offline
          E Offline
          Ernesto D
          wrote on last edited by
          #4

          Thanks for your answers, i was hoping to avoid multple treads, since the app is just a very "basic" utility that searches for certain files, but if its the only way to go then, so be it. why would it be considered "bad" to use PeakMessage() etc.? thanks.

          2 1 Reply Last reply
          0
          • E Ernesto D

            Thanks for your answers, i was hoping to avoid multple treads, since the app is just a very "basic" utility that searches for certain files, but if its the only way to go then, so be it. why would it be considered "bad" to use PeakMessage() etc.? thanks.

            2 Offline
            2 Offline
            224917
            wrote on last edited by
            #5

            Try this in your while loop.. if(GetMessage(&msg,NULL,0,0)) { DispatchMessage(&msg); if(msg.wParam==WM_DESTROY) { PostQuitMessage(0); return; } } greatest thing is to do wot others think you cant :)
            suhredayan@omniquad.com

            1 Reply Last reply
            0
            • L l a u r e n

              or ... worst case scenario (if ur allergic to multi-threading) you should use PeakMessage() etc to see if anythings waiting but thats bad and we dont do lazy bad things here do we? :rolleyes:


              "there is no spoon"
              biz stuff   about me

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

              Multithreading isn't something you just flip a switch and now your application is multithreaded. If you haven't laid the groundwork for resource locking, it would be a VERY bad idea to try to make an application multithreaded when a message pump is such a simple and functional alternative. Tim Smith I'm going to patent thought. I have yet to see any prior art.

              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