How to write a simple Bmp File Viewer ?


  1. Build a dialog based application through AppWizard.
  2. Add a picture control from the control tool bar into the dialog box using the Resource Editor.
  3. 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.
  4. Add Edit box and Button.
  5. 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 ) ;

}

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>