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. How to cancel long time drawing

How to cancel long time drawing

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicstutorial
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.
  • F Offline
    F Offline
    fitatc
    wrote on last edited by
    #1

    I am writing a code to do a long time draw like:

    void MyDialog::DoSlowDraw(DWORD tDelay){
    while(notFinished){
    DrawNextLine(); // like LineTo()....
    Sleep(tDelay);
    }
    }

    And it's better to have a "cancel button" because it may take a long time according to tDelay. --------------------- :(( My try: To handle "cancle button clicked Message" , Drawing must be done by another thread.

    UINT DrawProc( LPVOID pParam )
    {
    CMyDialog* pform = (CMyDialog*)pParam;
    int timeDelay = pform->timeD;
    Line_list* pLines = pform->m_pLines;
    CClientDC cdc(pform);
    //Draw....

    It's worked, but as far as I know 1. Work thread should not touch the GUI ---- (Do the drawing). 2. MFC object should not passed to another thread ---- (passing drawing data by CMyDialog*) :confused:Is there a good way to cancle long time drawing.

    D 1 Reply Last reply
    0
    • F fitatc

      I am writing a code to do a long time draw like:

      void MyDialog::DoSlowDraw(DWORD tDelay){
      while(notFinished){
      DrawNextLine(); // like LineTo()....
      Sleep(tDelay);
      }
      }

      And it's better to have a "cancel button" because it may take a long time according to tDelay. --------------------- :(( My try: To handle "cancle button clicked Message" , Drawing must be done by another thread.

      UINT DrawProc( LPVOID pParam )
      {
      CMyDialog* pform = (CMyDialog*)pParam;
      int timeDelay = pform->timeD;
      Line_list* pLines = pform->m_pLines;
      CClientDC cdc(pform);
      //Draw....

      It's worked, but as far as I know 1. Work thread should not touch the GUI ---- (Do the drawing). 2. MFC object should not passed to another thread ---- (passing drawing data by CMyDialog*) :confused:Is there a good way to cancle long time drawing.

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

      fitatc wrote:

      Is there a good way to cancle long time drawing.

      See here.

      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      F 1 Reply Last reply
      0
      • D David Crow

        fitatc wrote:

        Is there a good way to cancle long time drawing.

        See here.

        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

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

        May be You misunderstanding my qustion because of my poor english. My Question is "How to do multiThread thing in one GUI thread." in another word. But by your advise, I did find the answer from old Qustions By another guy: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=570370[^]

        D 1 Reply Last reply
        0
        • F fitatc

          May be You misunderstanding my qustion because of my poor english. My Question is "How to do multiThread thing in one GUI thread." in another word. But by your advise, I did find the answer from old Qustions By another guy: http://www.codeproject.com/script/Forums/View.aspx?fid=1647&msg=570370[^]

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

          fitatc wrote:

          May be You misunderstanding my qustion because of my poor english.

          I understood you perfectly. If you are drawing in a worker thread and you need to cancel that thread, my advice is the way to go. Using a message pump is an antiquated and largely unused 16-bit Windows solution.

          "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          F 1 Reply Last reply
          0
          • D David Crow

            fitatc wrote:

            May be You misunderstanding my qustion because of my poor english.

            I understood you perfectly. If you are drawing in a worker thread and you need to cancel that thread, my advice is the way to go. Using a message pump is an antiquated and largely unused 16-bit Windows solution.

            "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            F Offline
            F Offline
            fitatc
            wrote on last edited by
            #5

            Sorry for my late response,(I am in a busy work now) You are right, but before that, :confused:Do you think it is OK to draw in the work thread? I mean, a good design? because drawing is touching the GUI I thought, maybe I was wrong.

            D 1 Reply Last reply
            0
            • F fitatc

              Sorry for my late response,(I am in a busy work now) You are right, but before that, :confused:Do you think it is OK to draw in the work thread? I mean, a good design? because drawing is touching the GUI I thought, maybe I was wrong.

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

              fitatc wrote:

              Do you think it is OK to draw in the work thread?

              I would think not. Have the worker thread post a message to the main thread (that owns the UI).

              "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

              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