15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


TRANSPARENT TEXT?

Antonio Jorge Marques Pires -- AntonioPires@mail.telepac.pt
Wednesday, December 04, 1996

Environment: VC++ 4.2b, Win 95

I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
background.

Why "m_strProgName" background is allways grey?

My code: 

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	CString rString;
	if (nCtlColor == CTLCOLOR_STATIC) {
		//pDC->SetTextColor( RGB(0,0,255) );

		pWnd->GetWindowText(rString );
		if (rString == m_strProgName) {
		//	if (pWnd == GetDlgItem(IDC_PROGNAME))
			//OnEraseBkgnd( pDC );

			pDC->SetBkMode(TRANSPARENT);
			//pDC->SetBkMode(OPAQUE);
			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));

			pDC->SetTextColor( RGB(255, 0, 0) );

		}
	}

	// TODO: Return a different brush if the default is not desired
	return hbr;
}

BOOL CAboutDlg::OnEraseBkgnd( CDC* pDC ) {

	CDialog::OnEraseBkgnd(pDC);

	CBitmap bm;
	bm.LoadBitmap(_T("AboutBitmap"));
	BITMAP BM;
	bm.GetObject(sizeof(BITMAP), &BM);
	
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CBitmap* pOld = memDC.SelectObject(&bm);
	
	if (pOld == NULL)
		return 0;     // destructors will clean up

	CWnd* pidWnd = GetDlgItem(IDC_BMPFRAME);
	ASSERT(pidWnd);
	CRect bmpRect;
	pidWnd->GetWindowRect(&bmpRect);
	ScreenToClient(&bmpRect);

	pDC->StretchBlt(bmpRect.left, bmpRect.top, 
				bmpRect.right-bmpRect.left, bmpRect.bottom-bmpRect.top, 
				&memDC, 
				0, 0, BM.bmWidth, BM.bmHeight, 
				SRCCOPY);
	memDC.SelectObject(pOld);

	return TRUE;
}




Spencer Jones -- Spencer@azure.com
Friday, December 06, 1996

[Mini-digest: 5 responses]

Try changing the background colour to be NULL. This should give the
desired effect.


Spencer Jones
Chief Software Developer
Azure Limited
E-Mail (spencer@azure.com)
Web Page (http://www.azure.com/~spencer)
User Location Service (uls.azure.com)



>----------
>From: 	Antonio Jorge MArques Pires[SMTP:AntonioPires@mail.telepac.pt]
>Sent: 	Wednesday, December 04, 1996 3:12 AM
>To: 	mfc-l@netcom.com
>Subject: 	TRANSPARENT TEXT?
>
>Environment: VC++ 4.2b, Win 95
>
>I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
>background.
>
>Why "m_strProgName" background is allways grey?
>
>My code: 
>
>HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
>{
>	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
>	
>	CString rString;
>	if (nCtlColor == CTLCOLOR_STATIC) {
>		//pDC->SetTextColor( RGB(0,0,255) );
>
>		pWnd->GetWindowText(rString );
>		if (rString == m_strProgName) {
>		//	if (pWnd == GetDlgItem(IDC_PROGNAME))
>			//OnEraseBkgnd( pDC );
>
>			pDC->SetBkMode(TRANSPARENT);
>			//pDC->SetBkMode(OPAQUE);
>			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));
>
>			pDC->SetTextColor( RGB(255, 0, 0) );
>
>		}
>	}
>
>	// TODO: Return a different brush if the default is not desired
>	return hbr;
>}
>
>BOOL CAboutDlg::OnEraseBkgnd( CDC* pDC ) {
>
>	CDialog::OnEraseBkgnd(pDC);
>
>	CBitmap bm;
>	bm.LoadBitmap(_T("AboutBitmap"));
>	BITMAP BM;
>	bm.GetObject(sizeof(BITMAP), &BM);
>	
>	CDC memDC;
>	memDC.CreateCompatibleDC(pDC);
>	CBitmap* pOld = memDC.SelectObject(&bm);
>	
>	if (pOld == NULL)
>		return 0;     // destructors will clean up
>
>	CWnd* pidWnd = GetDlgItem(IDC_BMPFRAME);
>	ASSERT(pidWnd);
>	CRect bmpRect;
>	pidWnd->GetWindowRect(&bmpRect);
>	ScreenToClient(&bmpRect);
>
>	pDC->StretchBlt(bmpRect.left, bmpRect.top, 
>				bmpRect.right-bmpRect.left, bmpRect.bottom-bmpRect.top, 
>				&memDC, 
>				0, 0, BM.bmWidth, BM.bmHeight, 
>				SRCCOPY);
>	memDC.SelectObject(pOld);
>
>	return TRUE;
>}
>
>
-----From: Mao Zhihong 

> Environment: VC++ 4.2b, Win 95

>     I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
>     background.

