home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / progs / CB / DATA.Z / IMAGEWN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-05  |  4.8 KB  |  120 lines

  1.  //---------------------------------------------------------------------
  2. // IMAGE VIEWER DEMO v.01
  3. // 05 - 22 - 1996
  4. // Eric Uber ext. 8333
  5. //
  6. // Issues:
  7. //
  8. // 1. Appears to be a runtime problem with FileListBox1->FileName property.
  9. //    Instead of returning a valid string, a run-time error is generated.
  10. //    The type/problem is unknown as message box is blank.
  11. //
  12. // 2. There is a PUBDEF bug in VCL.LIB with the mangled SetNumGlyph name.
  13. //    Appears a signed char is expected but the mangled name
  14. //    from this obj says an unsigned char. Jeff J. found this.
  15. //
  16. //    example: SpeedButton1->NumGlyphs = UpDown1->Position;
  17. //
  18. //    ...generates linker error unresolved external->SetNumGlyphs(etc.
  19. //
  20. //    Modifications:
  21. //
  22. //---------------------------------------------------------------------
  23. #include <vcl.h>
  24. #pragma hdrstop
  25.  
  26. #include <sysutils.hpp>
  27. #include "imagewn.h"
  28. #include "ViewFrm.h"
  29. //---------------------------------------------------------------------
  30. #pragma resource "*.dfm"
  31. TImageForm *ImageForm;
  32. //---------------------------------------------------------------------
  33. __fastcall TImageForm::TImageForm(TComponent *Owner)
  34.   : TForm(Owner)
  35. {
  36. }
  37. //---------------------------------------------------------------------
  38. void __fastcall TImageForm::FormCreate(TObject* /*Sender*/)
  39. {     FormCaption = Caption + " - ";
  40. }
  41. //----------------------------------------------------------------------------
  42.  void __fastcall TImageForm::ViewBtnClick(TObject* /*Sender*/)
  43. {     ViewFrm->HorzScrollBar->Range = Image1->Picture->Width;
  44.       ViewFrm->VertScrollBar->Range = Image1->Picture->Height;
  45.       ViewFrm->Caption = Caption;
  46.       ViewFrm->Show();
  47. }
  48. //----------------------------------------------------------------------------
  49.  void __fastcall TImageForm::UpDownEditChange(TObject* /*Sender*/)
  50. {
  51.       SpeedButton1->NumGlyphs = UpDown1->Position;
  52.       SpeedButton2->NumGlyphs = UpDown1->Position;
  53. }
  54. //----------------------------------------------------------------------------
  55.  void __fastcall TImageForm::StretchCheckClick(TObject* /*Sender*/)
  56. {     Image1->Stretch = StretchCheck->Checked;
  57. }
  58. //----------------------------------------------------------------------------
  59. #pragma argsused
  60.  void __fastcall TImageForm::FileEditKeyPress(TObject* Sender,
  61.       Char &Key)
  62. {     if (Key == 0x13) {
  63.          FileListBox1->ApplyFilePath(FileEdit->Text);
  64.          Key = 0x0;
  65.       }
  66. }
  67. //----------------------------------------------------------------------------
  68.  void __fastcall TImageForm::GlyphCheckClick(TObject* /*Sender*/)
  69. {     ViewAsGlyph( UpperCase(FileListBox1->FileName) );
  70. }
  71. //----------------------------------------------------------------------------
  72.  void __fastcall TImageForm::ViewAsGlyph(const AnsiString FileExt)
  73. {
  74.     if ( GlyphCheck->Checked && !strcmp(FileExt.c_str(),".BMP") ) {
  75.          SpeedButton1->Glyph = Image1->Picture->Bitmap;
  76.          SpeedButton2->Glyph = Image1->Picture->Bitmap;
  77.          UpDown1->Position   = SpeedButton1->NumGlyphs;
  78.          BitBtn1->Glyph      = Image1->Picture->Bitmap;
  79.          BitBtn2->Glyph      = Image1->Picture->Bitmap;
  80.          UpDown1->Enabled    = True;
  81.          UpDownEdit->Enabled = True;
  82.          Label2->Enabled     = True;
  83.       }
  84.       else {
  85.          SpeedButton1->Glyph = NULL;
  86.          SpeedButton2->Glyph = NULL;
  87.          BitBtn1->Glyph      = NULL;
  88.          BitBtn2->Glyph      = NULL;
  89.          UpDown1->Enabled    = False;
  90.          UpDownEdit->Enabled = False;
  91.          Label2->Enabled     = False;
  92.       }
  93. }
  94. //----------------------------------------------------------------------------
  95. void __fastcall TImageForm::FileListBox1Click(TObject* /*Sender*/)
  96. {    char cCaption[25];
  97.      memset(cCaption,NULL,sizeof(cCaption));
  98.  
  99.      String FileExt = ExtractFileExt(FileListBox1->FileName);
  100.      FileExt = UpperCase(FileExt);
  101.  
  102.      if ( !strcmp(FileExt.c_str(),".BMP") || !strcmp(FileExt.c_str(),".ICO") ||
  103.           !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF" )) {
  104.         Image1->Picture->LoadFromFile(FileListBox1->FileName);
  105.         Caption = FormCaption + ExtractFileName(FileListBox1->FileName);
  106.  
  107.         if ( !strcmp(FileExt.c_str(),".BMP") ) {
  108.            sprintf(cCaption," (%d x %d)",Image1->Picture->Width,Image1->Picture->Height);
  109.            Caption = (String)cCaption;
  110.            ViewFrm->Image1->Picture = Image1->Picture;
  111.            ViewFrm->Caption = Caption;
  112.            if (GlyphCheck->Checked) ViewAsGlyph(FileExt);
  113.         }
  114.         if ( !strcmp(FileExt.c_str(),".ICO") ) Icon = Image1->Picture->Icon;
  115.         if ( !strcmp(FileExt.c_str(),".WMF") || !strcmp(FileExt.c_str(),".EMF") )
  116.             ViewFrm->Image1->Picture->Metafile = Image1->Picture->Metafile;
  117.      }
  118. }
  119. //----------------------------------------------------------------------------
  120.