Amost correct...
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in
message news:d142q554dl8oevri4hs3cim536l0gki78c@4ax.com...
See below...
On Tue, 16 Mar 2010 07:54:20 -0500, "Peter Olcott"
<NoSpam@OCR4Screen.com> wrote:
"Joseph M. Newcomer" <newcomer@flounder.com> wrote in
message
news:hoetp55bqv7f9lm31e1rr5dgv41tk0rjde@4ax.com...
What part of "use RestoreDC()" did you miss? If you
simply RestoreDC() when you are done
with the font, you will revert to whatever the default
font was. Not a big deal. The
other common practice is to note that if you do
SelectObject() of a font, the result is a
CFont * that had been selected and you simply
re-selecte
this. This technique generalizes
to all 30 or so parameters of an HDC (changing a
parameter
returns you the prvious
setting) but this means you have to keep variables
around
to know what value to
re-selected, and I find RestoreDC() to be a simpler
apprroach.
joe
Its not just Font its also CBitmap, and there is no
default
bitmap to restore.
***
Have you not been paying attention? THere is ALWAYS a
bitmap to restore, and it is the
one that is returned by SelectObject of the bitmap, OR
the
one that is restored when you
call RestoreDC, which is a 1x1 monochrome bitmap. But
you
didn't have to know about the
1x1 bitmap, just read about SelectObject OR about
RestoreDC, both of which state
explicitly what is going to happen! Your mistaken
believe
that there is no default bitmap
is the heart of the problem, and it means you have
ignored
everything we have been telling
you! If you ask questions in this forum and get
answers,
you should pay attention to them
instead of insisting that it works differently than we
are
telling you.
****
//
// Displays a Font Selection DialogBox with
// default "Times New Roman", Bold, Italic, 8 Point
//
inline void ScreenCaptureType::SelectFont() {
int PointSize = 8;
int FontHeight = -MulDiv(PointSize,
GetDeviceCaps(MemoryDC.m_hDC, LOGPIXELSY), 72);
LOGFONT LogFont = {FontHeight, 0, 0, 0, FW_BOLD, 1, 0,
0,
ANSI_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, L"Times New Roman"};
CFontDialog dlg(&LogFont);
CFont tempfont;
CFont *OldFont;
tempfont.CreateFontIndirect(&LogFont);
OldFont = this->MemoryDC.SelectObject(&tempfont);
OldFont->DeleteObject();
if (dlg.DoModal() == IDOK)
this->cfont.CreateFontIndirect(&LogFont);
this->MemoryDC.SelectObject(&cfont);
}
So basically the messy little five line block of code in
the
middle is the cleanest way to implement my functional
requirements within the requirements of MS Windows
resource
management?
A simpler way that could possibly work would be:
Get rid of the five line block and replace the last line
with these two lines:
CFont* OldFont = this->MemoryDC.SelectObject(&cfont);