CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2011
    Posts
    21

    Question show a bitmap in MFC

    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.

  2. #2
    Join Date
    Jul 2002
    Posts
    2,543

    Re: show a bitmap in MFC

    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.

  3. #3
    Join Date
    Aug 2011
    Posts
    21

    Smile Re: show a bitmap in MFC

    I'm sorry ,I am new to this field ,I did not understand you clear, could you please explain it in detail,thank you !

  4. #4
    Join Date
    Jul 2002
    Posts
    2,543

    Re: show a bitmap in MFC

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured