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. WM_PAINT [modified]

WM_PAINT [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 6 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.
  • K Offline
    K Offline
    Krauze
    wrote on last edited by
    #1

    I'm coding a plotting app using coordinates data saved in a .txt file. So I need access files in CDialog::OnPaint(). But it seems not to work coz I find the file pointer doesn't move though CFile::Seek() and CFile::Read() are used. Or could a while loop be in CDialog::OnPaint()?

    modified on Tuesday, September 7, 2010 10:46 PM

    L 1 Reply Last reply
    0
    • K Krauze

      I'm coding a plotting app using coordinates data saved in a .txt file. So I need access files in CDialog::OnPaint(). But it seems not to work coz I find the file pointer doesn't move though CFile::Seek() and CFile::Read() are used. Or could a while loop be in CDialog::OnPaint()?

      modified on Tuesday, September 7, 2010 10:46 PM

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Krauze wrote:

      So I need access files in CDialog::OnPaint().

      I don't think so. OnPaint() may be called hundreds of times, when your window gets resized, maximized, restored, covered and uncovered by some other window, etc. So you should read the file once, beforehand, outside OnPaint(); store all the information in an appropriate data structure, and use that inside OnPaint(). :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      K 1 Reply Last reply
      0
      • L Luc Pattyn

        Krauze wrote:

        So I need access files in CDialog::OnPaint().

        I don't think so. OnPaint() may be called hundreds of times, when your window gets resized, maximized, restored, covered and uncovered by some other window, etc. So you should read the file once, beforehand, outside OnPaint(); store all the information in an appropriate data structure, and use that inside OnPaint(). :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        K Offline
        K Offline
        Krauze
        wrote on last edited by
        #3

        In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

        C C I E 5 Replies Last reply
        0
        • K Krauze

          In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

          C Offline
          C Offline
          Chandrasekharan P
          wrote on last edited by
          #4

          why not use a CArray. store the complete set of values and then load the values dynamically

          1 Reply Last reply
          0
          • K Krauze

            In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

            C Offline
            C Offline
            Cedric Moonen
            wrote on last edited by
            #5

            It's even more appropriate to store the data rather than to read the full file again. For your information, I wrote an article about a charting control, maybe you can have a look at it and use it instead of recreating your own (see my sig). It works fine with that amount of data.

            Cédric Moonen Software developer
            Charting control [v3.0] OpenGL game tutorial in C++

            1 Reply Last reply
            0
            • K Krauze

              In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

              I Offline
              I Offline
              Iain Clarke Warrior Programmer
              wrote on last edited by
              #6

              Just in case the point is not sinking in. 30000 x CPoints = 30000 * 8 bytes = 234k = 1/4 Mb. I think you can afford to use that much ram. What you can't afford is disk access every time your application needs to paint. Cedric's article is a good one - and can thoroughly recommend it. Iain.

              I am one of "those foreigners coming over here and stealing our jobs". Yay me!

              K 1 Reply Last reply
              0
              • K Krauze

                In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

                E Offline
                E Offline
                Emilio Garavaglia
                wrote on last edited by
                #7

                30000 coords 8 bytes each are less than half a megabyte. That's not a big issue! Unless you think your file can be (in certain situations) millions of coords long! But -if that's the problem- consider also that the screen doesn't have millions of points in a line, so it is very wasteful keep all those details during drawing, since nobody will never physically able to see them. If that's the case, consider a design where your file is read in a vector that should not have much more than 10000 records, each of which takes the min, average and max value of a group of coords wide like the number of coords dived by the number of records. At that point, during ON_PAINT, draw an area that for each of the three values, fills the space between the min and max and draw over it a line that follows the average.

                2 bugs found. > recompile ... 65534 bugs found. :doh:

                1 Reply Last reply
                0
                • K Krauze

                  In fact there're up to 30,000 coordinates. So it's kinda terrible to store all of them in a particular structure at runtime.

                  C Offline
                  C Offline
                  Cedric Moonen
                  wrote on last edited by
                  #8

                  Just a precision, your answer makes me wonder. You are not thinking about something like this are you ? :~

                  structure data
                  {
                  double XVal1;
                  double YVal1;
                  double XVal2;
                  double YVal2;

                  ....
                  ....
                  ...

                  double XVal30000;
                  double YVal30000;
                  };

                  This would indeed be really really really horrible code and a good candidate for The Daily WTF[^]

                  Cédric Moonen Software developer
                  Charting control [v3.0] OpenGL game tutorial in C++

                  1 Reply Last reply
                  0
                  • I Iain Clarke Warrior Programmer

                    Just in case the point is not sinking in. 30000 x CPoints = 30000 * 8 bytes = 234k = 1/4 Mb. I think you can afford to use that much ram. What you can't afford is disk access every time your application needs to paint. Cedric's article is a good one - and can thoroughly recommend it. Iain.

                    I am one of "those foreigners coming over here and stealing our jobs". Yay me!

                    K Offline
                    K Offline
                    Krauze
                    wrote on last edited by
                    #9

                    Thank y'all!

                    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