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. LoadBitmap in rectangle

LoadBitmap in rectangle

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
2 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.
  • S Offline
    S Offline
    slah
    wrote on last edited by
    #1

    i am having problem in loading a bitmap in a rectangle contained in a dialogbox. anybody having idea what to do or any sample code

    D 1 Reply Last reply
    0
    • S slah

      i am having problem in loading a bitmap in a rectangle contained in a dialogbox. anybody having idea what to do or any sample code

      D Offline
      D Offline
      Dov Sherman
      wrote on last edited by
      #2

      I generally make a CStatic box with a border and then create a new class which is a child of CStatic. For example, class CBitmapViewBox : public CStatic I add a member variable of type CBitmapViewBox to my main dialog and, in the OnInitDialog() event, I do this... m_BitmapViewBox.SubclassDlgItem(IDC_SBITMAPDISPLAY, this); m_BitmapViewBox.Init(); To load and display the bitmap, I do this... void CBitmapViewBox::OnPaint() { CPaintDC dc(this); // device context for painting CMainViewDlg *pWnd = (CMainViewDlg *)GetParent(); if(pWnd != NULL) { if(m_bValid) { CRect lRect; GetClientRect(lRect); lRect.NormalizeRect(); BITMAP bm; m_BMP.GetBitmap(&bm); CBitmap *pOldBitmap = dcMem.SelectObject(&m_BMP); dc.BitBlt(0, 0, lRect.Width(), lRect.Height(), &dcMem, 0, 0, SRCCOPY); dc.SelectObject(pOldBitmap); } else { dc.DrawText("Not a valid BMP file", -1, lRect, DT_CENTER | DT_VCENTER | DT_WORDBREAK); } } CStatic::OnPaint(); } BOOL CBitmapViewBox::UpdateBMP(LPCTSTR lpszName) { CMainViewDlg *pFrameWnd = (CMainViewDlg *)GetParent(); HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), lpszName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION); m_bValid = TRUE; // Get rid of other bitmap if(m_BMP.DeleteObject()) m_BMP.Detach(); if(!hBitmap) { m_bValid = FALSE; UpdateSize(m_iMaxWidth, m_iMaxHeight); Invalidate(TRUE); return FALSE; } m_bValid = TRUE; m_BMP.Attach(hBitmap); }

      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