Drawing a text over a picture control
-
Hi, I added a picture control to my form and choose the BitMap type and loaded a bitmap into that control. Now I need to draw text over that bitmap. The problem is that the text is being drawn behind that bitmap and not above it(therefor - I can't see the text). I use the following peace of code :
HBRUSH Frm_WkAtol::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here CRect rect; CRgn rgn; switch(pWnd->GetDlgCtrlID()) { case IDC\_ATOL\_CORRIDOR\_BITMAP: { CRect TextRect; CDC \*pLabelDC = m\_AtolCorridorBitmap.GetDC(); m\_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; pLabelDC->DrawText(\_T("Test") , &TextRect , DT\_CENTER); ReleaseDC(pLabelDC); } break; } return hbr;
}
Note - if I change the type of the picture control to a Rectangle,I can see the text. Doe's it mean that I need to draw the Bitmap by myself??? With best regards, Eli
-
Hi, I added a picture control to my form and choose the BitMap type and loaded a bitmap into that control. Now I need to draw text over that bitmap. The problem is that the text is being drawn behind that bitmap and not above it(therefor - I can't see the text). I use the following peace of code :
HBRUSH Frm_WkAtol::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here CRect rect; CRgn rgn; switch(pWnd->GetDlgCtrlID()) { case IDC\_ATOL\_CORRIDOR\_BITMAP: { CRect TextRect; CDC \*pLabelDC = m\_AtolCorridorBitmap.GetDC(); m\_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; pLabelDC->DrawText(\_T("Test") , &TextRect , DT\_CENTER); ReleaseDC(pLabelDC); } break; } return hbr;
}
Note - if I change the type of the picture control to a Rectangle,I can see the text. Doe's it mean that I need to draw the Bitmap by myself??? With best regards, Eli
Hi Just a guess
CCleintDC dc(this) CRect TextRect; m_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; dc.DrawText(_T("Test") , &TextRect , DT_CENTER);
RegardsThe Best Religion is Science. Once you understand it, you will know God.
-
Hi, I added a picture control to my form and choose the BitMap type and loaded a bitmap into that control. Now I need to draw text over that bitmap. The problem is that the text is being drawn behind that bitmap and not above it(therefor - I can't see the text). I use the following peace of code :
HBRUSH Frm_WkAtol::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here CRect rect; CRgn rgn; switch(pWnd->GetDlgCtrlID()) { case IDC\_ATOL\_CORRIDOR\_BITMAP: { CRect TextRect; CDC \*pLabelDC = m\_AtolCorridorBitmap.GetDC(); m\_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; pLabelDC->DrawText(\_T("Test") , &TextRect , DT\_CENTER); ReleaseDC(pLabelDC); } break; } return hbr;
}
Note - if I change the type of the picture control to a Rectangle,I can see the text. Doe's it mean that I need to draw the Bitmap by myself??? With best regards, Eli
OnCtlColor() is called before the control draws itself so if you draw text there it will be drawn "under" the control, as you are seeing. You could derive your own picture box class from CStatic and make your m_AtolCorridorBitmap a variable of that type. add a WM_PAINT handler to the class. In the OnPaint() implementation, after calling the base class' OnPaint(), draw your text in the client area of the picture box. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
-
Hi, I added a picture control to my form and choose the BitMap type and loaded a bitmap into that control. Now I need to draw text over that bitmap. The problem is that the text is being drawn behind that bitmap and not above it(therefor - I can't see the text). I use the following peace of code :
HBRUSH Frm_WkAtol::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here CRect rect; CRgn rgn; switch(pWnd->GetDlgCtrlID()) { case IDC\_ATOL\_CORRIDOR\_BITMAP: { CRect TextRect; CDC \*pLabelDC = m\_AtolCorridorBitmap.GetDC(); m\_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; pLabelDC->DrawText(\_T("Test") , &TextRect , DT\_CENTER); ReleaseDC(pLabelDC); } break; } return hbr;
}
Note - if I change the type of the picture control to a Rectangle,I can see the text. Doe's it mean that I need to draw the Bitmap by myself??? With best regards, Eli
-
Hi, I added a picture control to my form and choose the BitMap type and loaded a bitmap into that control. Now I need to draw text over that bitmap. The problem is that the text is being drawn behind that bitmap and not above it(therefor - I can't see the text). I use the following peace of code :
HBRUSH Frm_WkAtol::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);// TODO: Change any attributes of the DC here CRect rect; CRgn rgn; switch(pWnd->GetDlgCtrlID()) { case IDC\_ATOL\_CORRIDOR\_BITMAP: { CRect TextRect; CDC \*pLabelDC = m\_AtolCorridorBitmap.GetDC(); m\_AtolCorridorBitmap.GetClientRect(&rect); TextRect = rect; TextRect.top = rect.top + 10; TextRect.bottom = TextRect.top + 25; TextRect.left = rect.left + 25; TextRect.right = rect.right - 25; pLabelDC->DrawText(\_T("Test") , &TextRect , DT\_CENTER); ReleaseDC(pLabelDC); } break; } return hbr;
}
Note - if I change the type of the picture control to a Rectangle,I can see the text. Doe's it mean that I need to draw the Bitmap by myself??? With best regards, Eli
Did you try on the
WM_PAINT or WM_ERASEBKGND
whats result?
WhiteSky
-
You must insert a static control of Toolbox and set bitmap property on the property of control and use of SetBitmap() for insert image file to this control.
WhiteSky
-
OnCtlColor() is called before the control draws itself so if you draw text there it will be drawn "under" the control, as you are seeing. You could derive your own picture box class from CStatic and make your m_AtolCorridorBitmap a variable of that type. add a WM_PAINT handler to the class. In the OnPaint() implementation, after calling the base class' OnPaint(), draw your text in the client area of the picture box. Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
Hi Mark, Thanks for your detailed explanation.
Mark Salsbery wrote:
OnCtlColor() is called before the control draws itself so if you draw text there it will be drawn "under" the control, as you are seeing.
I didn't knew that....:doh:(do you know where can I find a tutorial about the messages and windows events sequence?)
Mark Salsbery wrote:
You could derive your own picture box class from CStatic and make your m_AtolCorridorBitmap a variable of that type. add a WM_PAINT handler to the class. In the OnPaint() implementation, after calling the base class' OnPaint(), draw your text in the client area of the picture box.
This is just what I'm going to try.... Just one more question: In design time I can attach a bitmap resource to the picture control. How can I do it during run time(should I draw the bitmap by myself,or maybe attach the bitmap in design time and only change the declaration of that control , i.e will it save the properties I gave it in design time??) Thanks again, Eli
-
Hi Mark, Thanks for your detailed explanation.
Mark Salsbery wrote:
OnCtlColor() is called before the control draws itself so if you draw text there it will be drawn "under" the control, as you are seeing.
I didn't knew that....:doh:(do you know where can I find a tutorial about the messages and windows events sequence?)
Mark Salsbery wrote:
You could derive your own picture box class from CStatic and make your m_AtolCorridorBitmap a variable of that type. add a WM_PAINT handler to the class. In the OnPaint() implementation, after calling the base class' OnPaint(), draw your text in the client area of the picture box.
This is just what I'm going to try.... Just one more question: In design time I can attach a bitmap resource to the picture control. How can I do it during run time(should I draw the bitmap by myself,or maybe attach the bitmap in design time and only change the declaration of that control , i.e will it save the properties I gave it in design time??) Thanks again, Eli
eli15021979 wrote:
How can I do it during run time(should I draw the bitmap by myself,or maybe attach the bitmap in design time and only change the declaration of that control ,
You can use the CStatic::SetBitmap() method to set the control's bitmap. You'll need the bitmap to set, and how you get that depends on where it is. If it's a resource, the CBitmap class' CBitmap::LoadBitmap() method or the Image::LoadFromResource() method will do it. If it's a JPEG, GIF, BMP, or PNG file, you could use CImage::Load().
eli15021979 wrote:
do you know where can I find a tutorial about the messages and windows events sequence?)
I wish I had specific links but I don't, sorry :) The book "Programming Windows" by Charles Petzold is a classic text for Windows fundamentals. The Platform SDK has details on every Windows message. For example, the WM_CTLCOLORxxx messages state "is sent to the parent window of a button before drawing the button". Cheers! :) Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder