bblaunch.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <string>
  2. #include <windows.h>
  3. #include "checkdx.h"
  4. #include "checkie.h"
  5. using namespace std;
  6. static const char *dx_err=
  7. "You must have DirectX version 7 installed to run Blitz Basic.\n\n"
  8. "DirectX 7 is provided on the Blitz Basic CD in the DirectX7 folder.\n\n"
  9. "The latest version of DirectX is available from www.microsoft.com";
  10. static const char *ie_err=
  11. "You must have Internet Explorer version 4 installed to run Blitz Basic.\n\n"
  12. "Internet Explorer 5 is provided on the Blitz Basic CD in the IExplorer5 folder.\n\n"
  13. "The latest version of Internet Explorer is available from www.microsoft.com";
  14. static const char *bb_err=
  15. "Unable to run Blitz Basic";
  16. static const char *md_err=
  17. "Your desktop must be in high-colour mode to use Blitz Basic.\n\n"
  18. "You can change your display settings from the control panel.";
  19. static string getAppDir(){
  20. char buff[MAX_PATH];
  21. if( GetModuleFileName( 0,buff,MAX_PATH ) ){
  22. string t=buff;
  23. int n=t.find_last_of( '\\' );
  24. if( n!=string::npos ) t=t.substr( 0,n );
  25. return t;
  26. }
  27. return "";
  28. }
  29. static void fail( const char *p ){
  30. ::MessageBox( 0,p,"Blitz Basic Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONERROR );
  31. ExitProcess(-1);
  32. }
  33. static int desktopDepth(){
  34. HDC hdc=GetDC( GetDesktopWindow() );
  35. return GetDeviceCaps( hdc,BITSPIXEL );
  36. }
  37. int _stdcall WinMain( HINSTANCE inst,HINSTANCE prev,char *cmd,int show ){
  38. if( desktopDepth()<16 ) fail( md_err );
  39. #ifndef PLUS
  40. if( getDXVersion()<7 ) fail( dx_err );
  41. #endif
  42. if( getIEVersion()<4 ) fail( ie_err );
  43. //Ugly hack to get application dir...
  44. string t=getAppDir();
  45. putenv( ("blitzpath="+t).c_str() );
  46. SetCurrentDirectory( t.c_str() );
  47. t=t+"\\bin\\ide.exe "+cmd;
  48. STARTUPINFO si;
  49. PROCESS_INFORMATION pi;
  50. ZeroMemory(&si,sizeof(si));si.cb=sizeof(si);
  51. if( !CreateProcess( 0,(char*)t.c_str(),0,0,0,0,0,0,&si,&pi ) ){
  52. ::MessageBox( 0,bb_err,"Blitz Basic Error",MB_SETFOREGROUND|MB_TOPMOST|MB_ICONERROR );
  53. ExitProcess(-1);
  54. }
  55. //wait for BB to start
  56. WaitForInputIdle( pi.hProcess,INFINITE );
  57. // Close process and thread handles.
  58. CloseHandle( pi.hProcess );
  59. CloseHandle( pi.hThread );
  60. return 0;
  61. }