// This file is part of BOINC. // http://boinc.berkeley.edu // Copyright (C) 2014-2015 University of California // // BOINC is free software; you can redistribute it and/or modify it // under the terms of the GNU Lesser General Public License // as published by the Free Software Foundation, // either version 3 of the License, or (at your option) any later version. // // BOINC is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // See the GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with BOINC. If not, see . #define _ATL_FREE_THREADED #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS #include #include #include #include #include #include #include #include #include #include #include #include "win_util.h" #include "version.h" #include "boinc_api.h" #include "diagnostics.h" #include "filesys.h" #include "network.h" #include "webserver.h" #include "browser_i.h" #include "browser_i.c" #include "browser_win.h" #include "browserlog.h" #include "browserctrl_win.h" #include "browserwnd_win.h" #include "browsermain_win.h" #ifdef _MSC_VER #define snprintf _snprintf #endif CBrowserModule _AtlModule; CBrowserModule::CBrowserModule() { m_pWnd = NULL; m_bFullscreen = false; m_bDebugging = false; } HRESULT CBrowserModule::InitializeCom() throw() { HRESULT rc = OleInitialize(NULL); WSADATA wsdata; WSAStartup( MAKEWORD( 1, 1 ), &wsdata); return rc; } void CBrowserModule::UninitializeCom() throw() { WSACleanup(); OleUninitialize(); } HRESULT CBrowserModule::PreMessageLoop(int nShowCmd) throw() { HRESULT hr = 0; RECT rc = {0, 0, 0, 0}; DWORD dwExStyle = 0; DWORD dwStyle = 0; APP_INIT_DATA aid; char szWindowTitle[256]; char szWindowInfo[256]; char szDebuggingInfo[256]; int iWebServerPort = 0; hr = __super::PreMessageLoop(nShowCmd); if (FAILED(hr)) { return hr; } // Initialize ATL Window Classes // AtlAxWinInit(); // Prepare environment for web browser control // RegisterWebControlCompatiblity(); // Prepare environment for detecting system conditions // boinc_parse_init_data_file(); boinc_get_init_data(aid); // Initialize Web Server // boinc_get_port(false, iWebServerPort); webserver_initialize(iWebServerPort, m_bFullscreen, m_bDebugging); // Create Window Instance // m_pWnd = new CHTMLBrowserWnd(); if (m_pWnd == NULL) { __super::PostMessageLoop(); return E_OUTOFMEMORY; } // Construct the window caption // if (aid.app_version) { snprintf( szWindowInfo, sizeof(szWindowInfo), "%s version %.2f [workunit: %s]", aid.app_name, aid.app_version/100.0, aid.wu_name ); } else { snprintf( szWindowInfo, sizeof(szWindowInfo), "%s [workunit: %s]", aid.app_name, aid.wu_name ); } if (m_bDebugging) { snprintf(szDebuggingInfo, sizeof(szDebuggingInfo), "[Web Server Port: %d]", iWebServerPort); } else { strcpy(szDebuggingInfo, ""); } snprintf(szWindowTitle, sizeof(szWindowTitle)-1, "%s %s", szWindowInfo, szDebuggingInfo); // Determine window size and placement if (m_bFullscreen) { HDC dc = GetDC(NULL); rc.left = 0; rc.top = 0; rc.right = GetDeviceCaps(dc, HORZRES); rc.bottom = GetDeviceCaps(dc, VERTRES); ReleaseDC(NULL, dc); dwStyle = WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_POPUP; dwExStyle = WS_EX_APPWINDOW|WS_EX_TOPMOST; while(ShowCursor(false) >= 0); } else { rc.left = 0; rc.top = 0; rc.right = 1024; rc.bottom = 768; dwStyle = WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_OVERLAPPEDWINDOW; dwExStyle = WS_EX_APPWINDOW|WS_EX_WINDOWEDGE; while(ShowCursor(true) < 0); } // Create Window // m_pWnd->Create(GetDesktopWindow(), rc, szWindowTitle, dwStyle, dwExStyle); m_pWnd->ShowWindow(nShowCmd); return S_OK; } HRESULT CBrowserModule::PostMessageLoop() throw() { if (m_pWnd) { delete m_pWnd; m_pWnd = NULL; } webserver_destroy(); AtlAxWinTerm(); return __super::PostMessageLoop(); } int CBrowserModule::RegisterCommandLine(int argc, char** argv) { for (int i=1; i