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 ) ;

}

Subscribe / Share

It's very calm over here, why not leave a comment?

Leave a Reply




Categories

Powered by Yahoo! Answers