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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. load multiple image (both photo1 and photo2)

load multiple image (both photo1 and photo2)

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++graphics
4 Posts 3 Posters 2 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.
  • V Offline
    V Offline
    vc programmer 0
    wrote on last edited by
    #1

    every body.... my code is following. my problem is only photo2 is show. i want to show both photo1 and photo2.plz help me... //MyView.h CStatic m_photo1; CStatic m_photo2; HBITMAP m_hBmpOld; HBITMAP m_hBmpNew; BITMAP m_bmInfo; //MyView.cpp void CMyView::OnOK() { Load_Photo_1("image/1.bmp"); Load_Photo_2("image/2.bmp"); } void CMyView::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); dc.BitBlt(offsetx,offsety,m_size.cx,m_size.cy, &m_dcMem, sourcex, sourcey,SRCCOPY); CFormView::OnPaint(); } } void CMyView::OnInitialUpdate() { CClientDC dc(this); m_dcMem.CreateCompatibleDC( &dc ); } void CMyView::Load_Photo_1(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); // zero based m_size.cy = rectStaticClient.Height(); // zero based m_photo1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew)); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); } } void CMyView::Load_Photo_2(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo2.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rec

    A N 2 Replies Last reply
    0
    • V vc programmer 0

      every body.... my code is following. my problem is only photo2 is show. i want to show both photo1 and photo2.plz help me... //MyView.h CStatic m_photo1; CStatic m_photo2; HBITMAP m_hBmpOld; HBITMAP m_hBmpNew; BITMAP m_bmInfo; //MyView.cpp void CMyView::OnOK() { Load_Photo_1("image/1.bmp"); Load_Photo_2("image/2.bmp"); } void CMyView::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); dc.BitBlt(offsetx,offsety,m_size.cx,m_size.cy, &m_dcMem, sourcex, sourcey,SRCCOPY); CFormView::OnPaint(); } } void CMyView::OnInitialUpdate() { CClientDC dc(this); m_dcMem.CreateCompatibleDC( &dc ); } void CMyView::Load_Photo_1(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); // zero based m_size.cy = rectStaticClient.Height(); // zero based m_photo1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew)); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); } } void CMyView::Load_Photo_2(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo2.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rec

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      ;)definitely.....only the photo2 will get loaded..... u have defined only one dcmemory variable..... and u have assigned both the photoz to that same dcmemory variable..... since the first gets assigned to the "m_dcMem".....what happens is u assign even the second photo to the same variable "m_dcMem" so the first getz overwritten..... use two seperate variables :m_dcMem1 and m_dcMem2 that should sove the prob..... happy programmin..... cheerz..... :-D

      1 Reply Last reply
      0
      • V vc programmer 0

        every body.... my code is following. my problem is only photo2 is show. i want to show both photo1 and photo2.plz help me... //MyView.h CStatic m_photo1; CStatic m_photo2; HBITMAP m_hBmpOld; HBITMAP m_hBmpNew; BITMAP m_bmInfo; //MyView.cpp void CMyView::OnOK() { Load_Photo_1("image/1.bmp"); Load_Photo_2("image/2.bmp"); } void CMyView::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CPaintDC dc(this); dc.BitBlt(offsetx,offsety,m_size.cx,m_size.cy, &m_dcMem, sourcex, sourcey,SRCCOPY); CFormView::OnPaint(); } } void CMyView::OnInitialUpdate() { CClientDC dc(this); m_dcMem.CreateCompatibleDC( &dc ); } void CMyView::Load_Photo_1(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo1.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rectStaticClient.Width(); // zero based m_size.cy = rectStaticClient.Height(); // zero based m_photo1.ClientToScreen( &rectStaticClient ); ScreenToClient( &rectStaticClient); m_pt.x = rectStaticClient.left; m_pt.y = rectStaticClient.top; GetObject( m_hBmpNew , sizeof(BITMAP), &m_bmInfo ); VERIFY(m_hBmpOld = (HBITMAP)SelectObject(m_dcMem, m_hBmpNew)); offsetx= m_pt.x; offsety=m_pt.y; InvalidateRect(&rectStaticClient); } } void CMyView::Load_Photo_2(CString p_filepath) { m_hBmpNew = (HBITMAP) LoadImage( AfxGetInstanceHandle(), p_filepath, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); if( m_hBmpNew == NULL ) { AfxMessageBox("Load Image Failed"); } else { m_photo2.GetClientRect( &rectStaticClient ); rectStaticClient.NormalizeRect(); m_size.cx=rectStaticClient.Size().cx; m_size.cy=rectStaticClient.Size().cy; m_size.cx = rec

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

        ;)and oh.....i forgot,therz one more thing..... in ur paint function.....make sure u give two BitBlts..... that iz.... dc.BitBlt(offsetx1,offsety1,m_size1.cx,m_size1.cy,&m_dcMem1, sourcex1, sourcey1,SRCCOPY); dc.BitBlt(offsetx2,offsety2,m_size2.cx,m_size2.cy,&m_dcMem2, sourcex2, sourcey2,SRCCOPY); i hope u got that as well..... happy programmin..... cheerz..... :-D

        V 1 Reply Last reply
        0
        • N namaskaaram

          ;)and oh.....i forgot,therz one more thing..... in ur paint function.....make sure u give two BitBlts..... that iz.... dc.BitBlt(offsetx1,offsety1,m_size1.cx,m_size1.cy,&m_dcMem1, sourcex1, sourcey1,SRCCOPY); dc.BitBlt(offsetx2,offsety2,m_size2.cx,m_size2.cy,&m_dcMem2, sourcex2, sourcey2,SRCCOPY); i hope u got that as well..... happy programmin..... cheerz..... :-D

          V Offline
          V Offline
          vc programmer 0
          wrote on last edited by
          #4

          i understand ... thank you...

          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