Re: LBUTTONDOWN() problem
"neha" <coolcapri85@gmail.com> wrote in message
news:bf503d08-9b53-4000-b6bf-222d2a937f72@y28g2000prd.googlegroups.com...
Hi all,
I have written a piece of code to increment the font size of text
whenever i left click in the client area
void CTextDisplayView::OnLButtonDown(UINT nFlags, CPoint point)
{
CView::OnLButtonDown(nFlags, point);
CString str="Hello";
int x1=point.x;
int y1=point.y;
LOGFONT lf;
HFONT font;
memset(&lf, 0, sizeof(LOGFONT)); // Clear out structure.
lf.lfHeight = x1;
strcpy(lf.lfFaceName, "Comic Sans MS");
font=(HFONT)m_font.CreateFontIndirect(&lf);
CClientDC dc2(this);
dc2.SelectObject(m_font);
dc2.TextOut(x1,y1,str);
::ReleaseDC(m_hWnd,dc2);
}
whenever i execute the application, on first left click it
displays the text with size a the co-ordinate recieved in
lbuttondown's CPoint point argument, but on second button click it
stop the application with error (Debug assertion Failed!).
i want to display text with incremented fontsize on every
leftbutton click.
Please help me out.
You don't need to call ::ReleaseDC() since the CClientDC destructor does
that.
You can eliminate the 'font' variable as it isn't used anywhere.
As Goran says, any text you write onto the client DC will be erased the next
time your window is painted (I.e. OnPaint is called). If you're looking for
a tooltip effect, that's OK but if you want the text to stay there, you need
to write it in the OnPaint handler.
-- David