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. draw multiple lines and move then on screen

draw multiple lines and move then on screen

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

    I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines. I have created rectangle region for each line and trying to move the line. When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen. How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC. Please help me how can I do it. Any help is highly appreciated. Thanks Sujan

    L 1 Reply Last reply
    0
    • A appollosputnik

      I am writing a pure C based win32 applications. I have drawn line. Now i want to translate that line, move the line whereved user wants to move on screen. Then again I drawn another line, I am drawing multiple lines. I have created rectangle region for each line and trying to move the line. When I move the 2nd line over the 1st line on screen the 1st line is getting wiped out. Because I am InvalidateRect() of the rect for the line being moved, so when that rectangle is crossing the other line then the other line is getting removed from the screen. How can I rectify it. How can I have all the lined being on the screen and moved according to the user's wish. The code should be pure C and win32 no MFC. Please help me how can I do it. Any help is highly appreciated. Thanks Sujan

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You should draw all the lines in the code that handles the WM_PAINT message. Each time a new line is created, you save the details in a list or similar array. Then as your paint code is called, it should iterate that list and draw each line.

      Use the best guess

      A 1 Reply Last reply
      0
      • L Lost User

        You should draw all the lines in the code that handles the WM_PAINT message. Each time a new line is created, you save the details in a list or similar array. Then as your paint code is called, it should iterate that list and draw each line.

        Use the best guess

        A Offline
        A Offline
        appollosputnik
        wrote on last edited by
        #3

        how can I implement a transform for each line. I want to pick a line by mouse and then move it anywhere on the screen and place it. drag and move. Currently I am defining a a rect for each line and doing InvalidateRect() and moving and when this line is crossing other line , the other line is getting removed or wiped out. How can I move lines on screen without affecting other lines. Thanks Sujan

        L E 2 Replies Last reply
        0
        • A appollosputnik

          how can I implement a transform for each line. I want to pick a line by mouse and then move it anywhere on the screen and place it. drag and move. Currently I am defining a a rect for each line and doing InvalidateRect() and moving and when this line is crossing other line , the other line is getting removed or wiped out. How can I move lines on screen without affecting other lines. Thanks Sujan

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          I just explained what you have to do; redraw them all, not just the one that has moved. You need to invalidate the entire Window, or ensure that you check each line within the invalidated rectangle. Understanding this basic concept is key to writing Windows applications.

          Use the best guess

          R 1 Reply Last reply
          0
          • L Lost User

            I just explained what you have to do; redraw them all, not just the one that has moved. You need to invalidate the entire Window, or ensure that you check each line within the invalidated rectangle. Understanding this basic concept is key to writing Windows applications.

            Use the best guess

            R Offline
            R Offline
            Rajdeep_
            wrote on last edited by
            #5

            Understanding this basic concept is key to writing Windows applications

            very true. You had already justified it in your first reply. :)

            1 Reply Last reply
            0
            • A appollosputnik

              how can I implement a transform for each line. I want to pick a line by mouse and then move it anywhere on the screen and place it. drag and move. Currently I am defining a a rect for each line and doing InvalidateRect() and moving and when this line is crossing other line , the other line is getting removed or wiped out. How can I move lines on screen without affecting other lines. Thanks Sujan

              E Offline
              E Offline
              Erudite_Eric
              wrote on last edited by
              #6

              Richarsd just told you! Learn to read before learning to code.

              L 1 Reply Last reply
              0
              • E Erudite_Eric

                Richarsd just told you! Learn to read before learning to code.

                L Offline
                L Offline
                leon de boer
                wrote on last edited by
                #7

                That is perhaps the most ugliest way to solve the problem and has many horrible disadvantages ... IT IS OLD SCHOOL HORRIBLE DONT DO IT. Problems you will definitely encounter: 1.) The draw process become slower and slower the more lines you have to draw 2.) As your draw process is contained inside the WM_PAINT message your can't thread it 3.) Your application becomes locked and unresponsive while in the draw process 4.) Every time you resize the window it will redraw all the line database 5.) Every time you move the window order or position it will do an entire redraw Get an old copy of MS_WORD and open a 1MB image file if you want to see what it looks like. Old versions of many Cad programs and Corel draw were practically unusable because they used the above technique and we have long since moved on from it. The correct and more modern way to do this is to create a drawing thread that converts your line database onto a memory DC. That is all the thread does all the time when triggered. The WM_PAINT message simply puts the last finished memory DC from the thread to screen. Usually every database alteration is held so you can also undo-redo function it. The obvious advantages is your program never suffers non responsive or semi locked behavior no matter how complex the drawing gets and the application drawing process does not flash and carry on. Let me know if you get stuck and I will do a quick stub to show you how it works.

                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