Hi all,
I'm trying to port my code framework over to be MFC compatible so I can make editors for various programs, and for myself.
It all works great except for this small, barely significant problem that nothing draws at all.
Right now, I'm trying to just draw a black rectangle using GDI in the document window, so I've got this cool code:
Pretty straightforward, I thought, except for the cuteness of taking 60 lines to draw a simple rectangle in GDI. Anyway... no black rectangle! C'mon, this should be pretty easy, right? In the OnDraw, I do a BeginPaint, get the DC and fill a rect.Code:void CEditorView::OnDraw(CDC* /*pDC*/) { CEditorDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CPaintDC dc(this); // device context for painting PAINTSTRUCT aPaint; BeginPaint(&aPaint); CBrush aBrush; aBrush.CreateSolidBrush(COLORREF(RGB(0,0,0))); CRect aRect; aRect.left=0; aRect.top=0; aRect.right=100; aRect.bottom=100; dc.FillRect(&aRect,&aBrush); EndPaint(&aPaint); // TODO: add draw code for native data here }
At random I've also:
o Removed the BeginPaint/EndPaint commands
o Tried using the base FillRect and passing it a pointer to the DC
o Moved everything into OnPaint instead of OnDraw
And I always get a nice white clean document with nothing in it whatsoever.
Are any of you man enough to tell me what I'm doing wrong?
Thanks a skillion!


Reply With Quote
only OnPaint needs for you to create a dc, but all code in this thread should work, find if the function is even being called is the first step, OnSize (resize window) or invalidating manually should force a call as Sharkbait said. IIRC you can get the mfc wizard to create a basic hello world app which creates a window and draws some text using a similar method.. also what is CEditorView derived from ?

