home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / general / npp / np.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  4KB  |  152 lines

  1. // np.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. //
  13.  
  14. #include "stdafx.h"
  15. #include "np.h"
  16. #include "combobar.h"
  17. #include "mainfrm.h"
  18. #include "npdoc.h"
  19. #include "npview.h"
  20. #include <locale.h>
  21.  
  22. #ifdef _DEBUG
  23. #undef THIS_FILE
  24. static char BASED_CODE THIS_FILE[] = __FILE__;
  25. #endif
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CNotepadApp
  29.  
  30. BEGIN_MESSAGE_MAP(CNotepadApp, CWinApp)
  31.     //{{AFX_MSG_MAP(CNotepadApp)
  32.     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  33.     //}}AFX_MSG_MAP
  34.     // Standard file based document commands
  35.     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  36.     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  37.     // Standard print setup command
  38.     ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  39. END_MESSAGE_MAP()
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CNotepadApp construction
  43.  
  44. CNotepadApp::CNotepadApp()
  45. {
  46. }
  47.  
  48. /////////////////////////////////////////////////////////////////////////////
  49. // The one and only CNotepadApp object
  50.  
  51. CNotepadApp theApp;
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CNotepadApp initialization
  55.  
  56. BOOL CNotepadApp::InitInstance()
  57. {
  58.     _tsetlocale(LC_ALL, _T(""));
  59.  
  60.     // Standard initialization
  61.  
  62.     Enable3dControls();
  63.  
  64.     LoadStdProfileSettings(8);  // Load standard INI file options (including MRU)
  65.  
  66.     // Register document templates
  67.  
  68.     CSingleDocTemplate* pDocTemplate;
  69.     pDocTemplate = new CSingleDocTemplate(
  70.         IDR_MAINFRAME,
  71.         RUNTIME_CLASS(CNotepadDoc),
  72.         RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  73.         RUNTIME_CLASS(CNotepadView));
  74.     AddDocTemplate(pDocTemplate);
  75.  
  76.     // open file specified on command line
  77.     if (m_lpCmdLine[0] == 0)
  78.         OnFileNew();
  79.     else
  80.         OpenDocumentFile(m_lpCmdLine);
  81.  
  82.     return TRUE;
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CAboutDlg dialog used for App About
  87.  
  88. class CAboutDlg : public CDialog
  89. {
  90. public:
  91.     CAboutDlg();
  92.  
  93. // Dialog Data
  94.     //{{AFX_DATA(CAboutDlg)
  95.     enum { IDD = IDD_ABOUTBOX };
  96.     //}}AFX_DATA
  97.  
  98. // Implementation
  99. protected:
  100.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  101.     //{{AFX_MSG(CAboutDlg)
  102.         // No message handlers
  103.     //}}AFX_MSG
  104.     DECLARE_MESSAGE_MAP()
  105. };
  106.  
  107. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  108. {
  109.     //{{AFX_DATA_INIT(CAboutDlg)
  110.     //}}AFX_DATA_INIT
  111. }
  112.  
  113. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  114. {
  115.     CDialog::DoDataExchange(pDX);
  116.     //{{AFX_DATA_MAP(CAboutDlg)
  117.     //}}AFX_DATA_MAP
  118. }
  119.  
  120. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  121.     //{{AFX_MSG_MAP(CAboutDlg)
  122.         // No message handlers
  123.     //}}AFX_MSG_MAP
  124. END_MESSAGE_MAP()
  125.  
  126. // App command to run the dialog
  127. void CNotepadApp::OnAppAbout()
  128. {
  129.     CAboutDlg aboutDlg;
  130.     aboutDlg.DoModal();
  131. }
  132.  
  133. /////////////////////////////////////////////////////////////////////////////
  134. // CNotepadApp commands
  135.  
  136. BOOL CNotepadApp::OnIdle(LONG lCount)
  137. {
  138.     CMainFrame* pFrame = (CMainFrame*) AfxGetMainWnd();
  139.     CStatusBar* pStatusBar = (CStatusBar*) pFrame->GetDescendantWindow(AFX_IDW_STATUS_BAR);
  140.  
  141.     if(pStatusBar)
  142.     {
  143.         CEdit &edit = ((CEditView*)pFrame->GetActiveView())->GetEditCtrl();
  144.         CString s1;
  145.         UINT i = edit.LineFromChar();
  146.         s1.Format(_T("Ln %u"), ++i);
  147.         pStatusBar->SetPaneText(pStatusBar->CommandToIndex(ID_INDICATOR_LINE), s1);
  148.     }
  149.  
  150.     return CWinApp::OnIdle(lCount);
  151. }
  152.