home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / METAFILE.PAK / METAFILX.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  2.9 KB  |  140 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
  4. //----------------------------------------------------------------------------
  5. #include <owl/pch.h>
  6. #if !defined(OWL_APPLICAT_H)
  7. # include <owl/applicat.h>
  8. #endif
  9. #if !defined(OWL_FRAMEWIN_H)
  10. # include <owl/framewin.h>
  11. #endif
  12. #if !defined(OWL_STATIC_H)
  13. # include <owl/static.h>
  14. #endif
  15. #if !defined(OWL_METAFILE_H)
  16. # include <owl/metafile.h>
  17. #endif
  18. #if !defined(OWL_OPENSAVE_H)
  19. # include <owl/opensave.h>
  20. #endif
  21. #if !defined(OWL_EDITFILE_RH)
  22. # include <owl/editfile.rh>
  23. #endif
  24. #include <stdio.h>
  25.  
  26. //
  27. // class TMetaFileExWindow
  28. // ~~~~~ ~~~~~~~~~~~~~~~~~
  29. class TMetaFileExWindow : public TWindow {
  30.   public:
  31.     TMetaFileExWindow() : TWindow(0, 0, 0)
  32.     {}
  33.  
  34.     TAPointer<char>   FileName;
  35.  
  36. #if defined(BI_PLAT_WIN32)
  37.     bool              Enhanced;
  38. #endif
  39.  
  40.     void              CmFileOpen();
  41.     void              Paint(TDC& dc, bool erase, TRect& rect);
  42.     void              EvSize(uint sizeType, TSize& size);
  43.  
  44.   DECLARE_RESPONSE_TABLE(TMetaFileExWindow);
  45. };
  46.  
  47. DEFINE_RESPONSE_TABLE1(TMetaFileExWindow, TWindow)
  48.   EV_COMMAND(CM_FILEOPEN, CmFileOpen),
  49.   EV_WM_SIZE,
  50. END_RESPONSE_TABLE;
  51.  
  52. //
  53. //
  54. //
  55. void
  56. TMetaFileExWindow::CmFileOpen()
  57. {
  58.   char* filter = 
  59. #if defined(BI_PLAT_WIN32)
  60.                        "Enh. Metafiles|*.emf|"
  61. #endif
  62.                        "Metafiles |*.wmf|";
  63.  
  64.   // Prompt user for filenane
  65.   //
  66.   TOpenSaveDialog::TData data(OFN_FILEMUSTEXIST, filter);
  67.   if (TFileOpenDialog(this, data).Execute() == IDOK) {
  68.     FileName = strnewdup(data.FileName);
  69.  
  70. #if defined(BI_PLAT_WIN32)
  71.     Enhanced = data.FilterIndex == 1;
  72. #endif
  73.     
  74.     // Force redraw
  75.     //
  76.     Invalidate();
  77.   }
  78. }
  79.  
  80. //
  81. //
  82. //
  83. void              
  84. TMetaFileExWindow::Paint(TDC& dc, bool /*erase*/, TRect& /*rect*/)
  85. {
  86.   TRect clientRect;
  87.   GetClientRect(clientRect);
  88.  
  89.   if ((char*)FileName) {
  90.     try {
  91.     
  92. #if defined(BI_PLAT_WIN32)
  93.       if (Enhanced) {
  94.         TEnhMetaFilePict emf(FileName);
  95.         emf.PlayOnto(dc, &clientRect);
  96.         return;
  97.       }
  98. #endif
  99.       TMetaFilePict mf(FileName);
  100.       mf.PlayOnto(dc, clientRect.Size());
  101.     }
  102.     catch (TXGdi& xcpt) {
  103.       MessageBeep(-1);
  104.     }
  105.   }
  106. }
  107.  
  108. //
  109. //
  110. //
  111. void              
  112. TMetaFileExWindow::EvSize(uint sizeType, TSize& size)
  113. {
  114.   TWindow::EvSize(sizeType, size);
  115.   Invalidate();
  116. }
  117.  
  118. //
  119. // class TMetaFileExApp
  120. // ~~~~~ ~~~~~~~~~~~~~~
  121. class _USERCLASS TMetaFileExApp : public TApplication {
  122.   public:
  123.     void InitMainWindow();
  124. };
  125.  
  126. void
  127. TMetaFileExApp::InitMainWindow()
  128. {
  129.   TFrameWindow* frame = new TFrameWindow(0, "Metafile Example",
  130.                                          new TMetaFileExWindow);
  131.   frame->AssignMenu("MAINMENU");
  132.   SetMainWindow(frame);
  133. }
  134.  
  135. int
  136. OwlMain(int /*argc*/, char* /*argv*/ [])
  137. {
  138.   return TMetaFileExApp().Run();
  139. }
  140.