noxstring.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // noxstring.cpp : Defines the class behaviors for the application.
  19. //
  20. #include "stdafx.h"
  21. #include "noxstring.h"
  22. #include "noxstringDlg.h"
  23. #include "xlstuff.h"
  24. #include <direct.h>
  25. #include <stdlib.h>
  26. #include <stdio.h>
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. char AppTitle[200];
  33. CNoxstringDlg *MainDLG = NULL;
  34. static char *AppName = "Babylon:";
  35. static int AlreadyRunning( void );
  36. static HWND FoundWindow = NULL;
  37. /////////////////////////////////////////////////////////////////////////////
  38. // CNoxstringApp
  39. BEGIN_MESSAGE_MAP(CNoxstringApp, CWinApp)
  40. //{{AFX_MSG_MAP(CNoxstringApp)
  41. //}}AFX_MSG_MAP
  42. ON_COMMAND(ID_HELP, CWinApp::OnHelp)
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CNoxstringApp construction
  46. CNoxstringApp::CNoxstringApp()
  47. {
  48. // TODO: add construction code here,
  49. // Place all significant initialization in InitInstance
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // The one and only CNoxstringApp object
  53. CNoxstringApp theApp;
  54. TransDB *NoxstrDB = NULL;
  55. TransDB *MainDB = NULL;
  56. char NoxstrFilename[_MAX_PATH];
  57. char MainXLSFilename[_MAX_PATH];
  58. char DialogPath[_MAX_PATH];
  59. char RootPath[_MAX_PATH];
  60. LangID CurrentLanguage = LANGID_US;
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CNoxstringApp initialization
  63. BOOL CNoxstringApp::InitInstance()
  64. {
  65. // Initialize OLE libraries
  66. if (!AfxOleInit())
  67. {
  68. AfxMessageBox(IDP_OLE_INIT_FAILED);
  69. return FALSE;
  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. #ifdef _AFXDLL
  76. Enable3dControls(); // Call this when using MFC in a shared DLL
  77. #else
  78. Enable3dControlsStatic(); // Call this when linking to MFC statically
  79. #endif
  80. // Parse the command line to see if launched as OLE server
  81. if (RunEmbedded() || RunAutomated())
  82. {
  83. // Register all OLE server (factories) as running. This enables the
  84. // OLE libraries to create objects from other applications.
  85. COleTemplateServer::RegisterAll();
  86. }
  87. else
  88. {
  89. // When a server application is launched stand-alone, it is a good idea
  90. // to update the system registry in case it has been damaged.
  91. COleObjectFactory::UpdateRegistryAll();
  92. }
  93. MainDB = new TransDB ( "Main" );
  94. NoxstrDB = new TransDB ( "Generals.str" );
  95. MainDB->EnableIDs ();
  96. if ( !AfxInitRichEdit( ) )
  97. {
  98. AfxMessageBox ( "Error initializing Rich Edit" );
  99. }
  100. sprintf (AppTitle, "%s Built on %s - %s", AppName, __DATE__, __TIME__ );
  101. if ( !_getcwd( RootPath, _MAX_PATH ) )
  102. {
  103. AfxMessageBox ( "Failed to obtain current working directoy!\n\n Set directoy path to \"c:\\Babylon\"." );
  104. strcpy ( (char *) RootPath, "c:\\Babylon" );
  105. }
  106. strlwr ( RootPath );
  107. strcpy ( (char *) NoxstrFilename, RootPath );
  108. strcat ( (char *) NoxstrFilename, "\\Data\\Generals.str" );
  109. strcpy ( (char *) MainXLSFilename, RootPath );
  110. strcat ( (char *) MainXLSFilename, "\\Data\\main.db" );
  111. strcpy ( (char *) DialogPath, RootPath );
  112. strcat ( (char *) DialogPath, "\\dialog" );
  113. if ( AlreadyRunning () )
  114. {
  115. if ( FoundWindow )
  116. {
  117. SetForegroundWindow ( FoundWindow );
  118. }
  119. }
  120. else if ( OpenExcel ( ) )
  121. {
  122. CNoxstringDlg dlg;
  123. m_pMainWnd = &dlg;
  124. MainDLG = &dlg;
  125. int nResponse = dlg.DoModal();
  126. CloseExcel ();
  127. }
  128. delete NoxstrDB ;
  129. delete MainDB;
  130. // Since the dialog has been closed, return FALSE so that we exit the
  131. // application, rather than start the application's message pump.
  132. return FALSE;
  133. }
  134. //DEL void CNoxstringApp::OnDropFiles(HDROP hDropInfo)
  135. //DEL {
  136. //DEL // TODO: Add your message handler code here and/or call default
  137. //DEL
  138. //DEL CWinApp::OnDropFiles(hDropInfo);
  139. //DEL }
  140. static BOOL CALLBACK EnumAllWindowsProc(HWND hWnd, LPARAM lParam);
  141. static BOOL CALLBACK EnumAllWindowsProcExact(HWND hWnd, LPARAM lParam);
  142. static char *szSearchTitle;
  143. static int AlreadyRunning( void )
  144. {
  145. BOOL found = FALSE;
  146. szSearchTitle = AppName;
  147. EnumWindows((WNDENUMPROC) EnumAllWindowsProcExact, (LPARAM) &found);
  148. return found;
  149. }
  150. //--------------------------------------------------------------------------------
  151. int ExcelRunning( void )
  152. {
  153. BOOL found = FALSE;
  154. szSearchTitle = "Microsoft Excel";
  155. EnumWindows((WNDENUMPROC) EnumAllWindowsProc, (LPARAM) &found);
  156. return found;
  157. }
  158. //--------------------------------------------------------------------------------
  159. BOOL CALLBACK EnumAllWindowsProc(HWND hWnd, LPARAM lParam)
  160. {
  161. char szText[256];
  162. GetWindowText(hWnd, szText, sizeof(szText));
  163. if ( strstr(szText, szSearchTitle))
  164. {
  165. * (BOOL *) lParam = TRUE;
  166. FoundWindow = hWnd;
  167. return FALSE;
  168. }
  169. FoundWindow = NULL;
  170. return TRUE;
  171. }
  172. //--------------------------------------------------------------------------------
  173. BOOL CALLBACK EnumAllWindowsProcExact(HWND hWnd, LPARAM lParam)
  174. {
  175. char szText[256];
  176. GetWindowText(hWnd, szText, sizeof(szText));
  177. if ( !strncmp (szText, szSearchTitle, strlen ( szSearchTitle)))
  178. {
  179. * (BOOL *) lParam = TRUE;
  180. FoundWindow = hWnd;
  181. return FALSE;
  182. }
  183. FoundWindow = NULL;
  184. return TRUE;
  185. }