VC++ WM_PAINT

Started by
1 comment, last by TwisteR 22 years, 8 months ago
Hi...I am making a painting program and I want there to be a line drawn on the screen without the user having to do so.. the code i have so far is: MoveTo(100,200); LineTo(200,200); it is in the C___View::Draw(CDC *pDC) function.. How do i override WM_PAINT for this to work??? Thank you. ----------------------------- -------Mitch Mulholland------ ----A.K.A.= TwisteR---------- -----------------------------
------------------------------------Mitch Mulholland----------A.K.A.= TwisteR---------------------------------------
Advertisement
With MFC you don''t handle the WM_PAINT message. Just put your drawing code in the OnDraw methoed of the CView class.

ECKILLER
Well, sort of true.

Assuming you''re using MFC, you have to map the messages properly. Usually the way to do this is to just use the class wizard, but since you apparenly haven''t, here''s how to do it manually:

declare OnDraw as follows in your CView header:
virtual void OnDraw(CDC* pDC);

Place this in your message map (between BEGIN_MESSAGE_MAP(...) and END_MESSAGE_MAP())
ON_WM_PAINT()

Implement OnDraw as follows:
void C___View::OnDraw( CDC * pDC )

Without the ON_WM_PAINT in the message map your OnDraw will never get called. Yes, you have to call it OnDraw. No, the message map isn''t really C++, it''s sort of a script to set up the winproc that MFC does automagically for you.

-fel
~ The opinions stated by this individual are the opinions of this individual and not the opinions of her company, any organization she might be part of, her parrot, or anyone else. ~

This topic is closed to new replies.

Advertisement