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 dialog application problem

mfc dialog application problem

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestion
15 Posts 4 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.
  • C CPallini

    pierre_ribery wrote:

    Forget the timer approach. PostMessage is the correct way to do this.

    Why? :)

    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

    P Offline
    P Offline
    pierre_ribery
    wrote on last edited by
    #6

    Because you are not guaranteed that the WM_TIMER message will be handled. THe dialog might be closed before the timer elapses (lets say 200-300ms). If you post a user defined message in OnInitDialog you are guaranteed that it will be handled before any messages sent after this! the timer might be invoked too late. From MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue. also, you have to remember to kill the timer as the first thing in the WM_TIMER handler. Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources. Might be more reasons, but it boils down to what is the best approach. The timer approach is a possibility, but not the BEST.

    C 1 Reply Last reply
    0
    • P pierre_ribery

      Because you are not guaranteed that the WM_TIMER message will be handled. THe dialog might be closed before the timer elapses (lets say 200-300ms). If you post a user defined message in OnInitDialog you are guaranteed that it will be handled before any messages sent after this! the timer might be invoked too late. From MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue. also, you have to remember to kill the timer as the first thing in the WM_TIMER handler. Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources. Might be more reasons, but it boils down to what is the best approach. The timer approach is a possibility, but not the BEST.

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #7

      pierre_ribery wrote:

      THe dialog might be closed before the timer elapses (lets say 200-300ms).

      Provided you know such a feature it may be not a problem.

      pierre_ribery wrote:

      also, you have to remember to kill the timer as the first thing in the WM_TIMER handler.

      Of course. one-shot has to be one-shot, after all!

      pierre_ribery wrote:

      The timer approach is a possibility, but not the BEST

      pierre_ribery wrote:

      rom MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.

      To both points applies: Provided you've to immediatly execute code. :)

      pierre_ribery wrote:

      Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources.

      Oh, there are two possibilities here: (1) You already have such a timer (for different purposes) and you're just using its first call (in such a case, no performance loss). (2) You haven't such a timer and hence make a one-shot timer that is a low resource waster.

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

      modified on Monday, December 17, 2007 5:11:51 AM

      P 2 Replies Last reply
      0
      • C CPallini

        You can call PostMessage() inside OnInitDialog to post a user message, then in the message handler do needed stuff. You can also use a one-shot timer for it. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

        Z Offline
        Z Offline
        zengkun100
        wrote on last edited by
        #8

        Thank you CPallini Does that message will be the first message that the application received after it showed on the desktop? :)

        1 Reply Last reply
        0
        • C CPallini

          pierre_ribery wrote:

          THe dialog might be closed before the timer elapses (lets say 200-300ms).

          Provided you know such a feature it may be not a problem.

          pierre_ribery wrote:

          also, you have to remember to kill the timer as the first thing in the WM_TIMER handler.

          Of course. one-shot has to be one-shot, after all!

          pierre_ribery wrote:

          The timer approach is a possibility, but not the BEST

          pierre_ribery wrote:

          rom MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.

          To both points applies: Provided you've to immediatly execute code. :)

          pierre_ribery wrote:

          Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources.

          Oh, there are two possibilities here: (1) You already have such a timer (for different purposes) and you're just using its first call (in such a case, no performance loss). (2) You haven't such a timer and hence make a one-shot timer that is a low resource waster.

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

          modified on Monday, December 17, 2007 5:11:51 AM

          P Offline
          P Offline
          pierre_ribery
          wrote on last edited by
          #9

          Please re-read my post, I have made some updates.

          C 1 Reply Last reply
          0
          • Z zengkun100

            This is a dialog based application. I want the application execute some code after the main window and all child windows displayed correctly. Where should I write the code ? I think OnInitDialog is not a good place, because the window have not displayed yet. Thank you all!

            Z Offline
            Z Offline
            zengkun100
            wrote on last edited by
            #10

            Thank you all! I found call PostMessage in the dialog's OnInitDialog member before it returned is a good solution, it woks well :)

            1 Reply Last reply
            0
            • P pierre_ribery

              Please re-read my post, I have made some updates.

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #11

              Thank you, I've just update mine :-D

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

              1 Reply Last reply
              0
              • C CPallini

                pierre_ribery wrote:

                THe dialog might be closed before the timer elapses (lets say 200-300ms).

                Provided you know such a feature it may be not a problem.

                pierre_ribery wrote:

                also, you have to remember to kill the timer as the first thing in the WM_TIMER handler.

                Of course. one-shot has to be one-shot, after all!

                pierre_ribery wrote:

                The timer approach is a possibility, but not the BEST

                pierre_ribery wrote:

                rom MSDN: The WM_TIMER message is a low-priority message. The GetMessage and PeekMessage functions post this message only when no other higher-priority messages are in the thread's message queue.

                To both points applies: Provided you've to immediatly execute code. :)

                pierre_ribery wrote:

                Another point is that it uses significantly more system resources to simply post a message. Why create a timer which will post a message, when you can directly post the message? Timers are limited system resources.

                Oh, there are two possibilities here: (1) You already have such a timer (for different purposes) and you're just using its first call (in such a case, no performance loss). (2) You haven't such a timer and hence make a one-shot timer that is a low resource waster.

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                modified on Monday, December 17, 2007 5:11:51 AM

                P Offline
                P Offline
                pierre_ribery
                wrote on last edited by
                #12

                Why wait executing the code? The sooner the better I would think. That being said, you are wasting resources even if it is a one-shot timer. I think that any professional windows programmer would agree with me that the timer approach is not the best, but again you are free to do it the timer way if you think that is best.

                C 1 Reply Last reply
                0
                • P pierre_ribery

                  Why wait executing the code? The sooner the better I would think. That being said, you are wasting resources even if it is a one-shot timer. I think that any professional windows programmer would agree with me that the timer approach is not the best, but again you are free to do it the timer way if you think that is best.

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #13

                  pierre_ribery wrote:

                  That being said, you are wasting resources even if it is a one-shot timer.

                  :-D

                  pierre_ribery wrote:

                  I think that any professional windows programmer would agree with me that the timer approach is not the best

                  It is just an alternative to me. Anyway, thank you for including me among the hobbysts :laugh:

                  pierre_ribery wrote:

                  you are free to do it the timer way if you think that is best.

                  Oh freedom, what a wonderful thing! :) Have a nice day :rose:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                  P 1 Reply Last reply
                  0
                  • C CPallini

                    pierre_ribery wrote:

                    That being said, you are wasting resources even if it is a one-shot timer.

                    :-D

                    pierre_ribery wrote:

                    I think that any professional windows programmer would agree with me that the timer approach is not the best

                    It is just an alternative to me. Anyway, thank you for including me among the hobbysts :laugh:

                    pierre_ribery wrote:

                    you are free to do it the timer way if you think that is best.

                    Oh freedom, what a wonderful thing! :) Have a nice day :rose:

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                    P Offline
                    P Offline
                    pierre_ribery
                    wrote on last edited by
                    #14

                    I agree that it is an alternative. But can you please answer this question: Which approach do you think is the best?

                    C 1 Reply Last reply
                    0
                    • P pierre_ribery

                      I agree that it is an alternative. But can you please answer this question: Which approach do you think is the best?

                      C Offline
                      C Offline
                      CPallini
                      wrote on last edited by
                      #15

                      pierre_ribery wrote:

                      I agree that it is an alternative. But can you please answer this question: Which approach do you think is the best?

                      Yours (you're a professional, after all), of course. :-D just kidding. :rose:

                      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.

                      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