CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: c++

  1. #1
    Guest

    c++

    Im just wondering if anyone can tell me what API or function I would use to load a bitmap into a DC using Borland C++ 4.52, I don't own visual c++ but I figured someone would know.. thanks.
    -Dave


  2. #2
    Join Date
    Jun 1999
    Location
    Washington
    Posts
    32

    Re: c++

    This is all Win32 API This code loads a bitmap from a file into a HBITMAP then into a DC and then Stretches it to fit the window of a control in your dialog that you are displaying it to.

    Hope it helps.


    HDC hPhotoWndDC;
    HDC hCompatDC;
    HWND hPhotoWnd;

    m_hCurrentBmp = (HBITMAP)::LoadImageW(NULL, bstrFileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
    if (m_hCurrentBmp != NULL)
    {
    hPhotoWnd = ::GetDlgItem(hWnd, uCtrl);
    if (hPhotoWnd != NULL)
    {
    hPhotoWndDC = ::GetDC(hPhotoWnd);
    if (hPhotoWndDC != NULL)
    {
    hCompatDC = ::CreateCompatibleDC(hPhotoWndDC);
    if (hCompatDC != NULL)
    {
    RECT rect;
    ::GetClientRect(hPhotoWnd, &rect);
    HBITMAP oldBitmap = (HBITMAP)::SelectObject(hCompatDC, m_hCurrentBmp);
    BITMAP bm;
    ::GetObject( m_hCurrentBmp, sizeof( bm ), &bm );
    ::StretchBlt(hPhotoWndDC, 0, 0, rect.right - rect.left, rect.bottom - rect.top, hCompatDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
    ::SelectObject(hCompatDC, oldBitmap);
    ::ReleaseDC(hPhotoWnd, hCompatDC);
    hr = S_OK;
    }
    ::ReleaseDC(hPhotoWnd, hPhotoWndDC);
    }
    }
    }







  3. #3
    Join Date
    Apr 1999
    Location
    Finland
    Posts
    68

    Re: c++

    // This should give you a clue how to do it
    bool BitmapToDC(char *szImage)
    {
    // Try loading the image.
    HBITMAP hbm = (HBITMAP)LoadImage(NULL, szImage, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);

    if (hbm == NULL)
    return false;

    HDC hdcImage = CreateCompatibleDC(NULL);
    SelectObject(hdcImage, hbm);

    // if you need to draw the image on some window use GetDC and BitBlt (and ReleaseDC)

    if (hdc)
    DeleteDC(hdc);
    if (hbm)
    DeleteObject(hbm);
    return true;
    }


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