Discussion:
how to draw a bitmap on the Static control?
(too old to reply)
kathy
2006-03-22 23:26:27 UTC
Permalink
My dialog has a Static control. I have a bitmap and want to draw it in
the Static control when dialog pop up. I implement DrawBitmap() and
called it in OnInitDialog().

MyDialog::OnInitDialog()
{
...
DrawBitmap();
}

MyDialog::DrawBitmap()
{
HWND hWnd = 0;
HDC hDC = 0;
INT nCx = 0,nCy = 0,nY = 0;
RECT stCR ={0};

CClientDC dc(this); // device context for painting

hWnd = ::GetDlgItem(this->m_hWnd,IDC_STATIC_IMAGE);
::GetClientRect(hWnd,&stCR);
nCx = stCR.right - stCR.left;
nCy = stCR.bottom - stCR.top;
hDC = ::GetDC(hWnd);

StretchDIBits(hDC,stCR.left,stCR.top,nCx,nCy,0,0,m_nCameraCX,m_nCameraCY,m_pstBytes,m_pstBMI,DIB_RGB_COLORS,SRCCOPY);
}

But I can not see the bitmap. Even I put it in the OnPaint(). I still
can not see it.

If I add timer and add it in OnPaint() and called it in OnTimer(). I
can see it. why?
Tom Serface
2006-03-22 23:42:14 UTC
Permalink
I use this class and it works really well.

Tom

http://msdn.microsoft.com/msdnmag/issues/01/10/c/
Post by kathy
My dialog has a Static control. I have a bitmap and want to draw it in
the Static control when dialog pop up. I implement DrawBitmap() and
called it in OnInitDialog().
MyDialog::OnInitDialog()
{
...
DrawBitmap();
}
MyDialog::DrawBitmap()
{
HWND hWnd = 0;
HDC hDC = 0;
INT nCx = 0,nCy = 0,nY = 0;
RECT stCR ={0};
CClientDC dc(this); // device context for painting
hWnd = ::GetDlgItem(this->m_hWnd,IDC_STATIC_IMAGE);
::GetClientRect(hWnd,&stCR);
nCx = stCR.right - stCR.left;
nCy = stCR.bottom - stCR.top;
hDC = ::GetDC(hWnd);
StretchDIBits(hDC,stCR.left,stCR.top,nCx,nCy,0,0,m_nCameraCX,m_nCameraCY,m_pstBytes,m_pstBMI,DIB_RGB_COLORS,SRCCOPY);
}
But I can not see the bitmap. Even I put it in the OnPaint(). I still
can not see it.
If I add timer and add it in OnPaint() and called it in OnTimer(). I
can see it. why?
Ajay Kalra
2006-03-23 00:03:36 UTC
Permalink
Post by kathy
My dialog has a Static control. I have a bitmap and want to draw it in
the Static control when dialog pop up. I implement DrawBitmap()....
Why not use CStatic::SetBitmap() instead of drawing it?

--
Ajay Kalra [MVP - VC++]
***@yahoo.com
Scott McPhillips [MVP]
2006-03-23 00:06:29 UTC
Permalink
Post by kathy
My dialog has a Static control. I have a bitmap and want to draw it in
the Static control when dialog pop up. I implement DrawBitmap() and
called it in OnInitDialog().
MyDialog::OnInitDialog()
{
...
DrawBitmap();
}
MyDialog::DrawBitmap()
{
HWND hWnd = 0;
HDC hDC = 0;
INT nCx = 0,nCy = 0,nY = 0;
RECT stCR ={0};
CClientDC dc(this); // device context for painting
hWnd = ::GetDlgItem(this->m_hWnd,IDC_STATIC_IMAGE);
::GetClientRect(hWnd,&stCR);
nCx = stCR.right - stCR.left;
nCy = stCR.bottom - stCR.top;
hDC = ::GetDC(hWnd);
StretchDIBits(hDC,stCR.left,stCR.top,nCx,nCy,0,0,m_nCameraCX,m_nCameraCY,m_pstBytes,m_pstBMI,DIB_RGB_COLORS,SRCCOPY);
}
But I can not see the bitmap. Even I put it in the OnPaint(). I still
can not see it.
If I add timer and add it in OnPaint() and called it in OnTimer(). I
can see it. why?
CStatic is a child window on your dialog, with its own OnPaint handler.
You should be drawing in the CStatic OnPaint, not the dialog OnPaint.
As you have it now the CStatic is still doing its own painting, and
your painting is going underneath the CStatic.
--
Scott McPhillips [VC++ MVP]
kathy
2006-03-23 17:38:46 UTC
Permalink
I have created a custom Static control and move drawing code to Static
control's OnPaint().

Now it show the bitmap now when dialog start.

But when I switch to another window and then come back. Nothing on the
dialog - no bitmap on Static control, even no other controls show
up(other buttons, etc.)

What I missed?
kathy
2006-03-23 19:29:37 UTC
Permalink
I solved the problem.
Ajay Kalra
2006-03-23 20:11:49 UTC
Permalink
What was the fix? Was it the Z-order issue?

--------
Ajay Kalra
***@yahoo.com

Loading...