3

My browse button code is

void CFileOpenDlg::OnBnClickedButton1()
{
 // TODO: Add your control notification handler code here
 CFileDialog dlg(TRUE);
 int result=dlg.DoModal();
 if(result==IDOK)
 {
  path=dlg.GetPathName();
  UpdateData(FALSE);
 }
}

and this is the code for loading an image from resource but that does not work for loading an image from file. i know LoadImage(); is used for this but how? how can i edit this code to load image from file. Plzz help.....

void CFileOpenDlg::OnBnClickedButton2()
{
 // TODO: Add your control notification handler code here
CRect r;
CBitmap* m_bitmap;
CDC dc, *pDC;
BITMAP bmp;
m_bitmap = new CBitmap();
m_bitmap->LoadBitmapW(IDB_BITMAP1);
m_bitmap->GetBitmap(&bmp);
pDC = this->GetDC();
dc.CreateCompatibleDC(pDC);
dc.SelectObject(m_bitmap);
pDC->BitBlt(200, 200, bmp.bmWidth, bmp.bmHeight, &dc,0 , 0, SRCCOPY);
m_bitmap->DeleteObject();
m_bitmap->Detach();
}
Nick Dandoulakis
  • 42,588
  • 16
  • 104
  • 136
Sweety Khan
  • 41
  • 1
  • 1
  • 2

2 Answers2

5

MSDN LoadImage

HANDLE hBitMap = ::LoadImage(0, "c:\\mybmp.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
CBitmap bmp;
bmp.Attach((HBITMAP)hBitMap); 
renick
  • 3,873
  • 2
  • 31
  • 40
3

If you want to open .JPG, .PNG ... eventually you can use CImage (is a shared class between MFC and ATL)

CImage image;
image.Load ( "picture.jpg" );
image.Draw ( pDC , 200, 200 );
prompt
  • 66
  • 8