CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2000
    Location
    Islamabad,Pakistan
    Posts
    89

    How to Load Bitmap

    HI!
    i have a problem i want to loadd a bitmap from .bmp file to the views of MDI how to do this.
    Thanks



  2. #2
    Join Date
    Mar 2000
    Location
    Bangalore,India
    Posts
    776

    Re: How to Load Bitmap

    Hi
    i am giving u the sample code to load a bitmap from .bmp file and display it in a CView derived view class.u can put this code in OnDraw() function for test.

    //load the bitmap directly from file
    HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
    "C:\\winnt\\winnt.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

    //attach it to a CBitmap object
    CBitmap bmp;
    if(hBitmap)
    {
    bmp.Attach(hBitmap);
    }
    //get the bitmap header info
    BITMAP bm;
    bmp.GetBitmap(&bm);

    //create a temporary memory DC
    CDC mdc;
    mdc.CreateCompatibleDC(pDC);
    mdc.SelectObject(&bmp);

    //Use CDC::BitBlt() or StretchBlt(); here i have used BitBlt() here
    pDC->BitBlt(0,0,bm.bmWidth,bm.bmHeight,&mdc,0,0,SRCCOPY);
    //delete the temp DC when finished
    mdc.DeleteDC();


    Regards
    S.K.Pradhan


    Be sure to rate answers if it helped, to encourage them.

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