home *** CD-ROM | disk | FTP | other *** search
- /*
- Program to test the Open File common dialog box. The program
- displays the basic statistics for the file you select
- */
-
- #include <owl\applicat.h>
- #include <owl\framewin.h>
- #include <owl\opensave.h>
- #include "commdlg1.h"
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
- #include <dir.h>
-
- const MaxStringLen = 256;
-
- // declare the custom application class as
- // a subclass of TApplication
- class TWinApp : public TApplication
- {
- public:
- TWinApp() : TApplication() {}
-
- protected:
- virtual void InitMainWindow();
- };
-
- // expand the functionality of TWindow by
- // deriving class TMainWindow
- class TMainWindow : public TWindow
- {
- public:
-
- TMainWindow();
-
- protected:
-
- // the pointer to the data for the File Open dialog box
- TOpenSaveDialog::TData *FileData;
-
- // handle the calculation
- void CMFileStat();
-
- // handle exiting the program
- void CMExit();
-
- // handle closing the window
- virtual BOOL CanClose();
-
- // declare the message map macro
- DECLARE_RESPONSE_TABLE(TMainWindow);
-
- };
-
- DEFINE_RESPONSE_TABLE1(TMainWindow, TWindow)
- EV_COMMAND(CM_FILESTAT, CMFileStat),
- EV_COMMAND(CM_EXIT, CMExit),
- END_RESPONSE_TABLE;
-
- TMainWindow::TMainWindow()
- : TWindow(0, 0, 0)
- {
- FileData = new TOpenSaveDialog::TData(
- DWORD(OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT),
- "All Files (*.*)|*.*|"
- "C++ Programs (*.cpp)|*.cpp|"
- "Batch files (*.bat)|*.bat||",
- "*.cpp", "", "*.cpp");
- }
-
- void TMainWindow::CMFileStat()
- {
- char selFile[MaxStringLen];
- char s[MaxStringLen];
- char format[MaxStringLen];
- ffblk fileInfo;
- unsigned Hour, Minute, Second, Day, Month, Year,
- uDate, uTime;
- TFileOpenDialog* FileDialog;
-
- FileDialog = new TFileOpenDialog(this, *FileData);
-
- if (FileDialog->Execute() == IDOK) {
- // get the file information
- strcpy(selFile, FileData->FileName);
- findfirst(selFile, &fileInfo, FA_ARCH);
- // build the format string
- strcpy(format, "Filename: %s\n");
- strcat(format, "Time Stamp: %02u:%02u:%02u\n");
- strcat(format, "Date Stamp: %02u/%02u/%u\n");
- strcat(format, "Size: %ld bytes\n");
- uTime = (unsigned)fileInfo.ff_ftime;
- // get the seconds
- Second = 2 * (uTime & 0x1f);
- // get the minutes
- Minute = (uTime >> 5) & 0x3f;
- // get the hours
- Hour = (uTime >> 11) & 0x1f;
- uDate = (unsigned)fileInfo.ff_fdate;
- // get the day
- Day = uDate & 0x1f;
- // get the month
- Month = (uDate >> 5) & 0xf;
- // get the year
- Year = (uDate >> 9) & 0x7f;
- sprintf(s, format, fileInfo.ff_name, Hour, Minute, Second,
- Month, Day, Year + 1980U, fileInfo.ff_fsize);
- MessageBox(s, "File Statistics",
- MB_OK | MB_ICONINFORMATION);
- }
- }
-
- void TMainWindow::CMExit()
- {
- Parent->SendMessage(WM_CLOSE);
- }
-
- BOOL TMainWindow::CanClose()
- {
- return MessageBox("Want to close this application?",
- "Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
- }
-
- void TWinApp::InitMainWindow()
- {
- MainWindow = new TFrameWindow(0, "File Statistics",
- new TMainWindow);
- // load the menu resource
- MainWindow->AssignMenu(TResId(IDM_MAINMENU));
- // enable the keyboard handler
- MainWindow->EnableKBHandler();
- }
-
- int OwlMain(int /* argc */, char** /*argv[] */)
- {
- TWinApp app;
- return app.Run();
- }
-
-