G
George Styles
Hi,
I am trying to work out what a block of C++ does, but I am having trouble
understanding the syntax.
I know Delphi well, so am happy with objects etc, its just this syntax I
dont understand.
The code is
void CRipPanel::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC memDc;
if (!memDc.CreateCompatibleDC(&dc)) return;
m_bmpNormal.LoadBitmap(IDB_PANELBITMAP);
HBITMAP m_hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
m_bmpNormal);
dc.BitBlt(0,0,240,80, &memDc, 0,0,SRCCOPY);
::SelectObject(memDc.GetSafeHdc(), m_hOldBitmap);
memDc.DeleteDC();
m_bmpNormal.DeleteObject();
}
I dont understand:
1. CPaintDC dc(this); // device context for painting
CPaintDC is a type right? dc is the instance, but what does the (this) mean
(i know this is the current object, but havnt seen it used in this way
before)
2. I dont understand the line starting :: (
::SelectObject(memDc.GetSafeHdc(), m_hOldBitmap)
What object is that acting on? i have only seen :: in c++ before when
defining methods of a class, not in code like this.
It looks to me like some kind of WITH block.... but I didnt know c++
supported with...
help!
thanks
George
I am trying to work out what a block of C++ does, but I am having trouble
understanding the syntax.
I know Delphi well, so am happy with objects etc, its just this syntax I
dont understand.
The code is
void CRipPanel::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC memDc;
if (!memDc.CreateCompatibleDC(&dc)) return;
m_bmpNormal.LoadBitmap(IDB_PANELBITMAP);
HBITMAP m_hOldBitmap = (HBITMAP)::SelectObject(memDc.GetSafeHdc(),
m_bmpNormal);
dc.BitBlt(0,0,240,80, &memDc, 0,0,SRCCOPY);
::SelectObject(memDc.GetSafeHdc(), m_hOldBitmap);
memDc.DeleteDC();
m_bmpNormal.DeleteObject();
}
I dont understand:
1. CPaintDC dc(this); // device context for painting
CPaintDC is a type right? dc is the instance, but what does the (this) mean
(i know this is the current object, but havnt seen it used in this way
before)
2. I dont understand the line starting :: (
::SelectObject(memDc.GetSafeHdc(), m_hOldBitmap)
What object is that acting on? i have only seen :: in c++ before when
defining methods of a class, not in code like this.
It looks to me like some kind of WITH block.... but I didnt know c++
supported with...
help!
thanks
George