- Build a dialog based application through AppWizard.
- Add a picture control from the control tool bar into the dialog box using the Resource Editor.
- In Picture Properties change the ID of picture control from default ID_STATIC to some other ID, say, ID_PICTURE and select Bitmap from ‘Type’ option.
- Add Edit box and Button.
- Add handler for button and write the following code in it.
CFileDialog d ( TRUE, “*.bmp”, NULL, NULL, “Bmp Files(*.bmp)|*.bmp|AllFiles(*.*)|*.*||” ) ;
if ( d.DoModal( ) == IDOK )
{
m_path = d.GetPathName( ) ;
UpdateData ( FALSE ) ;
HBITMAP hbitmap = ( HBITMAP ) ::LoadImage ( AfxGetApp( ) -> m_hInstance, ( LPCTSTR )m_path, IMAGE_BITMAP, LR_DEFAULTSIZE,
LR_DEFAULTSIZE, LR_LOADFROMFILE ) ;
m_picture.SetBitmap ( hbitmap ) ;
}