Hello all,
I just started with MFC and Document/View architecture and have a problem with displaying text which changes quite often.
There's the setup:
1. A packet source sends me about 10 packets in a second.
2. I read and parse the data in a worker thread in Document.
3. When I decide it's time to refresh displayed data, I send a message to Main Frame, which reposts the message to View, where I call InvalidateRect() on rectangles with new data.
4. In OnDraw I just call a member function of Document which gets a CDC and rectangle and does all the drawing:
void CSimView::OnDraw(CDC* pDC)
{
CSimDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
And one more edit: the redrawing function I displayed was wrong, I posted a version where I was trying what would UpdateWindow do. Here goes the correct version:
For code use [code] [/code] tags around your code:
[code]
int main(void)...
[/code]
gives:
Code:
int main(void)...
I haven't analyzed your code in any detail, but for double buffering to work, you also need to prevent erasing the background. Override WM_ERASEBKGND (OnEraseBkgnd) and simply return TRUE. This tells the default message handler that you've handled the message yourself and it will forgo any other processing (which would normally include filling the client area with the background color).
See the MFC sample DRAWCLI for a good example of double buffering in a CScrollView class.
Bookmarks