home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / xped4 / xped4app.cpp < prev    next >
C/C++ Source or Header  |  1994-02-13  |  7KB  |  270 lines

  1. /*  Project xped4
  2.     
  3.     Copyright ⌐ 1993. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    xped4.exe Application
  6.     FILE:         xped4app.cpp
  7.     AUTHOR:       
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of XpEd4App (TApplication).      
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #pragma hdrstop
  18.  
  19. #include <dir.h>
  20.  
  21. #include "xped4app.h"
  22. #include "xpd4mdic.h"
  23. #include "xped4abd.h"                        // Definition of about dialog.       
  24.  
  25.  
  26. // Drag / Drop support:
  27. TFileDrop::TFileDrop (char* fileName, TPoint& p, BOOL inClient, TModule* module)
  28. {
  29.     char    exePath[MAXPATH];
  30.     
  31.     exePath[0] = 0;
  32.     FileName = strcpy(new char[strlen(fileName) + 1], fileName);
  33.     Point = p;
  34.     InClientArea = inClient;
  35.     
  36.     Icon = (WORD)FindExecutable(FileName, ".\\", exePath) <= 32 ? 0 : ::ExtractIcon(*module, exePath, 0);
  37.  
  38.     // Use a question mark if couldn't get the icon from the executable.
  39.     //
  40.     if ((WORD)Icon <= 1) {  // 0=no icons in exe,  1=not an exe
  41.         Icon = LoadIcon(0, (WORD)Icon == 1 ? IDI_APPLICATION : IDI_QUESTION);
  42.         DefIcon = TRUE;
  43.     } else
  44.         DefIcon = FALSE;
  45. }
  46.  
  47. TFileDrop::~TFileDrop ()
  48. {
  49.     delete FileName;
  50.     if (!DefIcon)
  51.         FreeResource(Icon);
  52. }
  53.  
  54. const char *TFileDrop::WhoAmI ()
  55. {
  56.   return FileName;
  57. }
  58.  
  59.  
  60. //{{XpEd4App Implementation}}
  61.  
  62. //
  63. // Build a response table for all messages/commands handled
  64. // by the application.
  65. //
  66. DEFINE_RESPONSE_TABLE1(XpEd4App, TApplication)
  67. //{{XpEd4AppRSP_TBL_BEGIN}}
  68.     EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  69.     EV_WM_DROPFILES,
  70.     EV_WM_WININICHANGE,
  71. //{{XpEd4AppRSP_TBL_END}}
  72. END_RESPONSE_TABLE;
  73.  
  74.  
  75. //////////////////////////////////////////////////////////
  76. // XpEd4App
  77. // =====
  78. //
  79. XpEd4App::XpEd4App () : TApplication("xped4")
  80. {
  81.  
  82.     Printer = 0;
  83.     Printing = FALSE;
  84.  
  85.     // INSERT>> Your constructor code here.
  86.  
  87. }
  88.  
  89.  
  90. XpEd4App::~XpEd4App ()
  91. {
  92.     if (Printer)
  93.         delete Printer;
  94.  
  95.     // INSERT>> Your destructor code here.
  96.  
  97. }
  98.  
  99.  
  100. //////////////////////////////////////////////////////////
  101. // XpEd4App
  102. // =====
  103. // Application intialization.
  104. //
  105. void XpEd4App::InitMainWindow ()
  106. {
  107.     TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, MDI_MENU, *(new xped4MDIClient), FALSE);
  108.  
  109.     nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
  110.  
  111.     //
  112.     // Assign ICON w/ this application.
  113.     //
  114.     frame->SetIcon(this, IDI_MDIAPPLICATION);
  115.  
  116.     //
  117.     // Menu associated with window and accelerator table associated with table.
  118.     //
  119.     frame->AssignMenu(MDI_MENU);
  120.     
  121.     //
  122.     // Associate with the accelerator table.
  123.     //
  124.     frame->Attr.AccelTable = MDI_MENU;
  125.  
  126.  
  127.   
  128.     MainWindow = frame;
  129.  
  130. }
  131.  
  132.  
  133. //////////////////////////////////////////////////////////
  134. // XpEd4App
  135. // ===========
  136. // Menu Help About xped4.exe command
  137. void XpEd4App::CmHelpAbout ()
  138. {
  139.     //
  140.     // Show the modal dialog.
  141.     //
  142.     XpEd4AboutDlg(MainWindow).Execute();
  143. }
  144.  
  145.  
  146. void XpEd4App::InitInstance ()
  147. {
  148.     TApplication::InitInstance();
  149.  
  150.     // Accept files via drag/drop in the frame window.
  151.     MainWindow->DragAcceptFiles(TRUE);
  152. }
  153.  
  154.  
  155. void XpEd4App::EvDropFiles (TDropInfo drop)
  156. {
  157.     // Number of files dropped.
  158.     int totalNumberOfFiles = drop.DragQueryFileCount();
  159.  
  160.     TFileList* files = new TFileList;
  161.  
  162.     for (int i = 0; i < totalNumberOfFiles; i++) {
  163.         // Tell DragQueryFile the file interested in (i) and the length of your buffer.
  164.         int     fileLength = drop.DragQueryFileNameLen(i) + 1;
  165.         char    *fileName = new char[fileLength];
  166.  
  167.         drop.DragQueryFile(i, fileName, fileLength);
  168.  
  169.         // Getting the file dropped. The location is relative to your client coordinates,
  170.         // and will have negative values if dropped in the non client parts of the window.
  171.         //
  172.         // DragQueryPoint copies that point where the file was dropped and returns whether
  173.         // or not the point is in the client area.  Regardless of whether or not the file
  174.         // is dropped in the client or non-client area of the window, you will still receive
  175.         // the file name.
  176.         TPoint  point;
  177.         BOOL    inClientArea = drop.DragQueryPoint(point);
  178.         files->Add(new TFileDrop(fileName, point, inClientArea, this));
  179.     }
  180.  
  181.     // Open the files that were dropped.
  182.     AddFiles(files);
  183.  
  184.     // Release the memory allocated for this handle with DragFinish.
  185.     drop.DragFinish();
  186. }
  187.  
  188.  
  189. void XpEd4App::AddFiles (TFileList* files)
  190. {
  191.     // Open all files dragged in.
  192.     TFileListIter fileIter(*files);
  193.  
  194.     TFrameWindow *tfw = TYPESAFE_DOWNCAST(MainWindow, TFrameWindow);
  195.     if (tfw) {
  196.         xped4MDIClient *theClient = TYPESAFE_DOWNCAST(tfw->GetClientWindow(), xped4MDIClient);
  197.  
  198.         if (theClient)
  199.             while (fileIter) {
  200.                 theClient->OpenFile(fileIter.Current()->WhoAmI());
  201.                 fileIter++;
  202.             }
  203.     }
  204. }
  205.  
  206.  
  207. void XpEd4App::EvWinIniChange (char far* section)
  208. {
  209.     if (lstrcmp(section, "windows") == 0) {
  210.         // If the device changed in the WIN.INI file then the printer
  211.         // might have changed.  If we have a TPrinter (Printer) then
  212.         // check and make sure it's identical to the current device
  213.         // entry in WIN.INI.
  214.         if (Printer) {
  215.             char printDBuffer[255];
  216.             LPSTR printDevice = printDBuffer;
  217.             LPSTR devName = 0;
  218.             LPSTR driverName = 0;
  219.             LPSTR outputName = 0;
  220.         
  221.             if (::GetProfileString("windows", "device", "", printDevice, sizeof(printDevice))) {
  222.                 // The string which should come back is something like:
  223.                 //
  224.                 //      HP LaserJet III,hppcl5a,LPT1:
  225.                 //
  226.                 // Where the format is:
  227.                 //
  228.                 //      devName,driverName,outputName
  229.                 //
  230.                 devName = printDevice;
  231.                 while (*printDevice) {
  232.                     if (*printDevice == ',') {
  233.                         *printDevice++ = 0;
  234.                         if (!driverName)
  235.                             driverName = printDevice;
  236.                         else
  237.                             outputName = printDevice;
  238.                     } else
  239.                         printDevice = AnsiNext(printDevice);
  240.                 }
  241.  
  242.                 if ((Printer->GetSetup().Error != 0)                                ||
  243.                     (lstrcmp(devName, Printer->GetSetup().GetDeviceName()) != 0)    ||
  244.                     (lstrcmp(driverName, Printer->GetSetup().GetDriverName()) != 0) ||
  245.                     (lstrcmp(outputName, Printer->GetSetup().GetOutputName()) != 0)) {
  246.                 
  247.                     // New printer installed so get the new printer device now.
  248.                     delete Printer;
  249.                     Printer = new TPrinter;
  250.                 }
  251.             } else {
  252.                 // No printer installed (GetProfileString failed).
  253.                 delete Printer;
  254.                 Printer = new TPrinter;
  255.             }
  256.         }
  257.     }
  258. }
  259.  
  260.  
  261. int OwlMain (int , char* [])
  262. {
  263.     XpEd4App     App;
  264.     int             result;
  265.  
  266.     result = App.Run();
  267.  
  268.     return result;
  269. }
  270.