home *** CD-ROM | disk | FTP | other *** search
- /* Project xped4
-
- Copyright ⌐ 1993. All Rights Reserved.
-
- SUBSYSTEM: xped4.exe Application
- FILE: xped4app.cpp
- AUTHOR:
-
-
- OVERVIEW
- ========
- Source file for implementation of XpEd4App (TApplication).
- */
-
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
- #include <dir.h>
-
- #include "xped4app.h"
- #include "xpd4mdic.h"
- #include "xped4abd.h" // Definition of about dialog.
-
-
- // Drag / Drop support:
- TFileDrop::TFileDrop (char* fileName, TPoint& p, BOOL inClient, TModule* module)
- {
- char exePath[MAXPATH];
-
- exePath[0] = 0;
- FileName = strcpy(new char[strlen(fileName) + 1], fileName);
- Point = p;
- InClientArea = inClient;
-
- Icon = (WORD)FindExecutable(FileName, ".\\", exePath) <= 32 ? 0 : ::ExtractIcon(*module, exePath, 0);
-
- // Use a question mark if couldn't get the icon from the executable.
- //
- if ((WORD)Icon <= 1) { // 0=no icons in exe, 1=not an exe
- Icon = LoadIcon(0, (WORD)Icon == 1 ? IDI_APPLICATION : IDI_QUESTION);
- DefIcon = TRUE;
- } else
- DefIcon = FALSE;
- }
-
- TFileDrop::~TFileDrop ()
- {
- delete FileName;
- if (!DefIcon)
- FreeResource(Icon);
- }
-
- const char *TFileDrop::WhoAmI ()
- {
- return FileName;
- }
-
-
- //{{XpEd4App Implementation}}
-
- //
- // Build a response table for all messages/commands handled
- // by the application.
- //
- DEFINE_RESPONSE_TABLE1(XpEd4App, TApplication)
- //{{XpEd4AppRSP_TBL_BEGIN}}
- EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
- EV_WM_DROPFILES,
- EV_WM_WININICHANGE,
- //{{XpEd4AppRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //////////////////////////////////////////////////////////
- // XpEd4App
- // =====
- //
- XpEd4App::XpEd4App () : TApplication("xped4")
- {
-
- Printer = 0;
- Printing = FALSE;
-
- // INSERT>> Your constructor code here.
-
- }
-
-
- XpEd4App::~XpEd4App ()
- {
- if (Printer)
- delete Printer;
-
- // INSERT>> Your destructor code here.
-
- }
-
-
- //////////////////////////////////////////////////////////
- // XpEd4App
- // =====
- // Application intialization.
- //
- void XpEd4App::InitMainWindow ()
- {
- TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, MDI_MENU, *(new xped4MDIClient), FALSE);
-
- nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
-
- //
- // Assign ICON w/ this application.
- //
- frame->SetIcon(this, IDI_MDIAPPLICATION);
-
- //
- // Menu associated with window and accelerator table associated with table.
- //
- frame->AssignMenu(MDI_MENU);
-
- //
- // Associate with the accelerator table.
- //
- frame->Attr.AccelTable = MDI_MENU;
-
-
-
- MainWindow = frame;
-
- }
-
-
- //////////////////////////////////////////////////////////
- // XpEd4App
- // ===========
- // Menu Help About xped4.exe command
- void XpEd4App::CmHelpAbout ()
- {
- //
- // Show the modal dialog.
- //
- XpEd4AboutDlg(MainWindow).Execute();
- }
-
-
- void XpEd4App::InitInstance ()
- {
- TApplication::InitInstance();
-
- // Accept files via drag/drop in the frame window.
- MainWindow->DragAcceptFiles(TRUE);
- }
-
-
- void XpEd4App::EvDropFiles (TDropInfo drop)
- {
- // Number of files dropped.
- int totalNumberOfFiles = drop.DragQueryFileCount();
-
- TFileList* files = new TFileList;
-
- for (int i = 0; i < totalNumberOfFiles; i++) {
- // Tell DragQueryFile the file interested in (i) and the length of your buffer.
- int fileLength = drop.DragQueryFileNameLen(i) + 1;
- char *fileName = new char[fileLength];
-
- drop.DragQueryFile(i, fileName, fileLength);
-
- // Getting the file dropped. The location is relative to your client coordinates,
- // and will have negative values if dropped in the non client parts of the window.
- //
- // DragQueryPoint copies that point where the file was dropped and returns whether
- // or not the point is in the client area. Regardless of whether or not the file
- // is dropped in the client or non-client area of the window, you will still receive
- // the file name.
- TPoint point;
- BOOL inClientArea = drop.DragQueryPoint(point);
- files->Add(new TFileDrop(fileName, point, inClientArea, this));
- }
-
- // Open the files that were dropped.
- AddFiles(files);
-
- // Release the memory allocated for this handle with DragFinish.
- drop.DragFinish();
- }
-
-
- void XpEd4App::AddFiles (TFileList* files)
- {
- // Open all files dragged in.
- TFileListIter fileIter(*files);
-
- TFrameWindow *tfw = TYPESAFE_DOWNCAST(MainWindow, TFrameWindow);
- if (tfw) {
- xped4MDIClient *theClient = TYPESAFE_DOWNCAST(tfw->GetClientWindow(), xped4MDIClient);
-
- if (theClient)
- while (fileIter) {
- theClient->OpenFile(fileIter.Current()->WhoAmI());
- fileIter++;
- }
- }
- }
-
-
- void XpEd4App::EvWinIniChange (char far* section)
- {
- if (lstrcmp(section, "windows") == 0) {
- // If the device changed in the WIN.INI file then the printer
- // might have changed. If we have a TPrinter (Printer) then
- // check and make sure it's identical to the current device
- // entry in WIN.INI.
- if (Printer) {
- char printDBuffer[255];
- LPSTR printDevice = printDBuffer;
- LPSTR devName = 0;
- LPSTR driverName = 0;
- LPSTR outputName = 0;
-
- if (::GetProfileString("windows", "device", "", printDevice, sizeof(printDevice))) {
- // The string which should come back is something like:
- //
- // HP LaserJet III,hppcl5a,LPT1:
- //
- // Where the format is:
- //
- // devName,driverName,outputName
- //
- devName = printDevice;
- while (*printDevice) {
- if (*printDevice == ',') {
- *printDevice++ = 0;
- if (!driverName)
- driverName = printDevice;
- else
- outputName = printDevice;
- } else
- printDevice = AnsiNext(printDevice);
- }
-
- if ((Printer->GetSetup().Error != 0) ||
- (lstrcmp(devName, Printer->GetSetup().GetDeviceName()) != 0) ||
- (lstrcmp(driverName, Printer->GetSetup().GetDriverName()) != 0) ||
- (lstrcmp(outputName, Printer->GetSetup().GetOutputName()) != 0)) {
-
- // New printer installed so get the new printer device now.
- delete Printer;
- Printer = new TPrinter;
- }
- } else {
- // No printer installed (GetProfileString failed).
- delete Printer;
- Printer = new TPrinter;
- }
- }
- }
- }
-
-
- int OwlMain (int , char* [])
- {
- XpEd4App App;
- int result;
-
- result = App.Run();
-
- return result;
- }
-