locked
How to set a static control background as a dialog background? RRS feed

Answers

  • I read your post in here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/f54923fa-3e8f-4406-8de6-0d06e3a0aa8b/how-to-set-a-static-control-background-as-a-dialog-background?forum=windowsuidevelopment

    I think the you should not return a NULL_BRUSH in the OnCtlColor function, your dialog will repaint with a NULL_BRUSH, so you get a overlapped text.

    To resolve this issue, I suggest you use a Pattern Brush. Something like this:

    HBRUSH m_hBitmapBrush;

    ..... CBitmap bmp; if (bmp.LoadBitmap(IDB_TEST)) { // Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); m_hBitmapBrush = CreatePatternBrush(bmp); ....

    m_hBitmapBrush is a member of the dialog class or a static variable. And you need to return the Pattern Brush in OnCtlColor function.

    HBRUSH YourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    
    	// TODO:  Change any attributes of the DC here
    	pDC->SetBkMode(TRANSPARENT);
    
    	if(pWnd->GetDlgCtrlID() == IDC_STATIC)
    	{       //      
    
    		pDC->SetBkMode(TRANSPARENT);
    
    		pDC->SetTextColor(RGB(0, 0, 255));
    	}
    
    	return	s_hBitmapBrush;
    	
    }

    Hope this helps some.

    Shu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by amitsalvi007 Tuesday, June 30, 2015 12:07 PM
    • Marked as answer by Shu 2017 Monday, July 6, 2015 9:39 AM
    Monday, June 29, 2015 9:21 AM
  • Thank you very much. However more or less I solved the problem using a RedrawWindow function u can follow it here: My stack profile
    • Edited by BraianStack Thursday, July 2, 2015 3:37 PM
    • Marked as answer by BraianStack Monday, July 6, 2015 9:51 AM
    Thursday, July 2, 2015 3:35 PM

All replies

  • This thread should probably be moved to the "User Interface development for Windows Desktop" forum.

    Although you are using VC++, your question is not really about the language, compiler, or runtime libraries, but rather about the behavior of the underlying Windows API functions for UI.


    Developer Support Engineer

    Saturday, June 27, 2015 1:05 AM
  • I read your post in here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/f54923fa-3e8f-4406-8de6-0d06e3a0aa8b/how-to-set-a-static-control-background-as-a-dialog-background?forum=windowsuidevelopment

    I think the you should not return a NULL_BRUSH in the OnCtlColor function, your dialog will repaint with a NULL_BRUSH, so you get a overlapped text.

    To resolve this issue, I suggest you use a Pattern Brush. Something like this:

    HBRUSH m_hBitmapBrush;

    ..... CBitmap bmp; if (bmp.LoadBitmap(IDB_TEST)) { // Get the size of the bitmap BITMAP bmpInfo; bmp.GetBitmap(&bmpInfo); m_hBitmapBrush = CreatePatternBrush(bmp); ....

    m_hBitmapBrush is a member of the dialog class or a static variable. And you need to return the Pattern Brush in OnCtlColor function.

    HBRUSH YourDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
    	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);
    
    	// TODO:  Change any attributes of the DC here
    	pDC->SetBkMode(TRANSPARENT);
    
    	if(pWnd->GetDlgCtrlID() == IDC_STATIC)
    	{       //      
    
    		pDC->SetBkMode(TRANSPARENT);
    
    		pDC->SetTextColor(RGB(0, 0, 255));
    	}
    
    	return	s_hBitmapBrush;
    	
    }

    Hope this helps some.

    Shu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by amitsalvi007 Tuesday, June 30, 2015 12:07 PM
    • Marked as answer by Shu 2017 Monday, July 6, 2015 9:39 AM
    Monday, June 29, 2015 9:21 AM
  • This is a really good article explaining how to create a control with transparent background:

    http://www.codeproject.com/Articles/9064/Yet-Another-Transparent-Static-Control


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.

    Monday, June 29, 2015 10:14 AM
  • Thank you very much. However more or less I solved the problem using a RedrawWindow function u can follow it here: My stack profile
    • Edited by BraianStack Thursday, July 2, 2015 3:37 PM
    • Marked as answer by BraianStack Monday, July 6, 2015 9:51 AM
    Thursday, July 2, 2015 3:35 PM