Hi all,
I use a dialog in MFC to load and show a bmp successfully, I use a picture control , now I want to mark part of the bmp with red color with the following code:
Code:
CWnd *pWnd=GetDlgItem(IDC_STATIC1);
CRect rect;
pWnd->GetClientRect(&rect);
CClientDC dcImage1(pWnd);
COLORREF col=RGB(255,0,0);
for( int i = 200; i < 300; i++)
for(int j = 200; j < 300; j++)
dcImage1.SetPixel(i,j,col);
pWnd->InvalidateRect(&rect);
the red part disappeared at once as the bmp was loaded, I just can not make the bmp and the red part I marked show at the same time, can anyone help me with this ,thank you very much,
the following is part of my code to load the bmp:
Code:
m_st1.GetClientRect( &rectStaticClient ); // define a variable of the picture control: CStatic m_st1
...
m_st1.ClientToScreen( &rectStaticClient );
ScreenToClient( &rectStaticClient);
...
GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo );
...
InvalidateRect(&rectStaticClient);
Last edited by Angela2010; November 5th, 2011 at 08:39 PM.
You need to draw both bitmap and rectangle in static control WM_PAINT event handler. In MFC the best way to do this is to write CStatic-derived class and implement drawing code there.
Write your own class derived from CStatic. In its WM_PAINT message handler draw bitmap, and then red overlay over it. There are several ways to draw bitmap, for example, you can use StretchDIBits function.
To use this class, create CStatic dialog member variable with MFC Class Wizard, and replace CStatic type with your own class.
Bookmarks