home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 January / Pcwk0198.iso / Zadarmo / HEXVIEW / SRC / HEXVIEW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-03  |  5.7 KB  |  213 lines

  1. /* ---------------------------------------------------------------------------
  2.  
  3.    This code can be used as you wish but without warranties as to performance 
  4.    of merchantability or any other warranties whether expressed or implied.
  5.    
  6.      Written by Mike Funduc, Funduc Software Inc. 8/1/96
  7.  
  8.      To download the code and more useful utilities (including Search and
  9.      Replace for Windows 95/NT, 3.1x) go to:
  10.      http://home.sprynet.com/sprynet/funduc  or
  11.      http://ourworld.compuserve.com/homepages/funduc
  12.  
  13. ----------------------------------------------------------------------------*/
  14.  
  15. // hexview.cpp : Defines the class behaviors for the application.
  16. //
  17.  
  18. #include "stdafx.h"
  19. #include "hexview.h"
  20.  
  21. #include "MainFrm.h"
  22. #include "ChildFrm.h"
  23. #include "hexviewDoc.h"
  24. #include "hexviewView.h"
  25.  
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31.  
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CHexviewApp
  34.  
  35. BEGIN_MESSAGE_MAP(CHexviewApp, CWinApp)
  36.     //{{AFX_MSG_MAP(CHexviewApp)
  37.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  38.         // NOTE - the ClassWizard will add and remove mapping macros here.
  39.         //    DO NOT EDIT what you see in these blocks of generated code!
  40.     //}}AFX_MSG_MAP
  41.     // Standard file based document commands
  42.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  43.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  44.     // Standard print setup command
  45.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  46. END_MESSAGE_MAP()
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // CHexviewApp construction
  50.  
  51. CHexviewApp::CHexviewApp()
  52. {
  53.     m_lStartOffset = -1;
  54.     m_lEndOffset = -1;
  55. }
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // The one and only CHexviewApp object
  59.  
  60. CHexviewApp theApp;
  61.  
  62. CHexviewApp *HexGetApp() 
  63.     return (CHexviewApp *)AfxGetApp(); 
  64. }          
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CHexviewApp initialization
  68.  
  69. BOOL CHexviewApp::InitInstance()
  70. {
  71.     // Standard initialization
  72.     // If you are not using these features and wish to reduce the size
  73.     //  of your final executable, you should remove from the following
  74.     //  the specific initialization routines you do not need.
  75.  
  76. #ifdef _AFXDLL
  77.     Enable3dControls();            // Call this when using MFC in a shared DLL
  78. #else
  79.     Enable3dControlsStatic();    // Call this when linking to MFC statically
  80. #endif
  81.  
  82.     LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  83.  
  84.     // Register the application's document templates.  Document templates
  85.     //  serve as the connection between documents, frame windows and views.
  86.  
  87.     CMultiDocTemplate* pDocTemplate;
  88.     pDocTemplate = new CMultiDocTemplate(
  89.         IDR_HEXVWTYPE,
  90.         RUNTIME_CLASS(CHexviewDoc),
  91.         RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  92.         RUNTIME_CLASS(CHexviewView));
  93.     AddDocTemplate(pDocTemplate);
  94.  
  95.     // create main MDI Frame window
  96.     CMainFrame* pMainFrame = new CMainFrame;
  97.     if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  98.         return FALSE;
  99.     m_pMainWnd = pMainFrame;
  100.  
  101.     // Parse command line for standard shell commands, DDE, file open
  102.     CHexCommandLine cmdInfo;
  103.     ParseCommandLine(cmdInfo);
  104.     m_lStartOffset = cmdInfo.m_lStartOffset;
  105.     m_lEndOffset = cmdInfo.m_lEndOffset;
  106.  
  107.     if (m_lStartOffset == -1)   // Show about box
  108.         m_pMainWnd->PostMessage(WM_COMMAND, ID_APP_ABOUT); 
  109.  
  110.     // DON'T display a new MDI child window during startup!!!
  111.     if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
  112.         cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
  113.     // Dispatch commands specified on the command line
  114.     if (!ProcessShellCommand(cmdInfo))
  115.         return FALSE;
  116.  
  117.     // The main window has been initialized, so show and update it.
  118.     pMainFrame->ShowWindow(m_nCmdShow);
  119.     pMainFrame->UpdateWindow();
  120.  
  121.     return TRUE;
  122. }
  123.  
  124. void CHexCommandLine::ParseParam( LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
  125. {
  126.     char *stopval;
  127.     switch (lpszParam[0])
  128.     {
  129.         case 's':  // Start Offset
  130.         case 'S':
  131.             if (bFlag)
  132.                 m_lStartOffset = strtol(lpszParam + 1, &stopval, 10);
  133.         break;
  134.  
  135.         case 'e':  // End Offset
  136.         case 'E':
  137.             if (bFlag)
  138.                 m_lEndOffset = strtol(lpszParam + 1, &stopval, 10);
  139.         break;
  140.  
  141.         default:
  142.         break;
  143.     }
  144.     CCommandLineInfo::ParseParam( lpszParam, bFlag, bLast);
  145. }
  146. /////////////////////////////////////////////////////////////////////////////
  147. // CAboutDlg dialog used for App About
  148.  
  149. class CAboutDlg : public CDialog
  150. {
  151. public:
  152.     CAboutDlg();
  153.  
  154. // Dialog Data
  155.     //{{AFX_DATA(CAboutDlg)
  156.     enum { IDD = IDD_ABOUTBOX };
  157.     //}}AFX_DATA
  158.  
  159.     // ClassWizard generated virtual function overrides
  160.     //{{AFX_VIRTUAL(CAboutDlg)
  161.     protected:
  162.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  163.     //}}AFX_VIRTUAL
  164.  
  165. // Implementation
  166. protected:
  167.     //{{AFX_MSG(CAboutDlg)
  168.         // No message handlers
  169.     //}}AFX_MSG
  170.     DECLARE_MESSAGE_MAP()
  171. };
  172.  
  173. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  174. {
  175.     //{{AFX_DATA_INIT(CAboutDlg)
  176.     //}}AFX_DATA_INIT
  177. }
  178.  
  179. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  180. {
  181.     CDialog::DoDataExchange(pDX);
  182.     //{{AFX_DATA_MAP(CAboutDlg)
  183.     //}}AFX_DATA_MAP
  184. }
  185.  
  186. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  187.     //{{AFX_MSG_MAP(CAboutDlg)
  188.         // No message handlers
  189.     //}}AFX_MSG_MAP
  190. END_MESSAGE_MAP()
  191.  
  192. // App command to run the dialog
  193. void CHexviewApp::OnAppAbout()
  194. {
  195.     CAboutDlg aboutDlg;
  196.     aboutDlg.DoModal();
  197. }
  198.  
  199. /////////////////////////////////////////////////////////////////////////////
  200. // CHexviewApp commands
  201. void CHexviewApp::GetOffsets(long &lStartOffset, long &lEndOffset)
  202. {
  203.     if (m_lEndOffset > m_lStartOffset)
  204.     {
  205.         lStartOffset = m_lStartOffset;
  206.         lEndOffset = m_lEndOffset;
  207.     }
  208.     m_lStartOffset = -1;
  209.     m_lEndOffset = -1;
  210. }
  211.  
  212.