Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Display DIB when I have its handle (HBITMAP)

Display DIB when I have its handle (HBITMAP)

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    ninck
    wrote on last edited by
    #1

    What's the easiest way to display a DIB when I have its handle which is a HBITMAP ? I found some functions which display it (the DIB) but for those I need some parameters which I don't have. I need a function, or member function of some class which would display it taking as argument the handle to the DIB (the HBITMAP), and the position .

    F 1 Reply Last reply
    0
    • N ninck

      What's the easiest way to display a DIB when I have its handle which is a HBITMAP ? I found some functions which display it (the DIB) but for those I need some parameters which I don't have. I need a function, or member function of some class which would display it taking as argument the handle to the DIB (the HBITMAP), and the position .

      F Offline
      F Offline
      Flit
      wrote on last edited by
      #2

      Create a memory device context and then select the bitmap into it using SelectObject. You can then use BitBlt to copy it to the DC of your window to display it. Have a look at the Windows GDI section of MSDN, that might help.

      N 1 Reply Last reply
      0
      • F Flit

        Create a memory device context and then select the bitmap into it using SelectObject. You can then use BitBlt to copy it to the DC of your window to display it. Have a look at the Windows GDI section of MSDN, that might help.

        N Offline
        N Offline
        ninck
        wrote on last edited by
        #3

        Well that's what I did ,basically . As you can see bellow I also have a function which makes my DIB from a DDB(the funnction is ConvertToDIB).I called this function before the SelectObject call .I don't know why I can't display the DIB (I see a white window when I try to open an image). I transformed the DDB into DIB so I can modify it (for now I don't know how to modify it , but I just want to display it first ).Here's the code : void CDoiView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CSize sizeTotal; sizeTotal.cx = sizeTotal.cy = 0; CleanUp(); CDoiDoc* pDoc = GetDocument(); CString strPath = pDoc->GetPathName(); if (!strPath.IsEmpty()) m_handlerToBMP = GetBitmapFromFile(strPath); if (m_handlerToBMP){ GetBitmapDimensionEx(m_handlerToBMP, &sizeTotal); } SetScrollSizes(MM_TEXT, sizeTotal); CDC* pDC=GetDC(); HDC hMemDC; hMemDC=CreateCompatibleDC(pDC->GetSafeHdc()); if (hMemDC) { if (m_handlerToBMP){ bool aa; if ( (aa=ConvertToDIB(m_handlerToBMP))==false ) { AfxMessageBox("eroare ConvertToDIB");} // select new bitmap into memory DC HBITMAP hOldBitmap = (HBITMAP)SelectObject(hMemDC, m_handlerToBMP); //alocam memorie pentru tabloul ce contine informatia despre culoarea pixelilor GetBitmapDimensionEx(m_handlerToBMP, &sizeTotal); //transfer din memorie in fereastra ::BitBlt(pDC->GetSafeHdc(),0,0,sizeTotal.cx,sizeTotal.cy,hMemDC,0,0,SRCCOPY); // select old bitmap back into memory DC and get handle to bitmap SelectObject(hMemDC, hOldBitmap); DeleteObject(hOldBitmap); DeleteDC(hMemDC); } Invalidate(); UpdateWindow(); } }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups