Windows NT 4.0 source code leak
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.

260 lines
6.0 KiB

4 years ago
  1. // dbwin32.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #define CMAPUSER
  5. #include "dbwin32.h"
  6. #include "mainfrm.h"
  7. #include "dbwindoc.h"
  8. #include "dbwinvw.h"
  9. #ifdef _DEBUG
  10. #undef THIS_FILE
  11. static char BASED_CODE THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CDbwin32App
  15. BEGIN_MESSAGE_MAP(CDbwin32App, CWinApp)
  16. //{{AFX_MSG_MAP(CDbwin32App)
  17. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  18. ON_COMMAND(ID_WINDOW_TILEHORIZONTALY,OnTileHorz)
  19. ON_COMMAND(ID_WINDOW_TILEVERTICALLY,OnTileVert)
  20. ON_COMMAND(ID_WINDOW_CASCADE,OnCascade)
  21. ON_COMMAND(ID_WINDOW_ARANGEICONS,OnArrange)
  22. // NOTE - the ClassWizard will add and remove mapping macros here.
  23. // DO NOT EDIT what you see in these blocks of generated code!
  24. //}}AFX_MSG_MAP
  25. // Standard file based document commands
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CDbwin32App construction
  29. CDbwin32App::CDbwin32App()
  30. {
  31. // TODO: add construction code here,
  32. // Place all significant initialization in InitInstance
  33. }
  34. /////////////////////////////////////////////////////////////////////////////
  35. // The one and only CDbwin32App object
  36. CDbwin32App theApp;
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CDbwin32App initialization
  39. BOOL CDbwin32App::InitInstance()
  40. {
  41. // Standard initialization
  42. // If you are not using these features and wish to reduce the size
  43. // of your final executable, you should remove from the following
  44. // the specific initialization routines you do not need.
  45. Enable3dControls();
  46. LoadStdProfileSettings(); // Load standard INI file options (including MRU)
  47. // Register the application's document templates. Document templates
  48. // serve as the connection between documents, frame windows and views.
  49. CMultiDocTemplate* pDocTemplate;
  50. pDocTemplate = new CMultiDocTemplate(
  51. IDR_DBWIN3TYPE,
  52. RUNTIME_CLASS(CDbwin32Doc),
  53. RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame
  54. RUNTIME_CLASS(CDbwin32View));
  55. AddDocTemplate(pDocTemplate);
  56. // create main MDI Frame window
  57. CMainFrame* pMainFrame = new CMainFrame;
  58. if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
  59. return FALSE;
  60. m_pMainWnd = pMainFrame;
  61. // The main window has been initialized, so show and update it.
  62. pMainFrame->ShowWindow(m_nCmdShow);
  63. pMainFrame->UpdateWindow();
  64. InitializeDbWin();
  65. return TRUE;
  66. }
  67. /////////////////////////////////////////////////////////////////////////////
  68. // CAboutDlg dialog used for App About
  69. class CAboutDlg : public CDialog
  70. {
  71. public:
  72. CAboutDlg();
  73. // Dialog Data
  74. //{{AFX_DATA(CAboutDlg)
  75. enum { IDD = IDD_ABOUTBOX };
  76. //}}AFX_DATA
  77. // Implementation
  78. protected:
  79. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  80. //{{AFX_MSG(CAboutDlg)
  81. // No message handlers
  82. //}}AFX_MSG
  83. DECLARE_MESSAGE_MAP()
  84. };
  85. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  86. {
  87. //{{AFX_DATA_INIT(CAboutDlg)
  88. //}}AFX_DATA_INIT
  89. }
  90. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  91. {
  92. CDialog::DoDataExchange(pDX);
  93. //{{AFX_DATA_MAP(CAboutDlg)
  94. //}}AFX_DATA_MAP
  95. }
  96. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  97. //{{AFX_MSG_MAP(CAboutDlg)
  98. // No message handlers
  99. //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101. // App command to run the dialog
  102. void CDbwin32App::OnAppAbout()
  103. {
  104. CAboutDlg aboutDlg;
  105. aboutDlg.DoModal();
  106. }
  107. void CDbwin32App::OnTileHorz()
  108. {
  109. ((CMDIFrameWnd*)m_pMainWnd)->MDITile( MDITILE_HORIZONTAL );
  110. }
  111. void CDbwin32App::OnTileVert()
  112. {
  113. ((CMDIFrameWnd*)m_pMainWnd)->MDITile( MDITILE_VERTICAL );
  114. }
  115. void CDbwin32App::OnCascade()
  116. {
  117. ((CMDIFrameWnd*)m_pMainWnd)->MDICascade( MDITILE_SKIPDISABLED );
  118. }
  119. void CDbwin32App::OnArrange()
  120. {
  121. ((CMDIFrameWnd*)m_pMainWnd)->MDIIconArrange();
  122. }
  123. /////////////////////////////////////////////////////////////////////////////
  124. // CDbwin32App commands
  125. BOOL
  126. CDbwin32App::OnIdle(
  127. LONG lCount
  128. )
  129. {
  130. WinIo *OutputWindow;
  131. if (WaitForSingleObject( ReadyEvent, 0 ) != WAIT_OBJECT_0) {
  132. return TRUE;
  133. }
  134. if (!WinMap.Lookup( *pThisPid, OutputWindow )) {
  135. CHAR szTitle[64];
  136. sprintf( szTitle, "Output Window for PID=%d", *pThisPid );
  137. OutputWindow = new WinIo( szTitle );
  138. OutputWindow->Initialize();
  139. WinMap.SetAt( *pThisPid, OutputWindow );
  140. }
  141. if (LastPid != *pThisPid) {
  142. LastPid = *pThisPid;
  143. if (!DidCR) {
  144. OutputWindow->printf( "\n" );
  145. DidCR = TRUE;
  146. }
  147. }
  148. OutputWindow->printf( "%s", String );
  149. DidCR = (*String && (String[strlen(String) - 1] == '\n'));
  150. SetEvent(AckEvent);
  151. return TRUE;
  152. }
  153. DWORD
  154. CDbwin32App::InitializeDbWin(
  155. VOID
  156. )
  157. {
  158. AckEvent = CreateEvent(
  159. NULL,
  160. FALSE,
  161. FALSE,
  162. "DBWIN_BUFFER_READY"
  163. );
  164. if (!AckEvent) {
  165. return GetLastError();
  166. }
  167. if (GetLastError() == ERROR_ALREADY_EXISTS) {
  168. return GetLastError();
  169. }
  170. ReadyEvent = CreateEvent(
  171. NULL,
  172. FALSE,
  173. FALSE,
  174. "DBWIN_DATA_READY"
  175. );
  176. if (!ReadyEvent) {
  177. return GetLastError();
  178. }
  179. SharedFile = CreateFileMapping(
  180. (HANDLE)-1,
  181. NULL,
  182. PAGE_READWRITE,
  183. 0,
  184. 4096,
  185. "DBWIN_BUFFER"
  186. );
  187. if (!SharedFile) {
  188. return GetLastError();
  189. }
  190. SharedMem = MapViewOfFile(
  191. SharedFile,
  192. FILE_MAP_READ,
  193. 0,
  194. 0,
  195. 512
  196. );
  197. if (!SharedMem) {
  198. return GetLastError();
  199. }
  200. String = (LPSTR)SharedMem + sizeof(DWORD);
  201. pThisPid = (LPDWORD)SharedMem;
  202. LastPid = 0xffffffff;
  203. DidCR = TRUE;
  204. SetEvent( AckEvent );
  205. return 0;
  206. }