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. EXECUTE code 1 after the other only

EXECUTE code 1 after the other only

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++javaannouncement
10 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.
  • T Offline
    T Offline
    Trupti Mehta
    wrote on last edited by
    #1

    Hello Friends, I have the following lines of code. The CRHPostMessageToParent() calls parent to parent class methods.

    AfxMessageBox(\_T("Page2::Inside TellPArent"));
    
    // Update deptStock obj with the parent
    this->CRHPostMessageToParent(WM\_CHANGED\_DS, (int)&deptStock);
    this->ShowWindow(SW\_HIDE);
    this->CRHPostMessageToParent(WM\_SHOW\_NEXT\_VIEW, i);
    AfxMessageBox(\_T("Page2::Finished TellParent"));
    

    These codes start running untill the previous line code is not completed. I want to ensure, that it should proceed to next line only when the first is completed. The CRHPostMessageToParent() calls PostMessage () to parent & returns void. The parent function OnChanged_DS() returns LRESULT. In Java, this can be achived by assigning each task in thread and synchronizing it, which makes sure that the process is completed & then only the handle is released. How do I achive the same in VC++6? I hope I have explained my situation to the best. If yet not, ask me.

    Thanks Terry

    D S J 3 Replies Last reply
    0
    • T Trupti Mehta

      Hello Friends, I have the following lines of code. The CRHPostMessageToParent() calls parent to parent class methods.

      AfxMessageBox(\_T("Page2::Inside TellPArent"));
      
      // Update deptStock obj with the parent
      this->CRHPostMessageToParent(WM\_CHANGED\_DS, (int)&deptStock);
      this->ShowWindow(SW\_HIDE);
      this->CRHPostMessageToParent(WM\_SHOW\_NEXT\_VIEW, i);
      AfxMessageBox(\_T("Page2::Finished TellParent"));
      

      These codes start running untill the previous line code is not completed. I want to ensure, that it should proceed to next line only when the first is completed. The CRHPostMessageToParent() calls PostMessage () to parent & returns void. The parent function OnChanged_DS() returns LRESULT. In Java, this can be achived by assigning each task in thread and synchronizing it, which makes sure that the process is completed & then only the handle is released. How do I achive the same in VC++6? I hope I have explained my situation to the best. If yet not, ask me.

      Thanks Terry

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Trupti Mehta wrote:

      How do I achive the same in VC++6?

      You can also use synchronization.

      "Love people and use things, not love things and use people." - Unknown

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      1 Reply Last reply
      0
      • T Trupti Mehta

        Hello Friends, I have the following lines of code. The CRHPostMessageToParent() calls parent to parent class methods.

        AfxMessageBox(\_T("Page2::Inside TellPArent"));
        
        // Update deptStock obj with the parent
        this->CRHPostMessageToParent(WM\_CHANGED\_DS, (int)&deptStock);
        this->ShowWindow(SW\_HIDE);
        this->CRHPostMessageToParent(WM\_SHOW\_NEXT\_VIEW, i);
        AfxMessageBox(\_T("Page2::Finished TellParent"));
        

        These codes start running untill the previous line code is not completed. I want to ensure, that it should proceed to next line only when the first is completed. The CRHPostMessageToParent() calls PostMessage () to parent & returns void. The parent function OnChanged_DS() returns LRESULT. In Java, this can be achived by assigning each task in thread and synchronizing it, which makes sure that the process is completed & then only the handle is released. How do I achive the same in VC++6? I hope I have explained my situation to the best. If yet not, ask me.

        Thanks Terry

        S Offline
        S Offline
        sudhir_Kumar
        wrote on last edited by
        #3

        You can use MFC sync classes like CMutex,CEvent and CSemaPhore.

        Sudhir Kumar

        1 Reply Last reply
        0
        • T Trupti Mehta

          Hello Friends, I have the following lines of code. The CRHPostMessageToParent() calls parent to parent class methods.

          AfxMessageBox(\_T("Page2::Inside TellPArent"));
          
          // Update deptStock obj with the parent
          this->CRHPostMessageToParent(WM\_CHANGED\_DS, (int)&deptStock);
          this->ShowWindow(SW\_HIDE);
          this->CRHPostMessageToParent(WM\_SHOW\_NEXT\_VIEW, i);
          AfxMessageBox(\_T("Page2::Finished TellParent"));
          

          These codes start running untill the previous line code is not completed. I want to ensure, that it should proceed to next line only when the first is completed. The CRHPostMessageToParent() calls PostMessage () to parent & returns void. The parent function OnChanged_DS() returns LRESULT. In Java, this can be achived by assigning each task in thread and synchronizing it, which makes sure that the process is completed & then only the handle is released. How do I achive the same in VC++6? I hope I have explained my situation to the best. If yet not, ask me.

          Thanks Terry

          J Offline
          J Offline
          JudyL_MD
          wrote on last edited by
          #4

          Does your CRHPostMessageToParent call PostMessage or SendMessage? Using SendMessage means that control does not return until the message has been processed which sounds like what you want. Judy

          D 1 Reply Last reply
          0
          • J JudyL_MD

            Does your CRHPostMessageToParent call PostMessage or SendMessage? Using SendMessage means that control does not return until the message has been processed which sounds like what you want. Judy

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            JudyL_FL wrote:

            Does your CRHPostMessageToParent call PostMessage or SendMessage?

            Did you miss: The CRHPostMessageToParent() calls PostMessage ()...

            "Love people and use things, not love things and use people." - Unknown

            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

            J 1 Reply Last reply
            0
            • D David Crow

              JudyL_FL wrote:

              Does your CRHPostMessageToParent call PostMessage or SendMessage?

              Did you miss: The CRHPostMessageToParent() calls PostMessage ()...

              "Love people and use things, not love things and use people." - Unknown

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              J Offline
              J Offline
              JudyL_MD
              wrote on last edited by
              #6

              DavidCrow wrote:

              Did you miss

              Yes and no :) . Yes, in that I didn't see the exact API function name and read the function description as "post a message." No, in that the function name implies Post instead of Send. More important was to make sure the OP was aware of the difference between PostMessage and SendMessage - unclear from the original post. Judy

              T 1 Reply Last reply
              0
              • J JudyL_MD

                DavidCrow wrote:

                Did you miss

                Yes and no :) . Yes, in that I didn't see the exact API function name and read the function description as "post a message." No, in that the function name implies Post instead of Send. More important was to make sure the OP was aware of the difference between PostMessage and SendMessage - unclear from the original post. Judy

                T Offline
                T Offline
                Trupti Mehta
                wrote on last edited by
                #7

                It calls the PostMessage(message, WPARAM, LPARAM) How do I achieve the goal? Can you give some guidance/example to work with CEvent etc classes as mentioned in ealier post.

                Thanks Terry

                J 1 Reply Last reply
                0
                • T Trupti Mehta

                  It calls the PostMessage(message, WPARAM, LPARAM) How do I achieve the goal? Can you give some guidance/example to work with CEvent etc classes as mentioned in ealier post.

                  Thanks Terry

                  J Offline
                  J Offline
                  JudyL_MD
                  wrote on last edited by
                  #8

                  I'm not the one who mentioned using CEvent. My suggestion was to call SendMessage instead of PostMessage to make the caller wait until the message was processed. Judy

                  T 1 Reply Last reply
                  0
                  • J JudyL_MD

                    I'm not the one who mentioned using CEvent. My suggestion was to call SendMessage instead of PostMessage to make the caller wait until the message was processed. Judy

                    T Offline
                    T Offline
                    Trupti Mehta
                    wrote on last edited by
                    #9

                    Oh sorry Judy. must have read in some website for solution of the problem. Anyways, I changed from PostMessage to SendMessage. Was just wondering will it make any differnece in using any of those. I mean, i changed from post to send will that make any other impact on the application other than not returning till the message is posted. Am just curious about it. Thanks Judy.

                    Thanks Terry

                    J 1 Reply Last reply
                    0
                    • T Trupti Mehta

                      Oh sorry Judy. must have read in some website for solution of the problem. Anyways, I changed from PostMessage to SendMessage. Was just wondering will it make any differnece in using any of those. I mean, i changed from post to send will that make any other impact on the application other than not returning till the message is posted. Am just curious about it. Thanks Judy.

                      Thanks Terry

                      J Offline
                      J Offline
                      JudyL_MD
                      wrote on last edited by
                      #10

                      Trupti Mehta wrote:

                      Was just wondering will it make any differnece in using any of those. I mean, i changed from post to send will that make any other impact on the application other than not returning till the message is posted.

                      Nope, that is the only difference. It can become an issue in multi-threaded programs whether you use Post or Send depending on how your GUI thread and your worker threads synchronize with each other. If you use Send, you need to be (even more) careful about potential deadlocks since Send causes your thread to wait. Judy

                      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