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

    Arrow what s the problem with my code?

    hi guys:
    everbody knows how to displaying a bitmap to screen.we just need a memory dc and a display dc. and i try to simulate this on OnPaint and it failed to work. anyone knows why? plz . ty so much

    CXXX::OnPaint()
    {
    CPaintDC dc(this);//default code

    CDC memdc;
    memdc.CreateCompatibleDC(&dc);

    memdc.TextOut(0,0,"hello");

    dc.BitBlt(0,0,100,30,&memdc,0,0,SRCCOPY);

    }


    have a nice day

  2. #2
    Join Date
    Apr 2006
    Posts
    46

    Re: what s the problem with my code?

    CPaintDC dc(this);//default code

    CDC memdc;
    CBitmap bmp;

    CRect rc;
    GetClientRect(&rc);

    bmp.CreateCompatibleBitmap(&dc,rc.Width(),rc.Height());

    memdc.CreateCompatibleDC(&dc);
    memdc.SelectObject(&bmp);
    memdc.FillRect(&rc,&CBrush(RGB(255,255,255)));
    memdc.TextOut(0,0,"hello");

    dc.BitBlt(0,0,100,30,&memdc,0,0,SRCCOPY);

  3. #3
    Join Date
    Apr 2006
    Posts
    46

    Re: what s the problem with my code?

    PS:if necessary, you can store the the Old bitmap object of the memdc when selecting the new bitmap:

    CBitmap *pOldBmp = memdc.SelectObject(&bmp);

    then at the last steps you can recover it:

    memdc.SelectObject(pOldBmp);

  4. #4
    Join Date
    Jan 2005
    Posts
    73

    Resolved Re: what s the problem with my code?

    thanks wisby

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