Leaked source code of windows server 2003
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.

488 lines
13 KiB

  1. /******************************************************************************
  2. Source File: MiniDriver Developer Studio.CPP
  3. This implements the MFC application object and closely related classes.
  4. Copyright (c) 1997 by Microsoft Corporation. All Rights Reserved.
  5. A Pretty Penny Enterprises Production.
  6. Change History:
  7. 02-03-1997 Bob_Kjelgaard@Prodigy.Net Created it
  8. 03-03-1997 Bob_Kjelgaard@Prodigy.Net Renamed it when the project was
  9. reorganized into an EXE with multiple DLLs
  10. ******************************************************************************/
  11. #include "StdAfx.H"
  12. #include <gpdparse.h>
  13. #include "resource.h"
  14. #include "WSCheck.H"
  15. #include "MiniDev.H"
  16. #include "MainFrm.H"
  17. #include "ChildFrm.H"
  18. #include "ProjView.H"
  19. #include "GTTView.H"
  20. #include "comctrls.h"
  21. #include "FontView.H"
  22. #include "GPDView.H"
  23. #include <CodePage.H>
  24. #include "tips.h"
  25. #include "StrEdit.h"
  26. #include "INFWizrd.h"
  27. #include <string.h>
  28. // for new project and new file
  29. #include "newcomp.h"
  30. #include <Dos.H>
  31. #include <Direct.H>
  32. #ifdef _DEBUG
  33. #define new DEBUG_NEW
  34. #undef THIS_FILE
  35. static char THIS_FILE[] = __FILE__;
  36. #endif
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CMiniDriverStudio
  39. BEGIN_MESSAGE_MAP(CMiniDriverStudio, CWinApp)
  40. ON_COMMAND(CG_IDS_TIPOFTHEDAY, ShowTipOfTheDay)
  41. //{{AFX_MSG_MAP(CMiniDriverStudio)
  42. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  43. ON_UPDATE_COMMAND_UI(ID_FILE_GENERATEMAPS, OnUpdateFileGeneratemaps)
  44. ON_COMMAND(ID_FILE_GENERATEMAPS, OnFileGeneratemaps)
  45. //}}AFX_MSG_MAP
  46. // Standard file based document commands
  47. #if defined(NOPOLLO)
  48. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  49. #else
  50. ON_COMMAND(ID_FILE_NEW, OnFileNew)
  51. #endif
  52. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  53. // Standard print setup command
  54. ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CMiniDriverStudio construction
  58. CMiniDriverStudio::CMiniDriverStudio()
  59. {
  60. m_bOSIsW2KPlus = false ;
  61. m_bExcludeBadCodePages = true ;
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // The one and only CMiniDriverStudio object
  65. static CMiniDriverStudio theApp;
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CMiniDriverStudio initialization
  68. BOOL CMiniDriverStudio::InitInstance() {
  69. // Standard initialization
  70. // If you are not using these features and wish to reduce the size
  71. // of your final executable, you should remove from the following
  72. // the specific initialization routines you do not need.
  73. #ifdef _AFXDLL
  74. Enable3dControls(); // Call this when using MFC in a shared DLL
  75. #else
  76. Enable3dControlsStatic(); // Call this when linking to MFC statically
  77. #endif
  78. SetRegistryKey(_TEXT("Microsoft"));
  79. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  80. // Register the application's document templates. Document templates
  81. // serve as the connection between documents, frame windows and views.
  82. m_pcmdtWorkspace = new CMultiDocTemplate(
  83. IDR_MINIWSTYPE,
  84. RUNTIME_CLASS(CProjectRecord),
  85. RUNTIME_CLASS(CMDIChildWnd),
  86. RUNTIME_CLASS(CProjectView));
  87. AddDocTemplate(m_pcmdtWorkspace);
  88. m_pcmdtGlyphMap = new CMultiDocTemplate(IDR_GLYPHMAP,
  89. RUNTIME_CLASS(CGlyphMapContainer),
  90. RUNTIME_CLASS(CChildFrame),
  91. RUNTIME_CLASS(CGlyphMapView));
  92. AddDocTemplate(m_pcmdtGlyphMap);
  93. m_pcmdtFont = new CMultiDocTemplate(IDR_FONT_VIEWER,
  94. RUNTIME_CLASS(CFontInfoContainer),
  95. RUNTIME_CLASS(CChildFrame),
  96. RUNTIME_CLASS(CFontViewer));
  97. AddDocTemplate(m_pcmdtFont);
  98. m_pcmdtModel = new CMultiDocTemplate(IDR_GPD_VIEWER,
  99. RUNTIME_CLASS(CGPDContainer),
  100. RUNTIME_CLASS(CChildFrame),
  101. RUNTIME_CLASS(CGPDViewer));
  102. AddDocTemplate(m_pcmdtModel);
  103. m_pcmdtWSCheck = new CMultiDocTemplate(IDR_WSCHECK,
  104. RUNTIME_CLASS(CWSCheckDoc),
  105. RUNTIME_CLASS(CChildFrame),
  106. RUNTIME_CLASS(CWSCheckView));
  107. AddDocTemplate(m_pcmdtWSCheck);
  108. m_pcmdtStringEditor = new CMultiDocTemplate(IDR_STRINGEDITOR,
  109. RUNTIME_CLASS(CStringEditorDoc),
  110. RUNTIME_CLASS(CChildFrame),
  111. RUNTIME_CLASS(CStringEditorView));
  112. AddDocTemplate(m_pcmdtStringEditor);
  113. m_pcmdtINFViewer = new CMultiDocTemplate(IDR_INF_FILE_VIEWER,
  114. RUNTIME_CLASS(CINFWizDoc),
  115. RUNTIME_CLASS(CChildFrame),
  116. RUNTIME_CLASS(CINFWizView));
  117. AddDocTemplate(m_pcmdtINFViewer);
  118. m_pcmdtINFCheck = new CMultiDocTemplate(IDR_INFCHECK,
  119. RUNTIME_CLASS(CINFCheckDoc),
  120. RUNTIME_CLASS(CChildFrame),
  121. RUNTIME_CLASS(CINFCheckView));
  122. AddDocTemplate(m_pcmdtINFCheck);
  123. // create main MDI Frame window
  124. CMainFrame* pMainFrame = new CMainFrame;
  125. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  126. return FALSE;
  127. m_pMainWnd = pMainFrame;
  128. // Enable drag/drop open
  129. m_pMainWnd->DragAcceptFiles();
  130. // Enable DDE Execute open
  131. EnableShellOpen();
  132. RegisterShellFileTypes(); //raid 104081 ..Types(TRUE) ->..Types()
  133. // Parse command line for standard shell commands, DDE, file open
  134. CMDTCommandLineInfo cmdInfo ;
  135. ParseCommandLine(cmdInfo) ;
  136. // Turn off New on startup
  137. if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
  138. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ;
  139. // Check to see if the OS check should be skipped. Clean up command line
  140. // related info if the OS check will be skipped.
  141. if (!cmdInfo.m_bCheckOS || !cmdInfo.m_bExcludeBadCodePages)
  142. if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileOpen)
  143. cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ;
  144. m_bExcludeBadCodePages = cmdInfo.m_bExcludeBadCodePages ;
  145. // Dispatch commands specified on the command line
  146. if (!ProcessShellCommand(cmdInfo))
  147. return FALSE ;
  148. // The MDT can only run on Win 98 or NT 4.0+.
  149. if (cmdInfo.m_bCheckOS) {
  150. OSVERSIONINFO osinfo ; // Filled by GetVersionEx()
  151. osinfo.dwOSVersionInfoSize = sizeof(osinfo) ;
  152. GetVersionEx(&osinfo) ;
  153. if (osinfo.dwPlatformId != VER_PLATFORM_WIN32_NT
  154. || osinfo.dwMajorVersion < 5) {
  155. AfxMessageBox(IDS_ReqOSError) ;
  156. return FALSE ;
  157. } ;
  158. m_bOSIsW2KPlus = true ;
  159. } ;
  160. // The main window has been initialized, so show and update it.
  161. pMainFrame->ShowWindow(m_nCmdShow);
  162. pMainFrame->UpdateWindow();
  163. // Get and save the application path
  164. SaveAppPath() ;
  165. // CG: This line inserted by 'Tip of the Day' component.
  166. ShowTipAtStartup();
  167. return TRUE;
  168. }
  169. void CMiniDriverStudio::SaveAppPath()
  170. {
  171. // Get the program's filespec
  172. GetModuleFileName(m_hInstance, m_strAppPath.GetBufferSetLength(256), 256) ;
  173. m_strAppPath.ReleaseBuffer() ;
  174. // Take the file name off the string so that only the path is left.
  175. int npos = npos = m_strAppPath.ReverseFind(_T('\\')) ;
  176. m_strAppPath = m_strAppPath.Left(npos + 1) ;
  177. }
  178. /////////////////////////////////////////////////////////////////////////////
  179. // CMDTCommandLineInfo used to process command line info
  180. CMDTCommandLineInfo::CMDTCommandLineInfo()
  181. {
  182. m_bCheckOS = true ;
  183. m_bExcludeBadCodePages = true ;
  184. }
  185. CMDTCommandLineInfo::~CMDTCommandLineInfo()
  186. {
  187. }
  188. void CMDTCommandLineInfo::ParseParam(LPCTSTR lpszParam, BOOL bFlag, BOOL bLast)
  189. {
  190. if (strcmp(lpszParam, _T("4")) == 0)
  191. m_bCheckOS = false ;
  192. else if (_stricmp(lpszParam, _T("CP")) == 0)
  193. m_bExcludeBadCodePages = false ;
  194. else
  195. CCommandLineInfo::ParseParam(lpszParam, bFlag, bLast) ;
  196. }
  197. /////////////////////////////////////////////////////////////////////////////
  198. // CAboutDlg dialog used for App About
  199. class CAboutDlg : public CDialog {
  200. public:
  201. CAboutDlg();
  202. // Dialog Data
  203. //{{AFX_DATA(CAboutDlg)
  204. enum { IDD = IDD_ABOUTBOX };
  205. //}}AFX_DATA
  206. // ClassWizard generated virtual function overrides
  207. //{{AFX_VIRTUAL(CAboutDlg)
  208. protected:
  209. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  210. //}}AFX_VIRTUAL
  211. // Implementation
  212. protected:
  213. virtual BOOL OnInitDialog();
  214. //{{AFX_MSG(CAboutDlg)
  215. // No message handlers
  216. //}}AFX_MSG
  217. DECLARE_MESSAGE_MAP()
  218. };
  219. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) {
  220. //{{AFX_DATA_INIT(CAboutDlg)
  221. //}}AFX_DATA_INIT
  222. }
  223. void CAboutDlg::DoDataExchange(CDataExchange* pDX) {
  224. CDialog::DoDataExchange(pDX);
  225. //{{AFX_DATA_MAP(CAboutDlg)
  226. //}}AFX_DATA_MAP
  227. }
  228. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  229. //{{AFX_MSG_MAP(CAboutDlg)
  230. // No message handlers
  231. //}}AFX_MSG_MAP
  232. END_MESSAGE_MAP()
  233. // App command to run the dialog
  234. void CMiniDriverStudio::OnAppAbout() {
  235. CAboutDlg aboutDlg;
  236. aboutDlg.DoModal();
  237. }
  238. /////////////////////////////////////////////////////////////////////////////
  239. // CMiniDriverStudio commands
  240. // Handle the File GenerateMaps menu item. We only enable it if there's
  241. // something new to see.
  242. void CMiniDriverStudio::OnUpdateFileGeneratemaps(CCmdUI* pccui) {
  243. CCodePageInformation ccpi;
  244. for (unsigned u = 0; u < ccpi.InstalledCount(); u++)
  245. if (!ccpi.HaveMap(ccpi.Installed(u)))
  246. break;
  247. pccui -> Enable(u < ccpi.InstalledCount());
  248. }
  249. void CMiniDriverStudio::OnFileGeneratemaps() {
  250. CCodePageInformation ccpi;
  251. AfxMessageBox(ccpi.GenerateAllMaps() ? IDS_MapsGenerated : IDS_MapsFailed);
  252. }
  253. void CMiniDriverStudio::ShowTipAtStartup(void) {
  254. // CG: This function added by 'Tip of the Day' component.
  255. CCommandLineInfo cmdInfo;
  256. ParseCommandLine(cmdInfo);
  257. if (cmdInfo.m_bShowSplash) {
  258. CTipOfTheDay dlg;
  259. if (dlg.m_bStartup)
  260. dlg.DoModal();
  261. }
  262. }
  263. void CMiniDriverStudio::ShowTipOfTheDay(void) {
  264. // CG: This function added by 'Tip of the Day' component.
  265. CTipOfTheDay dlg;
  266. dlg.DoModal();
  267. }
  268. #if !defined(NOPOLLO)
  269. /******************************************************************************
  270. CMiniDriverStudio::OnFileNew
  271. This allows you to create a workspace by conversion. Perhaps when the Co.
  272. Jones arrive, this will be invoked as a separate menu item, rather than the
  273. File New item...
  274. ******************************************************************************/
  275. void CMiniDriverStudio::OnFileNew() {
  276. // LPBYTE pfoo = (LPBYTE) 0x2cffe7 ;
  277. CNewComponent cnc(_T("New") ) ;
  278. cnc.DoModal() ;
  279. /* CDocument* pcdWS = m_pcmdtWorkspace -> CreateNewDocument();
  280. if (!pcdWS || !pcdWS -> OnNewDocument()) {
  281. if (pcdWS)
  282. delete pcdWS;
  283. return;
  284. }
  285. m_pcmdtWorkspace -> SetDefaultTitle(pcdWS);
  286. CFrameWnd* pcfw = m_pcmdtWorkspace -> CreateNewFrame(pcdWS, NULL);
  287. if (!pcfw) return;
  288. m_pcmdtWorkspace -> InitialUpdateFrame(pcfw, pcdWS);
  289. */
  290. }
  291. #endif //!defined(NOPOLLO)
  292. // Global Functions go here, saith the Bob...
  293. CMiniDriverStudio& ThisApp() { return theApp; }
  294. CMultiDocTemplate* GlyphMapDocTemplate() {
  295. return theApp.GlyphMapTemplate();
  296. }
  297. CMultiDocTemplate* FontTemplate() { return theApp.FontTemplate(); }
  298. CMultiDocTemplate* GPDTemplate() { return theApp.GPDTemplate(); }
  299. CMultiDocTemplate* WSCheckTemplate() { return theApp.WSCheckTemplate(); }
  300. CMultiDocTemplate* StringEditorTemplate() { return theApp.StringEditorTemplate(); }
  301. CMultiDocTemplate* INFViewerTemplate() { return theApp.INFViewerTemplate(); }
  302. CMultiDocTemplate* INFCheckTemplate() { return theApp.INFCheckTemplate(); }
  303. BOOL LoadFile(LPCTSTR lpstrFile, CStringArray& csaContents) {
  304. CStdioFile csiof;
  305. if (!csiof.Open(lpstrFile,
  306. CFile::modeRead | CFile::shareDenyWrite | CFile::typeText))
  307. return FALSE;
  308. csaContents.RemoveAll();
  309. try {
  310. CString csContents;
  311. while (csiof.ReadString(csContents))
  312. csaContents.Add(csContents);
  313. }
  314. catch(...) {
  315. return FALSE;
  316. }
  317. return TRUE;
  318. }
  319. // CAboutDlg command handlers.
  320. BOOL CAboutDlg::OnInitDialog() {
  321. CDialog::OnInitDialog();
  322. CString csWork, csFormat;
  323. // Fill available memory
  324. MEMORYSTATUS ms = {sizeof(MEMORYSTATUS)};
  325. GlobalMemoryStatus(&ms);
  326. csFormat.LoadString(CG_IDS_PHYSICAL_MEM);
  327. csWork.Format(csFormat, ms.dwAvailPhys / 1024L, ms.dwTotalPhys / 1024L);
  328. SetDlgItemText(IDC_PhysicalMemory, csWork);
  329. // Fill disk free information
  330. struct _diskfree_t diskfree;
  331. int nDrive = _getdrive(); // use current default drive
  332. if (_getdiskfree(nDrive, &diskfree) == 0) {
  333. csFormat.LoadString(CG_IDS_DISK_SPACE);
  334. csWork.Format(csFormat, (DWORD)diskfree.avail_clusters *
  335. (DWORD)diskfree.sectors_per_cluster *
  336. (DWORD)diskfree.bytes_per_sector / (DWORD)1024L,
  337. nDrive - 1 + _T('A'));
  338. }
  339. else
  340. csWork.LoadString(CG_IDS_DISK_SPACE_UNAVAIL);
  341. SetDlgItemText(IDC_FreeDiskSpace, csWork);
  342. csWork.Format(_TEXT("Code Pages: ANSI %u OEM %u"), GetACP(), GetOEMCP());
  343. SetDlgItemText(IDC_CodePages, csWork);
  344. return TRUE;
  345. }
  346. // This code is needed because of the references to the following functions
  347. // and variable in DEBUG.H.
  348. #ifdef DBG
  349. ULONG _cdecl DbgPrint(PCSTR, ...)
  350. {
  351. return 0 ;
  352. }
  353. VOID DbgBreakPoint(VOID)
  354. {
  355. }
  356. PCSTR StripDirPrefixA(PCSTR pstrFilename)
  357. {
  358. return "" ;
  359. }
  360. int giDebugLevel ;
  361. #endif