home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / borland / cb / setup / cbuilder / data.z / IMAGEWN.CPP < prev    next >
C/C++ Source or Header  |  1997-02-28  |  5KB  |  120 lines

  1. //----------------------------------------------------------------------------
  2. //Borland C++Builder
  3. //Copyright (c) 1987, 1997 Borland International Inc. All Rights Reserved.
  4. //----------------------------------------------------------------------------
  5.  //---------------------------------------------------------------------
  6. // IMAGE VIEWER DEMO v.01
  7. //---------------------------------------------------------------------
  8. #include <vcl.h>
  9. #pragma hdrstop
  10.  
  11. #include <sysutils.hpp>
  12. #include "imagewn.h"
  13. #include "ViewFrm.h"
  14. //---------------------------------------------------------------------
  15. #pragma resource "*.dfm"
  16. TImageForm *ImageForm;
  17. //---------------------------------------------------------------------
  18. __fastcall TImageForm::TImageForm(TComponent *Owner)
  19.   : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------
  23. void __fastcall TImageForm::FormCreate(TObject* /*Sender*/)
  24. {     FormCaption = Caption + " - ";
  25. }
  26. //----------------------------------------------------------------------------
  27.  void __fastcall TImageForm::ViewBtnClick(TObject* /*Sender*/)
  28. {     ViewFrm->HorzScrollBar->Range = Image1->Picture->Width;
  29.       ViewFrm->VertScrollBar->Range = Image1->Picture->Height;
  30.       ViewFrm->Caption = Caption;
  31.       ViewFrm->Show();
  32. }
  33. //----------------------------------------------------------------------------
  34.  void __fastcall TImageForm::UpDownEditChange(TObject* /*Sender*/)
  35. {
  36.       SpeedButton1->NumGlyphs = UpDown1->Position;
  37.       SpeedButton2->NumGlyphs = UpDown1->Position;
  38. }
  39. //----------------------------------------------------------------------------
  40.  void __fastcall TImageForm::StretchCheckClick(TObject* /*Sender*/)
  41. {     Image1->Stretch = StretchCheck->Checked;
  42. }
  43. //----------------------------------------------------------------------------
  44. #pragma argsused
  45.  void __fastcall TImageForm::FileEditKeyPress(TObject* Sender,
  46.       Char &Key)
  47. {     if (Key == 0x13) {
  48.          FileListBox1->ApplyFilePath(FileEdit->Text);
  49.          Key = 0x0;
  50.       }
  51. }
  52. //----------------------------------------------------------------------------
  53.  void __fastcall TImageForm::GlyphCheckClick(TObject* /*Sender*/)
  54. {
  55.      ViewAsGlyph(FileExt);
  56. }
  57. //----------------------------------------------------------------------------
  58.  void __fastcall TImageForm::ViewAsGlyph(const AnsiString FileExt)
  59. {
  60.     if ( GlyphCheck->Checked && !strcmp(FileExt.c_str(),".BMP") ) {
  61.          SpeedButton1->Glyph = Image1->Picture->Bitmap;
  62.          SpeedButton2->Glyph = Image1->Picture->Bitmap;
  63.          UpDown1->Position   = SpeedButton1->NumGlyphs;
  64.          BitBtn1->Glyph      = Image1->Picture->Bitmap;
  65.          BitBtn2->Glyph      = Image1->Picture->Bitmap;
  66.          UpDown1->Enabled    = True;
  67.          UpDownEdit->Enabled = True;
  68.          Label2->Enabled     = True;
  69.       }
  70.       else {
  71.          SpeedButton1->Glyph = NULL;
  72.          SpeedButton2->Glyph = NULL;
  73.          BitBtn1->Glyph      = NULL;
  74.          BitBtn2->Glyph      = NULL;
  75.          UpDown1->Enabled    = False;
  76.          UpDownEdit->Enabled = False;
  77.          Label2->Enabled     = False;
  78.       }
  79. }
  80. //----------------------------------------------------------------------------
  81. void __fastcall TImageForm::FileListBox1Click(TObject* /*Sender*/)
  82. {    char cCaption[25];
  83.      memset(cCaption,NULL,sizeof(cCaption));
  84.  
  85.      FileExt = ExtractFileExt(FileListBox1->FileName);
  86.      FileExt = UpperCase(FileExt);
  87.  
  88.      if ( !strcmp(FileExt.c_str(),".BMP") || !strcmp(FileExt.c_str(),".ICO") ||
  89.           !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF" ))
  90.      {
  91.         Image1->Picture->LoadFromFile(FileListBox1->FileName);
  92.         Caption = FormCaption + ExtractFileName(FileListBox1->FileName);
  93.  
  94.         if ( !strcmp(FileExt.c_str(),".BMP") )
  95.         {
  96.            sprintf(cCaption," (%d x %d)",Image1->Picture->Width,Image1->Picture->Height);
  97.            Caption = (AnsiString)cCaption;
  98.            ViewFrm->Image1->Picture = Image1->Picture;
  99.            ViewFrm->Caption = Caption;
  100.            GlyphCheck->Enabled = true;
  101.            if (GlyphCheck->Checked)
  102.                 ViewAsGlyph(FileExt);
  103.         }
  104.         if ( !strcmp(FileExt.c_str(),".ICO") )
  105.         {
  106.              ViewFrm->Image1->Picture->Icon = Image1->Picture->Icon;
  107.              Icon = Image1->Picture->Icon;
  108.              GlyphCheck->Checked = false;
  109.              GlyphCheck->Enabled = false;
  110.         }
  111.         if ( !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF") )
  112.         {
  113.              ViewFrm->Image1->Picture->Metafile = Image1->Picture->Metafile;
  114.              GlyphCheck->Checked = false;
  115.              GlyphCheck->Enabled = false;
  116.         }
  117.      }
  118. }
  119. //----------------------------------------------------------------------------
  120.