Keeping track of fonts, pens, device contexts, etc.
-
I wrote a program which includes these declarations:-
class PEN{public: HDC d; HPEN pen,old;
PEN(HDC dc,COLORREF col);
~PEN();};/*-----*/ /* the device context dc must still exist when the pen is deleted */
PEN::PEN(HDC dc,COLORREF col){ // constructor
d=dc;
pen=(HPEN)CreatePen(0,1,col);
old=(HPEN)SelectObject(dc,pen);};
PEN::~PEN(){ // destructor
SelectObject(d,old);
DeleteObject(pen);};/*-----*/ // then I can write for example:- /*-----*/
if(xhairs) {
PEN orange(WIdc,RGB(255,128,0)); // crosshairs
Line(WIdc,0,b/2,(int)(2*a),(int)(b/2));
Line(WIdc,(int)(a/2),0,(int)(a/2),b);
Line(WIdc,(int)(a*1.5),0,(int)(a*1.5),b);}/*-----*/ and the new pen is automatically cleared away when control leaves the block where the pen was declared. And similarly with fonts etc.
-
I wrote a program which includes these declarations:-
class PEN{public: HDC d; HPEN pen,old;
PEN(HDC dc,COLORREF col);
~PEN();};/*-----*/ /* the device context dc must still exist when the pen is deleted */
PEN::PEN(HDC dc,COLORREF col){ // constructor
d=dc;
pen=(HPEN)CreatePen(0,1,col);
old=(HPEN)SelectObject(dc,pen);};
PEN::~PEN(){ // destructor
SelectObject(d,old);
DeleteObject(pen);};/*-----*/ // then I can write for example:- /*-----*/
if(xhairs) {
PEN orange(WIdc,RGB(255,128,0)); // crosshairs
Line(WIdc,0,b/2,(int)(2*a),(int)(b/2));
Line(WIdc,(int)(a/2),0,(int)(a/2),b);
Line(WIdc,(int)(a*1.5),0,(int)(a*1.5),b);}/*-----*/ and the new pen is automatically cleared away when control leaves the block where the pen was declared. And similarly with fonts etc.
And your question is?
The difficult we do right away... ...the impossible takes slightly longer.
-
And your question is?
The difficult we do right away... ...the impossible takes slightly longer.
Is this class declaration likely to be any use to any of you?
-
Is this class declaration likely to be any use to any of you?