Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HDC CDC and Document/View Redrawing

Status
Not open for further replies.

MarcoMB

Programmer
Oct 24, 2006
61
0
0
IT
I'm trying to create a document/view app to draw spline...i use 2 CArray objects to store the control point of the curves and the real points of the curves...can someone explain how redraw the user designed spline when the view is refreshed? And so can someone explain me the real difference between the use of CDC* pDC and HDC & hDC?in other words a pointer to CDC class have what differences with a reference to HDC in drawing functions?
 
Ok, let's talk the fundamentals of GUI programming.

1) Thou shalt calculate in the calculate function and paint in the paint function and never the two shall meet.

2) You may break rule 1) if you know how to use offscreen bitmaps. I explained how to do that elsewhere.

Application to your problem:

1) When the user adds or moves a point, redo your calculations and invalidate the rectangle or region that changes (or the whole window if you're not sure how much changed). Do not draw from this routine! Basically, if you're calling GetDC or any other functions that return a DC, HDC or CDC, just don't.

2) The paint function gets called both by the invalidate function and by user events like bringing a window to the front or changing the size or a zillion other things... Anyhow... a CDC (most likely) or an HDC (less likely but possible) gets passed into that function. Pass that to your function which draws spline based on your CArrays.

A CDC is a MFC class wrapper for an HDC. Basically, there's an HDC variable inside it, plus a bunch of functions to create/maintain/modify it. I don't have the MSDN Library installed on this machine or I could tell you which function to call to get the HDC from a variable of that class.
 
ok thanks for explanation...but what i would like to understand is what the difference between:
1)CDC* pDC;
pDC = GetDC();
and so, pass to functions that accept CDC *pDC parameter the pDC variable that encapsulate the Device Context and his handle or:
2) pass directly to functions pDC->m_hDC the DC handle variable contained in wrapper class CDC, to some functions that accept a HDC hDC parameter...

what the difference between this method?
 
I'd assume
1) the functions that use CDC* pDC parameters are MFC routines which wrap Windows GUI functions
2) the functions that use HDC hDC are Windows GUI functions

If you can give me specific function names, I can look them up on the other computer which has the MSDN library on it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top