WM_PAINT [modified]
-
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
-
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
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.
-
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.
-
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.
why not use a CArray. store the complete set of values and then load the values dynamically
-
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.
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++ -
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.
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!
-
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.
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:
-
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.
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++ -
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!