WINMAIN.CPP 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /*
  2. ** Command & Conquer Renegade(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. /***********************************************************************************************
  19. *** Confidential - Westwood Studios ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : Commando *
  23. * *
  24. * $Archive:: /Commando/Code/Commando/WINMAIN.CPP $*
  25. * *
  26. * $Author:: Steve_t $*
  27. * *
  28. * $Modtime:: 2/17/02 11:08a $*
  29. * *
  30. * $Revision:: 85 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * WinMain -- Win32 Program Entry Point! *
  35. * WIN_resize -- Surrender-required function which resizes the main window *
  36. * WIN_set_fullscreen -- Surrender-required function for toggling full-screen mode *
  37. * Main_Window_Proc -- Windows Proc for the main game window *
  38. * Create_Main_Window -- Creates the main game window *
  39. * On_Focus_Loss -- this function is called when the application loses focus *
  40. * On_Focus_Restore -- This function is called when the application gets focus *
  41. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  42. #include "winmain.h"
  43. #define _WIN32_WINDOWS 0x0401
  44. #include "win.h"
  45. #include "resource.h"
  46. #include "WW3D.H"
  47. #include "miscutil.h"
  48. #include "input.h"
  49. #include "useroptions.h"
  50. #include "WWAudio.H"
  51. #include "FFactory.H"
  52. #include "debug.h"
  53. #include "verchk.h"
  54. #include "devoptions.h"
  55. #include "dialogmgr.h"
  56. #include "renegadedialogmgr.h"
  57. #include "except.h"
  58. #include "DirectInput.h"
  59. #include "WebBrowser.h"
  60. #include "wwmemlog.h"
  61. #include "datasafe.h"
  62. #include "combatgmode.h"
  63. #include "registry.h"
  64. #include "init.h"
  65. #include "_globals.h"
  66. #include "buildnum.h"
  67. #include "dx8wrapper.h"
  68. #include "formconv.h"
  69. #include "autostart.h"
  70. #include "consolemode.h"
  71. #include "specialbuilds.h"
  72. #include "slavemaster.h"
  73. #include "serversettings.h"
  74. #ifdef _DEBUG
  75. #include <crtdbg.h>
  76. #endif //_DEBUG
  77. #if (_MSC_VER >= 1200)
  78. #pragma warning(push,1)
  79. #endif
  80. #include <iostream>
  81. #include "singletoninstancekeeper.h"
  82. #include "packetmgr.h"
  83. #if (_MSC_VER >= 1200)
  84. #pragma warning(pop)
  85. #endif
  86. //----------------------------------------------------------------------------
  87. // Globals
  88. //----------------------------------------------------------------------------
  89. extern "C"
  90. {
  91. HWND hWndMain;
  92. bool WIN_fullscreen = true;
  93. }
  94. //----------------------------------------------------------------------------
  95. // Local functions
  96. //----------------------------------------------------------------------------
  97. static BOOL Create_Main_Window(HANDLE hInstance, int nCmdShow);
  98. long FAR PASCAL Main_Window_Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  99. void On_Focus_Loss(void);
  100. void On_Focus_Restore(void);
  101. void Split_Command_Line_Args(HINSTANCE instance, char *path_to_exe, char *command_line);
  102. void Set_Working_Directory(char *old_path, char *new_path);
  103. int Start_Application( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow );
  104. void Set_Working_Directory(HINSTANCE hInstance);
  105. #include "packet.h"
  106. #ifndef _MSC_VER
  107. long Top_Level_Exception_Filter(EXCEPTION_POINTERS *e_info)
  108. {
  109. return(Exception_Handler(e_info->ExceptionRecord->ExceptionCode, e_info));
  110. }
  111. #endif //_MSC_VER
  112. /***********************************************************************************************
  113. * WinMain -- Win32 Program Entry Point! *
  114. * *
  115. * INPUT: *
  116. * *
  117. * Standard WinMain inputs :-) *
  118. * *
  119. * OUTPUT: *
  120. * *
  121. * Standard WinMain output *
  122. * *
  123. * WARNINGS: *
  124. * *
  125. * HISTORY: *
  126. * 07/18/1997 GH : Created. *
  127. *=============================================================================================*/
  128. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  129. {
  130. WWMemoryLogClass::Init(); // This switches memlog from static to dynamic allocations mode
  131. #ifdef _DEBUG
  132. /*
  133. ** Setup to track memory heap integrity and check for
  134. ** memory leaks. Output is dumped to the debug string console.
  135. */
  136. if (cDevOptions::CrtDbgEnabled.Is_True()) {
  137. _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_DEBUG);
  138. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_DEBUG);
  139. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
  140. _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  141. }
  142. /*
  143. ** Leak test
  144. */
  145. //char *flibble = new char [1024];
  146. //unsigned long *flibble2 = new unsigned long;
  147. //void *flibble3 = malloc(128);
  148. //flibble = flibble;
  149. //flibble2 = flibble2;
  150. //flibble3 = flibble3;
  151. #endif //_DEBUG
  152. #ifdef WWDEBUG
  153. //
  154. // If necessary, disable packet optimizations
  155. //
  156. if (cDevOptions::PacketOptimizationsEnabled.Is_False()) {
  157. PacketManager.Disable_Optimizations();
  158. }
  159. #endif //WWDEBUG
  160. #ifdef _DEBUG // Denzil - DO NOT COMPILE INTO FINAL BUILD
  161. bool webInstalled = WebBrowser::InstallPrerequisites();
  162. if (!webInstalled) {
  163. ::MessageBox(NULL, "Embedded browser prerequisites missing\n\nBrowser functionality questionable.\n\n(Please call Denzil @ 27272)",
  164. "Renegade Warning!", MB_ICONWARNING|MB_OK);
  165. }
  166. #endif // WWDEBUG
  167. if (!cUserOptions::Parse_Command_Line(lpCmdLine)) {
  168. return(0);
  169. }
  170. //
  171. // There's a couple of options we need for the FDS
  172. //
  173. #ifdef FREEDEDICATEDSERVER
  174. if (!SlaveMaster.Am_I_Slave() && !ServerSettingsClass::Is_Server_Settings_File_Set()) {
  175. cUserOptions::Set_Server_INI_File("STARTSERVER=server.ini");
  176. }
  177. ConsoleBox.Set_Exclusive(true);
  178. #endif //FREEDEDICATEDSERVER
  179. //
  180. // Verify that we can execute (i.e. make sure there are no other instances running)
  181. //
  182. SingletonInstanceKeeperClass instance_keeper;
  183. if (instance_keeper.Verify_Safe_To_Execute () == false) {
  184. return 0;
  185. }
  186. //
  187. // Start the game!
  188. //
  189. int retval = Start_Application( hInstance, hPrevInstance, lpCmdLine, nCmdShow );
  190. return retval;
  191. }
  192. static bool Graphics_Settings_Trouble_Shooting()
  193. {
  194. RegistryClass registry( APPLICATION_SUB_KEY_NAME_DEBUG );
  195. if (!registry.Is_Valid()) return true;
  196. int progress=registry.Get_Int( VALUE_NAME_GAME_INITIALIZATION_IN_PROGRESS, 0 );
  197. if (progress) {
  198. StringClass options="wwconfig.exe ";
  199. char* opts=options.Peek_Buffer();
  200. STARTUPINFO startup_info;
  201. ZeroMemory(&startup_info,sizeof(STARTUPINFO));
  202. startup_info.cb=sizeof(STARTUPINFO);
  203. PROCESS_INFORMATION process_info;
  204. CreateProcess(
  205. NULL,
  206. opts,
  207. NULL,
  208. NULL,
  209. FALSE,
  210. 0,
  211. NULL,
  212. NULL,
  213. &startup_info,
  214. &process_info);
  215. unsigned long exit_code=STILL_ACTIVE;
  216. unsigned res=0;
  217. do {
  218. res=GetExitCodeProcess(process_info.hProcess,&exit_code);
  219. if (!res) {
  220. return true;
  221. }
  222. Sleep(100);
  223. }
  224. while (exit_code==STILL_ACTIVE);
  225. return !exit_code;
  226. }
  227. return true;
  228. }
  229. typedef IDirect3D8* (WINAPI *Direct3DCreate8Type) (UINT SDKVersion);
  230. static Direct3DCreate8Type Direct3DCreate8Ptr = NULL;
  231. static HINSTANCE D3D8Lib = NULL;
  232. static bool Video_Card_Driver_Check()
  233. {
  234. RegistryClass render_registry(APPLICATION_SUB_KEY_NAME_RENDER);
  235. if (!render_registry.Is_Valid()) return true;
  236. int disabled=render_registry.Get_Int( "DriverVersionCheckDisabled" );
  237. if (disabled>=87) return true;
  238. IDirect3D8* d3d=NULL;
  239. D3DCAPS8 tmp_caps;
  240. const D3DCAPS8* d3dcaps=NULL;
  241. D3DADAPTER_IDENTIFIER8 adapter_id;
  242. // Init D3D
  243. Init_D3D_To_WW3_Conversion();
  244. D3D8Lib = LoadLibrary("D3D8.DLL");
  245. if (D3D8Lib != NULL) {
  246. Direct3DCreate8Ptr = (Direct3DCreate8Type) GetProcAddress(D3D8Lib, "Direct3DCreate8");
  247. if (Direct3DCreate8Ptr) {
  248. d3d=Direct3DCreate8Ptr(D3D_SDK_VERSION); // TODO: handle failure cases...
  249. if (!d3d) {
  250. FreeLibrary(D3D8Lib);
  251. return true;
  252. }
  253. } else {
  254. FreeLibrary(D3D8Lib);
  255. return(true);
  256. }
  257. } else {
  258. return(true);
  259. }
  260. // Select device. If there is already a device selected in the registry, use it.
  261. int current_adapter_index=D3DADAPTER_DEFAULT;
  262. //
  263. // Load the render device settings from the registry
  264. //
  265. char device_name[256] = { 0 };
  266. render_registry.Get_String( VALUE_NAME_RENDER_DEVICE_NAME, device_name, sizeof(device_name));
  267. int adapter_count = d3d->GetAdapterCount();
  268. for (int adapter_index=0; adapter_index<adapter_count; adapter_index++) {
  269. D3DADAPTER_IDENTIFIER8 id;
  270. ::ZeroMemory(&id, sizeof(D3DADAPTER_IDENTIFIER8));
  271. HRESULT res = d3d->GetAdapterIdentifier(adapter_index,D3DENUM_NO_WHQL_LEVEL,&id);
  272. // If device ok, check if it matches the currently set adapter name
  273. if (res == D3D_OK) {
  274. StringClass name(id.Description,true);
  275. if (name==device_name) {
  276. current_adapter_index=adapter_index;
  277. break;
  278. }
  279. }
  280. }
  281. if (FAILED(d3d->GetDeviceCaps(
  282. current_adapter_index,
  283. D3DDEVTYPE_HAL,
  284. &tmp_caps))) {
  285. d3d->Release();
  286. FreeLibrary(D3D8Lib);
  287. return true;
  288. }
  289. ::ZeroMemory(&adapter_id, sizeof(D3DADAPTER_IDENTIFIER8));
  290. if (FAILED( d3d->GetAdapterIdentifier(
  291. current_adapter_index,
  292. D3DENUM_NO_WHQL_LEVEL,
  293. &adapter_id))) {
  294. d3d->Release();
  295. FreeLibrary(D3D8Lib);
  296. return true;
  297. }
  298. d3dcaps=&tmp_caps;
  299. DX8Caps caps(d3d,*d3dcaps,WW3D_FORMAT_UNKNOWN,adapter_id);
  300. DX8Caps::DriverVersionStatusType status=caps.Get_Driver_Version_Status();
  301. d3d->Release();
  302. FreeLibrary(D3D8Lib);
  303. switch (status) {
  304. default:
  305. case DX8Caps::DRIVER_STATUS_GOOD:
  306. case DX8Caps::DRIVER_STATUS_OK:
  307. case DX8Caps::DRIVER_STATUS_UNKNOWN:
  308. render_registry.Set_Int( "DriverVersionCheckDisabled",87 );
  309. return true;
  310. break;
  311. case DX8Caps::DRIVER_STATUS_BAD:
  312. break;
  313. }
  314. StringClass options="wwconfig.exe -driverversion";
  315. char* opts=options.Peek_Buffer();
  316. STARTUPINFO startup_info;
  317. ZeroMemory(&startup_info,sizeof(STARTUPINFO));
  318. startup_info.cb=sizeof(STARTUPINFO);
  319. PROCESS_INFORMATION process_info;
  320. if (!CreateProcess(
  321. NULL,
  322. opts,
  323. NULL,
  324. NULL,
  325. FALSE,
  326. 0,
  327. NULL,
  328. NULL,
  329. &startup_info,
  330. &process_info)) {
  331. return true;
  332. }
  333. unsigned long exit_code=STILL_ACTIVE;
  334. unsigned res=0;
  335. do {
  336. res=GetExitCodeProcess(process_info.hProcess,&exit_code);
  337. if (!res) {
  338. return true;
  339. }
  340. Sleep(100);
  341. }
  342. while (exit_code==STILL_ACTIVE);
  343. return !exit_code;
  344. }
  345. /***********************************************************************************************
  346. * Start_Application -- Handles WinMain execution. *
  347. * *
  348. * INPUT: *
  349. * *
  350. * Standard WinMain inputs :-) *
  351. * *
  352. * OUTPUT: *
  353. * *
  354. * Standard WinMain output *
  355. * *
  356. * WARNINGS: *
  357. * *
  358. * HISTORY: *
  359. * 09/19/2001 PDS : Created. *
  360. *=============================================================================================*/
  361. int Start_Application( HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow )
  362. {
  363. {
  364. WWMEMLOG(MEM_GAMEINIT);
  365. //LPSTR command = lpCmdLine;
  366. /*
  367. ** Set the working directory.
  368. */
  369. Set_Working_Directory(hInstance);
  370. //
  371. // TEMP Dev code - check the working folder is correct!
  372. //
  373. char tmp_buffer[256];
  374. char* tmp_ptr;
  375. if (!SearchPath(
  376. "data",
  377. "always.dat",
  378. NULL,
  379. sizeof(tmp_buffer),
  380. tmp_buffer,
  381. &tmp_ptr)) {
  382. MessageBox(NULL,"Set working folder and try again...","Invalid working folder",MB_OK);
  383. return 0;
  384. }
  385. /*
  386. ** Only do these checks if this isn't an auto-restart. If we are restarting then we must have run once OK already. Right?
  387. */
  388. if (AutoRestart.Get_Restart_Flag() == false && !ConsoleBox.Is_Exclusive()) {
  389. if (!Video_Card_Driver_Check()) return 0;
  390. if (!Graphics_Settings_Trouble_Shooting()) return 0;
  391. }
  392. //Debug_Say(("Started logging at time %s", cMiscUtil::Get_Text_Time()));
  393. if (!Create_Main_Window(hInstance, nCmdShow)) return 0;
  394. Register_Thread_ID(GetCurrentThreadId(), "Main Thread", true);
  395. }
  396. int exitCode = EXIT_SUCCESS;
  397. #ifdef WWDEBUG
  398. if (cDevOptions::EnableExceptionHandler.Is_False()) {
  399. exitCode = Game_Main_Loop();
  400. } else {
  401. #endif //WWDEBUG
  402. Register_Application_Exception_Callback(&Application_Exception_Callback);
  403. Register_Application_Version_Callback(&BuildInfoClass::Composite_Build_Info);
  404. #ifdef _MSC_VER
  405. /*
  406. ** The __try/__except construct is part of the WIN32 interface. This is not the same
  407. ** as C++ exception handling. There is no additional code overhead required
  408. ** with this interface and the compilers exception handling options should be disabled
  409. ** to prevent the compiler generating additional stack unwinding code.
  410. */
  411. __try {
  412. #else
  413. SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) &Top_Level_Exception_Filter);
  414. #endif
  415. WWDEBUG_SAY(("Game_Main_Loop\n"));
  416. exitCode = Game_Main_Loop();
  417. #ifdef _MSC_VER
  418. } __except(Exception_Handler(GetExceptionCode(), GetExceptionInformation())) {};
  419. /*
  420. ** Set the exception filter to use on shutdown.
  421. */
  422. #else
  423. SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) &Top_Level_Exception_Filter);
  424. #endif
  425. #ifdef WWDEBUG
  426. }
  427. #endif //WWDEBUG
  428. Unregister_Thread_ID(GetCurrentThreadId(), "Main Thread");
  429. //Debug_Say(("Finished logging at time %s", cMiscUtil::Get_Text_Time()));
  430. return exitCode;
  431. }
  432. /***********************************************************************************************
  433. * Main_Window_Proc -- Windows Proc for the main game window *
  434. * *
  435. * INPUT: *
  436. * *
  437. * Standard Windows Proc inputs *
  438. * *
  439. * OUTPUT: *
  440. * *
  441. * Standard Windows Proc output *
  442. * *
  443. * WARNINGS: *
  444. * *
  445. * HISTORY: *
  446. * 07/18/1997 GH : Created. *
  447. *=============================================================================================*/
  448. long FAR PASCAL Main_Window_Proc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
  449. {
  450. static bool _reset = false;
  451. /*
  452. ** Pass this message through to the input handler. If the message
  453. ** was processed and requires no further action, then return with
  454. ** this information.
  455. */
  456. if (_TheWWUIInput && Input::Is_Console_Enabled () == false) {
  457. LRESULT result = 0;
  458. //DialogWalker->Process_Message(hwnd, message, wParam, lParam, result);
  459. if (_TheWWUIInput->ProcessMessage(hwnd, message, wParam, lParam, result)) {
  460. return result;
  461. }
  462. }
  463. switch (message )
  464. {
  465. /*
  466. ** basic management messages
  467. */
  468. case WM_ACTIVATEAPP:
  469. if (wParam && !GameInFocus) {
  470. WWDEBUG_SAY(("***** FOCUS GAINED *****\n"));
  471. GameInFocus = true;
  472. On_Focus_Restore();
  473. } else if (!wParam && GameInFocus) {
  474. WWDEBUG_SAY(("***** FOCUS LOST *****\n"));
  475. GameInFocus = false;
  476. On_Focus_Loss();
  477. }
  478. return(0);
  479. case WM_ERASEBKGND:
  480. return 1;
  481. case WM_PAINT:
  482. ValidateRect(hwnd, NULL);
  483. break;
  484. /*
  485. ** minimize/maximize
  486. */
  487. case WM_SYSKEYDOWN:
  488. if (wParam == VK_RETURN && ((lParam>>16) & KF_ALTDOWN) && !((lParam>>16) & KF_REPEAT))
  489. {
  490. if (WIN_fullscreen) {
  491. WIN_fullscreen = false;
  492. } else {
  493. WIN_fullscreen = true;
  494. }
  495. }
  496. break;
  497. /*
  498. ** getch()
  499. */
  500. case WM_CHAR:
  501. //Debug_Say(("WM_CHAR %d\n", wParam));
  502. Input::Console_Add_Key( wParam );
  503. break;
  504. /*
  505. ** Main window creation
  506. */
  507. case WM_CREATE:
  508. break;
  509. /*
  510. ** Main window destruction
  511. */
  512. case WM_DESTROY:
  513. ReleaseCapture ();
  514. PostQuitMessage (0);
  515. break;
  516. case WM_SYSCOMMAND:
  517. switch (wParam) {
  518. case SC_CLOSE:
  519. /*
  520. ** Windows sent us a close message. Probably in response to Alt-F4. Ignore it by
  521. ** pretending to handle the message and returning true;
  522. */
  523. return (0);
  524. case SC_KEYMENU:
  525. /*
  526. ** Ignore all "menu-activation" commands.
  527. */
  528. return (0);
  529. case SC_SCREENSAVE:
  530. /*
  531. ** Windoze is about to start the screen saver. If we just return without passing
  532. ** this message to DefWindowProc then the screen saver will not be allowed to start.
  533. */
  534. return (0);
  535. }
  536. break;
  537. // Denzil - Using WM_xxxFOCUS messages to switch to windowed / fullscreen fails.
  538. #if(0)
  539. case WM_KILLFOCUS:
  540. {
  541. if (WW3D::Is_Initted ()) {
  542. // Get the current state of the redendering device
  543. int width = 0;
  544. int height = 0;
  545. int bits = 0;
  546. bool bwindowed = false;
  547. WW3D::Get_Device_Resolution (width, height, bits, bwindowed);
  548. // If we are running fullscreen, then toggle to 'windowed'
  549. // and minimze the window.
  550. if (bwindowed == false) {
  551. //Debug_Say(("WM_KILLFOCUS minimize"));
  552. WW3D::Set_Device_Resolution (-1, -1, -1, true);
  553. ::ShowWindow (hwnd, SW_MINIMIZE);
  554. _reset = true;
  555. }
  556. }
  557. }
  558. break;
  559. case WM_SETFOCUS:
  560. // If we need to reset the app to 'fullscreen' mode then
  561. // do so an restore the window.
  562. if (_reset == true) {
  563. WW3D::Set_Device_Resolution (-1, -1, -1, false);
  564. ::ShowWindow (hwnd, SW_RESTORE);
  565. _reset = false;
  566. }
  567. break;
  568. #endif
  569. case WM_COMMAND:
  570. if (LOWORD (wParam) == IDM_TOGGLE_FULLSCREEN) {
  571. // Ask WW3D to toggle the fullscreen mode for us.
  572. WW3D::Toggle_Windowed ();
  573. }
  574. break;
  575. default:
  576. break;
  577. }
  578. return DefWindowProc(hwnd, message, wParam, lParam);
  579. }
  580. /***********************************************************************************************
  581. * Create_Main_Window -- Creates the main game window *
  582. * *
  583. * INPUT: *
  584. * *
  585. * hInstance -- Instance handle of the application *
  586. * nCmdShow -- how the window is to be shown *
  587. * *
  588. * OUTPUT: *
  589. * *
  590. * TRUE = success, FALSE = failure *
  591. * *
  592. * WARNINGS: *
  593. * *
  594. * HISTORY: *
  595. * 07/18/1997 GH : Created. *
  596. *=============================================================================================*/
  597. static BOOL Create_Main_Window(HANDLE hInstance, int nCmdShow)
  598. {
  599. WNDCLASS wc;
  600. BOOL rc;
  601. ProgramInstance = (HINSTANCE)hInstance;
  602. if (!ConsoleBox.Is_Exclusive()) {
  603. wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  604. wc.lpfnWndProc = Main_Window_Proc;
  605. wc.cbClsExtra = 0;
  606. wc.cbWndExtra = 0;
  607. wc.hInstance = (HINSTANCE)hInstance;
  608. wc.hIcon = LoadIcon( NULL, IDI_APPLICATION);
  609. wc.hCursor = LoadCursor( NULL, IDC_ARROW);
  610. wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH);
  611. wc.lpszMenuName = NULL;
  612. wc.lpszClassName = SingletonInstanceKeeperClass::Get_GUID ();
  613. rc = RegisterClass( &wc);
  614. if (!rc ) return FALSE;
  615. // Assume windowed mode
  616. MainWindow = CreateWindowEx(0, SingletonInstanceKeeperClass::Get_GUID(), "Renegade",
  617. WS_SYSMENU|WS_CAPTION|WS_MINIMIZEBOX|WS_CLIPCHILDREN,
  618. 0, 0, 0, 0, NULL, NULL, ProgramInstance, NULL);
  619. if (!MainWindow) {
  620. return FALSE;
  621. }
  622. SetFocus(MainWindow);
  623. }
  624. return TRUE;
  625. }
  626. /***********************************************************************************************
  627. * On_Focus_Loss -- this function is called when the application loses focus *
  628. * *
  629. * INPUT: Nothing *
  630. * *
  631. * OUTPUT: Nothing *
  632. * *
  633. * WARNINGS: None *
  634. * *
  635. * HISTORY: *
  636. * 07/18/1997 GH : Created. *
  637. *=============================================================================================*/
  638. void On_Focus_Loss(void)
  639. {
  640. DirectInput::Unacquire();
  641. }
  642. /***********************************************************************************************
  643. * On_Focus_Restore -- This function is called when the application gets focus *
  644. * *
  645. * INPUT: Nothing *
  646. * *
  647. * OUTPUT: Nothing *
  648. * *
  649. * WARNINGS: None *
  650. * *
  651. * HISTORY: *
  652. * 07/18/1997 GH : Created. *
  653. *=============================================================================================*/
  654. void On_Focus_Restore(void)
  655. {
  656. if (WebBrowser::IsWebPageDisplayed() == false) {
  657. DirectInput::Acquire();
  658. }
  659. GameModeManager::Hide_Render_Frames(1); // Hide the first rendered frame
  660. }
  661. void Prog_End(void)
  662. {
  663. }
  664. /***********************************************************************************************
  665. * Set_Working_Directory -- Sets current directory to be the same as the .exe *
  666. * *
  667. * *
  668. * *
  669. * INPUT: Program instance *
  670. * *
  671. * OUTPUT: Nothing *
  672. * *
  673. * WARNINGS: None *
  674. * *
  675. * HISTORY: *
  676. * 11/6/2001 12:11PM ST : Created *
  677. *=============================================================================================*/
  678. void Set_Working_Directory(HINSTANCE instance)
  679. {
  680. char path_to_exe[256];
  681. char drive[_MAX_DRIVE];
  682. char dir[_MAX_DIR];
  683. char path[_MAX_PATH];
  684. GetModuleFileName(instance, path_to_exe, sizeof(path_to_exe));
  685. _splitpath(path_to_exe, drive, dir, NULL, NULL);
  686. _makepath(path, drive, dir, NULL, NULL);
  687. SetCurrentDirectory(path);
  688. }