>     Why "m_strProgName" background is allways grey?

  Maybe your app is CTL3D enabled, some dirty thing in CTL3D cause 
OnCtlColor() has no effect!
  It is simple to get rid of this problem, 
  write your own OnPaint() for your dialog, and draw the transparent 
text yourself! 
			Yours Truly
				Mao Zhihong
-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
      Mao Zhihong ( Robert Mao )  DreamyRainbow Software Studio

      Voc/Fax : 86-25-5408086
      E-Mail  : maozhihong@hotmail.com  mao@seu.edu.cn
      URL     : http://seic3.seu.edu.cn/~mao
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-----From: David Little 

You shouldn't have to worry about OnCtlColor, and in the =
OnEraseBackground, don't call the base class.  If your box can be =
re-sized, you should add an OnSize handler to stretch the bitmap to the =
proper size.

----------
From: 	Antonio Jorge MArques Pires[SMTP:AntonioPires@mail.telepac.pt]
Sent: 	Tuesday, December 03, 1996 9:12 PM
To: 	mfc-l@netcom.com
Subject: 	TRANSPARENT TEXT?

Environment: VC++ 4.2b, Win 95

I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
background.

Why "m_strProgName" background is allways grey?

My code:=20

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)=20
{
	HBRUSH hbr =3D CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
=09
	CString rString;
	if (nCtlColor =3D=3D CTLCOLOR_STATIC) {
		//pDC->SetTextColor( RGB(0,0,255) );

		pWnd->GetWindowText(rString );
		if (rString =3D=3D m_strProgName) {
		//	if (pWnd =3D=3D GetDlgItem(IDC_PROGNAME))
			//OnEraseBkgnd( pDC );

			pDC->SetBkMode(TRANSPARENT);
			//pDC->SetBkMode(OPAQUE);
			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));

			pDC->SetTextColor( RGB(255, 0, 0) );

		}
	}

	// TODO: Return a different brush if the default is not desired
	return hbr;
}

BOOL CAboutDlg::OnEraseBkgnd( CDC* pDC ) {

	CDialog::OnEraseBkgnd(pDC);

	CBitmap bm;
	bm.LoadBitmap(_T("AboutBitmap"));
	BITMAP BM;
	bm.GetObject(sizeof(BITMAP), &BM);
=09
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CBitmap* pOld =3D memDC.SelectObject(&bm);
=09
	if (pOld =3D=3D NULL)
		return 0;     // destructors will clean up

	CWnd* pidWnd =3D GetDlgItem(IDC_BMPFRAME);
	ASSERT(pidWnd);
	CRect bmpRect;
	pidWnd->GetWindowRect(&bmpRect);
	ScreenToClient(&bmpRect);

	pDC->StretchBlt(bmpRect.left, bmpRect.top,=20
				bmpRect.right-bmpRect.left, bmpRect.bottom-bmpRect.top,=20
				&memDC,=20
				0, 0, BM.bmWidth, BM.bmHeight,=20
				SRCCOPY);
	memDC.SelectObject(pOld);

	return TRUE;
}
-----From: "George Pavlou" 

It's always grey because on the OnCtrColor you always return the Dialog's
default brush. Your text is tranparent on the static control, but you
always keep the background of the static control.
You need to return a NULL brush at the end of your condition (rString ==
m_strProgName)
for example: 
return (HBRUSH)GetStockObject(NULL_BRUSH);

Note: SetBkColor is not needed if you have SetBkMode(TRANPARENT)

George

 |--------------------------------------------------------------------------
-----|
   George Pavlou                           Tantalus, Inc.            
   Windows Games Programmer     Key West, FL       
   georgep@tansoft.com                www.mpgn.com 
 |--------------------------------------------------------------------------
