Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

246 lines
7.1 KiB

  1. // ncbrowse.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "ncbrowse.h"
  5. #include "MainFrm.h"
  6. #include "ChildFrm.h"
  7. #include "ncbrowseDoc.h"
  8. #include "LeftView.h"
  9. #include "SplitterView.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CNcbrowseApp
  17. BEGIN_MESSAGE_MAP(CNcbrowseApp, CWinApp)
  18. //{{AFX_MSG_MAP(CNcbrowseApp)
  19. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  20. // NOTE - the ClassWizard will add and remove mapping macros here.
  21. // DO NOT EDIT what you see in these blocks of generated code!
  22. //}}AFX_MSG_MAP
  23. // Standard file based document commands
  24. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  25. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  26. // Standard print setup command
  27. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  28. END_MESSAGE_MAP()
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CNcbrowseApp construction
  31. CNcbrowseApp::CNcbrowseApp()
  32. {
  33. // TODO: add construction code here,
  34. // Place all significant initialization in InitInstance
  35. }
  36. /////////////////////////////////////////////////////////////////////////////
  37. // The one and only CNcbrowseApp object
  38. CNcbrowseApp theApp;
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CNcbrowseApp initialization
  41. class CNCMultiDocTemplate : public CMultiDocTemplate
  42. {
  43. public:
  44. CNCMultiDocTemplate(UINT nIDResource, CRuntimeClass* pDocClass, CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass) :
  45. CMultiDocTemplate(nIDResource, pDocClass, pFrameClass, pViewClass) {}
  46. BOOL GetDocString(CString& rString,enum DocStringIndex i) const
  47. {
  48. CString strTemp,strLeft,strRight;
  49. int nFindPos;
  50. AfxExtractSubString(strTemp, m_strDocStrings, (int)i);
  51. if(i == CDocTemplate::filterExt) {
  52. nFindPos=strTemp.Find(';');
  53. if(-1 != nFindPos) {
  54. //string contains two extensions
  55. strLeft=strTemp.Left(nFindPos+1);
  56. strRight="*"+strTemp.Right(lstrlen((LPCTSTR)strTemp)-nFindPos-1);
  57. strTemp=strLeft+strRight;
  58. }
  59. }
  60. rString = strTemp;
  61. return TRUE;
  62. }
  63. CDocTemplate::Confidence MatchDocType(const char* pszPathName, CDocument*& rpDocMatch)
  64. {
  65. ASSERT(pszPathName != NULL);
  66. rpDocMatch = NULL;
  67. // go through all documents
  68. POSITION pos = GetFirstDocPosition();
  69. while (pos != NULL)
  70. {
  71. CDocument* pDoc = GetNextDoc(pos);
  72. if (pDoc->GetPathName() == pszPathName) {
  73. // already open
  74. rpDocMatch = pDoc;
  75. return yesAlreadyOpen;
  76. }
  77. } // end while
  78. // see if it matches either suffix
  79. CString strFilterExt;
  80. if (GetDocString(strFilterExt, CDocTemplate::filterExt) &&
  81. !strFilterExt.IsEmpty())
  82. {
  83. // see if extension matches
  84. ASSERT(strFilterExt[0] == '.');
  85. CString ext1,ext2;
  86. int nDot = CString(pszPathName).ReverseFind('.');
  87. const char* pszDot = nDot < 0 ? NULL : pszPathName + nDot;
  88. int nSemi = strFilterExt.Find(';');
  89. if(-1 != nSemi) {
  90. // string contains two extensions
  91. ext1=strFilterExt.Left(nSemi);
  92. ext2=strFilterExt.Mid(nSemi+2);
  93. // check for a match against either extension
  94. if (nDot >= 0 && (lstrcmpi((LPCTSTR)pszPathName+nDot, ext1) == 0
  95. || lstrcmpi((LPCTSTR)pszPathName+nDot,ext2) ==0))
  96. return yesAttemptNative; // extension matches
  97. }
  98. else
  99. { // string contains a single extension
  100. if (nDot >= 0 && (lstrcmpi((LPCTSTR)pszPathName+nDot,
  101. strFilterExt)==0))
  102. return yesAttemptNative; // extension matches
  103. }
  104. }
  105. return yesAttemptForeign; //unknown document type
  106. }
  107. };
  108. BOOL CNcbrowseApp::InitInstance()
  109. {
  110. AfxEnableControlContainer();
  111. // Standard initialization
  112. // If you are not using these features and wish to reduce the size
  113. // of your final executable, you should remove from the following
  114. // the specific initialization routines you do not need.
  115. #ifdef _AFXDLL
  116. Enable3dControls(); // Call this when using MFC in a shared DLL
  117. #else
  118. Enable3dControlsStatic(); // Call this when linking to MFC statically
  119. #endif
  120. // Change the registry key under which our settings are stored.
  121. // TODO: You should modify this string to be something appropriate
  122. // such as the name of your company or organization.
  123. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  124. LoadStdProfileSettings(6); // Load standard INI file options (including MRU)
  125. // Register the application's document templates. Document templates
  126. // serve as the connection between documents, frame windows and views.
  127. CMultiDocTemplate* pDocTemplate;
  128. pDocTemplate = new CMultiDocTemplate(
  129. IDR_NCSPEWTYPE,
  130. RUNTIME_CLASS(CNcbrowseDoc),
  131. RUNTIME_CLASS(CChildFrame), // custom MDI child frame
  132. RUNTIME_CLASS(CSplitterView));
  133. AddDocTemplate(pDocTemplate);
  134. // create main MDI Frame window
  135. CMainFrame* pMainFrame = new CMainFrame;
  136. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  137. {
  138. ASSERT("Could not load main frame");
  139. return FALSE;
  140. }
  141. m_pMainWnd = pMainFrame;
  142. // Enable drag/drop open
  143. m_pMainWnd->DragAcceptFiles();
  144. // Enable DDE Execute open
  145. EnableShellOpen();
  146. RegisterShellFileTypes(TRUE);
  147. // Parse command line for standard shell commands, DDE, file open
  148. CCommandLineInfo cmdInfo;
  149. ParseCommandLine(cmdInfo);
  150. // Dispatch commands specified on the command line
  151. if (!ProcessShellCommand(cmdInfo))
  152. return FALSE;
  153. // The main window has been initialized, so show and update it.
  154. pMainFrame->ShowWindow(m_nCmdShow);
  155. pMainFrame->UpdateWindow();
  156. return TRUE;
  157. }
  158. /////////////////////////////////////////////////////////////////////////////
  159. // CAboutDlg dialog used for App About
  160. class CAboutDlg : public CDialog
  161. {
  162. public:
  163. CAboutDlg();
  164. // Dialog Data
  165. //{{AFX_DATA(CAboutDlg)
  166. enum { IDD = IDD_ABOUTBOX };
  167. //}}AFX_DATA
  168. // ClassWizard generated virtual function overrides
  169. //{{AFX_VIRTUAL(CAboutDlg)
  170. protected:
  171. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  172. //}}AFX_VIRTUAL
  173. // Implementation
  174. protected:
  175. //{{AFX_MSG(CAboutDlg)
  176. // No message handlers
  177. //}}AFX_MSG
  178. DECLARE_MESSAGE_MAP()
  179. };
  180. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  181. {
  182. //{{AFX_DATA_INIT(CAboutDlg)
  183. //}}AFX_DATA_INIT
  184. }
  185. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  186. {
  187. CDialog::DoDataExchange(pDX);
  188. //{{AFX_DATA_MAP(CAboutDlg)
  189. //}}AFX_DATA_MAP
  190. }
  191. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  192. //{{AFX_MSG_MAP(CAboutDlg)
  193. // No message handlers
  194. //}}AFX_MSG_MAP
  195. END_MESSAGE_MAP()
  196. // App command to run the dialog
  197. void CNcbrowseApp::OnAppAbout()
  198. {
  199. CAboutDlg aboutDlg;
  200. aboutDlg.DoModal();
  201. }
  202. /////////////////////////////////////////////////////////////////////////////
  203. // CNcbrowseApp message handlers