int CCustomPlayer::DoSystemCheck(XString&errorText) { /************************************************************************/ /* System Check : */ /************************************************************************/ int foundError = 0; ////////////////////////////////////////////////////////////////////////// // Check DirectX Version : bool DirectXVer_OK = true; if (CPR_CHECK_DIRECTX) { DWORD dxVerMinor=0; char *strVersion = NULL; xUtils::system::GetDirectVersion(strVersion,dxVerMinor); XString dxVer(strVersion); XString dxVer3 = dxVer.Crop(0,3); int dxVerWeNeedMin = GetPAppStyle()->g_MinimumDirectXVersion; int dxVerInt = dxVer3.ToInt(); if(dxVerInt < dxVerWeNeedMin ) { errorText << "\n\n" << "Wrong DirectX Version Detected !"; errorText << "\n\n" << "This application needs at least version : " << GetPAppStyle()->g_MinimumDirectXVersion; errorText << "\n\n" << "You have version : " << strVersion; errorText << "\n\n" << "You can download it from here :" << CPR_MINIMUM_DIRECTX_VERSION_FAIL_URL ; errorText << "\n"; foundError =1; DirectXVer_OK =false; } } ////////////////////////////////////////////////////////////////////////// // Check System Ram if (CPR_CHECK_RAM && DirectXVer_OK ) { int ram = xUtils::system::GetPhysicalMemoryInMB(); if( ram < GetPAppStyle()->g_MiniumumRAM) { errorText << "\n This application needs at least : " << GetPAppStyle()->g_MiniumumRAM << " of System Memory."; errorText << "\n\n\t You have only : " << ram ; foundError = 1; } } ////////////////////////////////////////////////////////////////////////// // Add the last line : support eMail if(foundError) { errorText << "\n\n You can contact us via EMail : mailto:"<<CP_SUPPORT_EMAIL ; } m_LastErrorText = errorText ; return foundError; }
BOOL CCustomPlayer::InitPlayer(HWND iMainWindow, HWND iRenderWindow, int iConfig, const void* iData,int iDataSize) { // keep a reference on the main/render window m_MainWindow = iMainWindow; m_RenderWindow = iRenderWindow; // start the Virtools Engine //CKInitCustomPlayer(false); CKStartUp(); ////////////////////////////////////////////////////////////////////////// // we have unmet requirements ? XString errorText; int hasError = DoSystemCheck(errorText); ////////////////////////////////////////////////////////////////////////// // show splash when we have no error and we are not in the explicit configuration mode ( invoked by : "CustomPlayer.exe -c ") : if( GetPAppStyle()->UseSplash() && !hasError && PGetApplicationMode() != config ) { ShowSplash(); } // retrieve the plugin manager ... CKPluginManager* pluginManager = CKGetPluginManager(); ////////////////////////////////////////////////////////////////////////// // ... to intialize plugins ... if (!_InitPlugins(*pluginManager)) { MessageBox(NULL,UNABLE_TO_INIT_PLUGINS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // ... and the render engine. int renderEngine = _InitRenderEngines(*pluginManager); if (renderEngine==-1) { MessageBox(NULL,UNABLE_TO_LOAD_RENDERENGINE,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // now create the CK context XString inifile = CKGetStartPath(); inifile << "CompositionPrefs_R_Hi.ini"; CKERROR res = CKCreateContext(&m_CKContext,m_MainWindow,inifile.Str()); if (res!=CK_OK) { MessageBox(NULL,UNABLE_TO_INIT_CK,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } #if defined(CUSTOM_PLAYER_STATIC) // if the player is not static char BehaviorPath[_MAX_PATH]; char szPath[_MAX_PATH]; VxGetModuleFileName(NULL,szPath,_MAX_PATH); CKPathSplitter ps(szPath); sprintf(BehaviorPath,"%s%s%s",ps.GetDrive(),ps.GetDir(),GetEPathProfile()->BehaviorPath.Str()); pluginManager->ParsePlugins(BehaviorPath); #endif ////////////////////////////////////////////////////////////////////////// // adding load callback if(GetPAppStyle()->UseSplash() && !m_LastError && PGetApplicationMode() != config ) { if (GetPAppStyle()->ShowLoadingProcess()) { m_CKContext->SetInterfaceMode(FALSE,LoadCallBack,NULL); } } // retrieve the main managers which will be used by the player m_MessageManager = m_CKContext->GetMessageManager(); m_RenderManager = m_CKContext->GetRenderManager(); m_TimeManager = m_CKContext->GetTimeManager(); m_AttributeManager = m_CKContext->GetAttributeManager(); m_EnginePointers.TheMessageManager = m_MessageManager; m_EnginePointers.TheRenderManager = m_RenderManager; m_EnginePointers.TheTimeManager = m_TimeManager; m_EnginePointers.TheCKContext = m_CKContext; //We have an error, show our dialog : if (hasError) { AfxInitRichEdit2(); CustomPlayerDialog k(NULL,CString(errorText.Str())); k.DoModal(); if (CPA_ABORT_ON_ERROR) { return FALSE; } } m_InputManager = (CKInputManager*)m_CKContext->GetManagerByGuid(INPUT_MANAGER_GUID); if (!m_MessageManager || !m_RenderManager || !m_TimeManager || !m_AttributeManager || !m_InputManager) { MessageBox(NULL,UNABLE_TO_INIT_MANAGERS,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } // initialize the display driver using the player configuration (resolution, rasterizer, ...) if (!_InitDriver()) { MessageBox(NULL,UNABLE_TO_INIT_DRIVER,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Textures",0); PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Data",1); PLoadResourcePaths(CUSTOM_PLAYER_CONFIG_FILE,"Music",2); // now load the composition if (iDataSize) { // if iDataSize is not null it means the composition is already in memory if (_Load(iData,iDataSize)!=CK_OK) { MessageBox(NULL,"Unable to load composition from memory.","Initialization Error",MB_OK|MB_ICONERROR); return FALSE; } } else if (_Load((const char*)iData)!=CK_OK) { // else we load it from a file (iData contains the filename) MessageBox(NULL,"Unable to load composition from file.","Initialization Error",MB_OK|MB_ICONERROR); return FALSE; } //GetPlayer().HideSplash(); //show our dialog ? if (GetPAppStyle()->g_ShowDialog) { AfxInitRichEdit2(); CustomPlayerDialog k(NULL,CString(errorText.Str())); k.DoModal(); } ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// // update of our member variables vtPlayer::Structs::xSEnginePointers* ep = GetPlayer().GetEnginePointers(); vtPlayer::Structs::xSEngineWindowInfo* ewinfo = GetPlayer().GetEngineWindowInfo(); m_WindowedHeight = ewinfo->g_HeightW; m_WindowedWidth = ewinfo->g_WidthW; m_FullscreenWidth = ewinfo->g_Width; m_FullscreenHeight = ewinfo->g_Height; if(ewinfo->g_GoFullScreen) m_Driver = ewinfo->g_FullScreenDriver; else m_Driver = ewinfo->g_WindowedDriver; m_FullscreenBpp = ewinfo->g_Bpp; ////////////////////////////////////////////////////////////////////////// CKVariableManager *vm = (CKVariableManager *)m_EnginePointers.TheCKContext->GetVariableManager(); vm->SetValue("CK2_3D/Antialias", GetEWindowInfo()->FSSA * 2 ); if(PGetApplicationMode() != config) { if (GetPlayer().GetPAppStyle()->IsRenderering()) { ////////////////////////////////////////////////////////////////////////// // create the render context if (GetEWindowInfo()->g_GoFullScreen) { // in fullscreen we specify the rendering size using a rectangle (CKRECT) CKRECT rect; rect.left = 0; rect.top = 0; rect.right = m_FullscreenWidth; rect.bottom = m_FullscreenHeight; // create the render context m_RenderContext = m_RenderManager->CreateRenderContext(m_RenderWindow,GetEWindowInfo()->g_FullScreenDriver,&rect,TRUE,m_FullscreenBpp); // set the position of the render window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_FullscreenWidth,m_FullscreenHeight,SWP_NOMOVE|SWP_NOZORDER); // resize the render context if (m_RenderContext) { m_RenderContext->Resize(0,0,m_FullscreenWidth,m_FullscreenHeight); } } else { ////////////////////////////////////////////////////////////////////////// // [2/18/2008 mc007] // we only repositioning the window when we are not displayed by a hosting application like // a charp panel ! if (!GetPAppStyle()->g_OwnerDrawed) { LONG st = GetWindowLong(m_MainWindow,GWL_STYLE); st|=WS_THICKFRAME; st&=~WS_SIZEBOX; SetWindowLong(m_MainWindow,GWL_STYLE,st); //reposition the window m_MainWindowRect.left = (GetSystemMetrics(SM_CXSCREEN)-m_WindowedWidth)/2; m_MainWindowRect.right = m_WindowedWidth+m_MainWindowRect.left; m_MainWindowRect.top = (GetSystemMetrics(SM_CYSCREEN)-m_WindowedHeight)/2; m_MainWindowRect.bottom = m_WindowedHeight+m_MainWindowRect.top; BOOL ret = AdjustWindowRect(&m_MainWindowRect,WS_OVERLAPPEDWINDOW & ~(WS_SYSMENU|WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SIZEBOX),FALSE); ::SetWindowPos(m_MainWindow,0,m_MainWindowRect.left,m_MainWindowRect.top,m_MainWindowRect.right - m_MainWindowRect.left,m_MainWindowRect.bottom - m_MainWindowRect.top,NULL); // set the position of the render window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_WindowedWidth,m_WindowedHeight,SWP_NOMOVE|SWP_NOZORDER); } // create the render context m_RenderContext = m_RenderManager->CreateRenderContext(m_RenderWindow,m_Driver,0,FALSE); // resize the render context if (m_RenderContext) { m_RenderContext->Resize(0,0,m_WindowedWidth,m_WindowedHeight); } } ////////////////////////////////////////////////////////////////////////// // when somebody changed any resolution in the configuration tab , we should update our windows : //store current size /* GetWindowRect(m_MainWindow,&m_MainWindowRect); LONG st = GetWindowLong(m_MainWindow,GWL_STYLE); st|=WS_THICKFRAME; st&=~WS_SIZEBOX; SetWindowLong(m_MainWindow,GWL_STYLE,st); //reposition the window m_MainWindowRect.left = (GetSystemMetrics(SM_CXSCREEN)-m_WindowedWidth)/2; m_MainWindowRect.right = m_WindowedWidth+m_MainWindowRect.left; m_MainWindowRect.top = (GetSystemMetrics(SM_CYSCREEN)-m_WindowedHeight)/2; m_MainWindowRect.bottom = m_WindowedHeight+m_MainWindowRect.top; BOOL ret = AdjustWindowRect(&m_MainWindowRect,WS_OVERLAPPEDWINDOW & ~(WS_SYSMENU|WS_SIZEBOX|WS_MAXIMIZEBOX|WS_MINIMIZEBOX|WS_SIZEBOX),FALSE); ::SetWindowPos(m_MainWindow,0,m_MainWindowRect.left,m_MainWindowRect.top,m_MainWindowRect.right - m_MainWindowRect.left,m_MainWindowRect.bottom - m_MainWindowRect.top,NULL); // and set the position of the render window in the main window ::SetWindowPos(m_RenderWindow,NULL,0,0,m_WindowedWidth,m_WindowedHeight,SWP_NOMOVE|SWP_NOZORDER); m_RenderContext->Resize(0,0,GetEWindowInfo()->g_GoFullScreen ? m_FullscreenWidth : m_WindowedWidth, GetEWindowInfo()->g_GoFullScreen ? m_FullscreenHeight : m_WindowedHeight);*/ if (!m_RenderContext) { MessageBox(NULL,UNABLE_TO_CREATE_RENDERCONTEXT,INIT_ERROR,MB_OK|MB_ICONERROR); return FALSE; } ////////////////////////////////////////////////////////////////////////// // clear the render view m_RenderContext->Clear(); m_RenderContext->BackToFront(); m_RenderContext->Clear(); } // finalize the loading if (!_FinishLoad()) { return FALSE; } } return TRUE; }
LRESULT CALLBACK CCustomPlayer::_MainWindowWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam) { switch(message) { case WM_DROPFILES: // Load any dropped file { char FileName[_MAX_PATH]; HDROP hdrop=(HDROP)wParam; DragQueryFile(hdrop,0,FileName,_MAX_PATH); Reset(); _Load(FileName); _FinishLoad(); break; } case WM_MOUSEMOVE: { // we allow window dragging enabled in the player.ini file ! if (GetPAppStyle()->g_MouseDrag==1) { DoMMove(lParam,wParam); } } case WM_ACTIVATEAPP: { OnActivateApp(wParam); } break; // Minimum size of the player window case WM_GETMINMAXINFO: // this message is not very useful because // the main window of the player is not resizable ... // but perhaps it will change so we manage this message. { CCustomPlayer& player = CCustomPlayer::Instance(); if((LPMINMAXINFO)lParam) { ((LPMINMAXINFO)lParam)->ptMinTrackSize.x=MininumWindowedWidth(); ((LPMINMAXINFO)lParam)->ptMinTrackSize.y=MininumWindowedHeight(); } } break; // Sends a Message "OnClick" or "OnDblClick" if any object is under mouse cursor case WM_LBUTTONDBLCLK: case WM_LBUTTONDOWN: { OnMouseClick(message); // [2/18/2008 mc007] // we allow window dragging enabled in the player.ini file ! if (GetPAppStyle()->g_MouseDrag) { StartMove(lParam); } } break; // Size and focus management case WM_SIZE: // if the window is maximized or minimized // we get/lost focus. { if (wParam==SIZE_MINIMIZED) { OnFocusChange(FALSE); } else if (wParam==SIZE_MAXIMIZED) { OnFocusChange(TRUE); } } break; // Manage system key (ALT + KEY) case WM_SYSKEYDOWN: { // return OnSysKeyDownMainWindow(theApp.m_Config,(int)wParam); } break; // Repaint main frame case WM_PAINT: { OnPaint(); } break; // The main windows has been closed by the user case WM_CLOSE: PostQuitMessage(0); break; // Focus management case WM_KILLFOCUS: case WM_SETFOCUS: { OnFocusChange(message==WM_SETFOCUS); } break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return DefWindowProc(hWnd, message, wParam, lParam); }