Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3046

[RESOLVED] Issues drawing background bitmap in edit box common control

$
0
0
I was trying to subclass common-control's edit box to display a custom background bitmap.

The brush for drawing is created as such:

Code:

CBitmap bmp1;
CBrush brush1;

VERIFY(bmp1.LoadBitmap(IDB_BITMAP1));
VERIFY(brush1.CreatePatternBrush(&bmp1));

Then I override OnCtlColor():

Code:

HBRUSH CMyDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
        HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

        // TODO:  Change any attributes of the DC here
        if(pWnd->GetDlgCtrlID() == edt1.GetDlgCtrlID())
        {
                //Use special brush
                hbr = edt1.brush1;

                pDC->SetBkMode(TRANSPARENT);
        }

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

This works but only if I set ES_MULTILINE style for the edit box. For a single line control when I move it quickly off the screen and then back it creates this visual artifact.

I made a small MFC app to illustrate the issue. This is a screenshot of what happens:

Name:  ask_img.png
Views: 53
Size:  2.1 KB

So what am I doing wrong?


PS. I tried to override OnEraseBkgnd() to redraw background there (see my sample project) using FillRect() but it still didn't fix the issue.
Attached Images
 
Attached Files

Viewing all articles
Browse latest Browse all 3046

Trending Articles