-----|
----------
> From: Antonio Jorge MArques Pires 
> To: mfc-l@netcom.com
> Subject: TRANSPARENT TEXT?
> Date: Tuesday, December 03, 1996 10:12 PM
> 
> Environment: VC++ 4.2b, Win 95
> 
> I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
> background.
> 
> Why "m_strProgName" background is allways grey?
> 
> My code: 
> 
> HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
> {
> 	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
> 	
> 	CString rString;
> 	if (nCtlColor == CTLCOLOR_STATIC) {
> 		//pDC->SetTextColor( RGB(0,0,255) );
> 
> 		pWnd->GetWindowText(rString );
> 		if (rString == m_strProgName) {
> 		//	if (pWnd == GetDlgItem(IDC_PROGNAME))
> 			//OnEraseBkgnd( pDC );
> 
> 			pDC->SetBkMode(TRANSPARENT);
> 			//pDC->SetBkMode(OPAQUE);
> 			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));
> 
> 			pDC->SetTextColor( RGB(255, 0, 0) );
> 
> 		}
> 	}
> 
> 	// TODO: Return a different brush if the default is not desired
> 	return hbr;
> }
> 
> BOOL CAboutDlg::OnEraseBkgnd( CDC* pDC ) {
> 
> 	CDialog::OnEraseBkgnd(pDC);
> 
> 	CBitmap bm;
> 	bm.LoadBitmap(_T("AboutBitmap"));
> 	BITMAP BM;
> 	bm.GetObject(sizeof(BITMAP), &BM);
> 	
> 	CDC memDC;
> 	memDC.CreateCompatibleDC(pDC);
> 	CBitmap* pOld = memDC.SelectObject(&bm);
> 	
> 	if (pOld == NULL)
> 		return 0;     // destructors will clean up
> 
> 	CWnd* pidWnd = GetDlgItem(IDC_BMPFRAME);
> 	ASSERT(pidWnd);
> 	CRect bmpRect;
> 	pidWnd->GetWindowRect(&bmpRect);
> 	ScreenToClient(&bmpRect);
> 
> 	pDC->StretchBlt(bmpRect.left, bmpRect.top, 
> 				bmpRect.right-bmpRect.left, bmpRect.bottom-bmpRect.top, 
> 				&memDC, 
> 				0, 0, BM.bmWidth, BM.bmHeight, 
> 				SRCCOPY);
> 	memDC.SelectObject(pOld);
> 
> 	return TRUE;
> }
> 
-----From: Claus Michelsen 

Hi Antonio,

If you set the SS_SIMPLE style in the static label you should have no problem. The background will then not be drawn by the static label.

 
Best regards,
Claus Michelsen



-----Original Message-----
From:	Antonio Jorge MArques Pires [SMTP:AntonioPires@mail.telepac.pt]
Sent:	4. december 1996 04:13
To:	mfc-l@netcom.com
Subject:	TRANSPARENT TEXT?

Environment: VC++ 4.2b, Win 95

I'm trying to put text on a dialog with a bitmap ("AboutBitmap") as
background.

Why "m_strProgName" background is allways grey?

My code: 

HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	CString rString;
	if (nCtlColor == CTLCOLOR_STATIC) {
		//pDC->SetTextColor( RGB(0,0,255) );

		pWnd->GetWindowText(rString );
		if (rString == m_strProgName) {
		//	if (pWnd == GetDlgItem(IDC_PROGNAME))
			//OnEraseBkgnd( pDC );

			pDC->SetBkMode(TRANSPARENT);
			//pDC->SetBkMode(OPAQUE);
			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));

			pDC->SetTextColor( RGB(255, 0, 0) );

		}
	}

	// TODO: Return a different brush if the default is not desired
	return hbr;
}

BOOL CAboutDlg::OnEraseBkgnd( CDC* pDC ) {

	CDialog::OnEraseBkgnd(pDC);

	CBitmap bm;
	bm.LoadBitmap(_T("AboutBitmap"));
	BITMAP BM;
	bm.GetObject(sizeof(BITMAP), &BM);
	
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	CBitmap* pOld = memDC.SelectObject(&bm);
	
	if (pOld == NULL)
		return 0;     // destructors will clean up

	CWnd* pidWnd = GetDlgItem(IDC_BMPFRAME);
	ASSERT(pidWnd);
	CRect bmpRect;
	pidWnd->GetWindowRect(&bmpRect);
	ScreenToClient(&bmpRect);

	pDC->StretchBlt(bmpRect.left, bmpRect.top, 
				bmpRect.right-bmpRect.left, bmpRect.bottom-bmpRect.top, 
				&memDC, 
				0, 0, BM.bmWidth, BM.bmHeight, 
				SRCCOPY);
	memDC.SelectObject(pOld);

	return TRUE;
}



Vijai Singh -- vsingh@m-net.arbornet.org
Monday, December 09, 1996

Dear Jones,
	Apart from what U have done in OnCtlColor U need to send the hbr(HBRUSH)
of the same color which U are setting for the background of static text, ur code
could be something like this


> HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
> {
> 	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
> 	
> 	CString rString;
> 	if (nCtlColor == CTLCOLOR_STATIC) {
> 		//pDC->SetTextColor( RGB(0,0,255) );
> 
> 		pWnd->GetWindowText(rString );
> 		if (rString == m_strProgName) {
> 		//	if (pWnd == GetDlgItem(IDC_PROGNAME))
> 			//OnEraseBkgnd( pDC );
> 
> 			pDC->SetBkMode(TRANSPARENT);
> 			//pDC->SetBkMode(OPAQUE);
> 			pDC->SetBkColor(RGB( 0x00, 0x00, 0xFF ));
> 
> 			pDC->SetTextColor( RGB(255, 0, 0) );

			return (HBRUSH)m_Brush;
			// where m_Brush is either declared   static in this 
			// function or a member of this class

> 
> 		}
> 	}




| Вернуться в корень Архива |