2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2007-10-16 20:53:10 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2007-10-16 20:53:10 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2007-10-16 20:53:10 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2007-10-16 20:53:10 +00:00
|
|
|
// 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.
|
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-16 20:53:10 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "boinc_win.h"
|
|
|
|
|
|
|
|
#include "boinc_tray.h"
|
|
|
|
#include "tray_win.h"
|
2009-11-13 21:23:15 +00:00
|
|
|
#include "idlemon.h"
|
2007-10-16 20:53:10 +00:00
|
|
|
|
|
|
|
|
2007-11-30 18:52:41 +00:00
|
|
|
HMODULE g_hModule = NULL;
|
|
|
|
static CBOINCTray* gspBOINCTray = NULL;
|
2007-10-16 20:53:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
INT WINAPI WinMain(
|
|
|
|
HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow
|
|
|
|
) {
|
|
|
|
CBOINCTray BOINCTray;
|
|
|
|
return BOINCTray.Run( hInstance, hPrevInstance, lpCmdLine, nCmdShow );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBOINCTray::CBOINCTray() {
|
|
|
|
gspBOINCTray = this;
|
|
|
|
m_hDataManagementThread = NULL;
|
2008-08-07 16:59:52 +00:00
|
|
|
m_bIdleTrackerInitialized = FALSE;
|
2007-10-16 20:53:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Starts main execution of BOINC Tray.
|
|
|
|
//
|
2009-11-13 21:23:15 +00:00
|
|
|
INT CBOINCTray::Run( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR /* lpCmdLine */ , int /* nCmdShow */ ) {
|
2007-11-30 18:52:41 +00:00
|
|
|
|
2007-10-16 20:53:10 +00:00
|
|
|
if (!hPrevInstance) {
|
|
|
|
// Register an appropriate window class for the primary window
|
|
|
|
WNDCLASS cls;
|
2007-10-19 02:55:31 +00:00
|
|
|
cls.hCursor = NULL;
|
|
|
|
cls.hIcon = NULL;
|
2007-10-16 20:53:10 +00:00
|
|
|
cls.lpszMenuName = NULL;
|
|
|
|
cls.lpszClassName = _T("BOINCTrayWndClass");
|
|
|
|
cls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
cls.hInstance = hInstance;
|
|
|
|
cls.style = CS_OWNDC|CS_VREDRAW|CS_HREDRAW;
|
|
|
|
cls.lpfnWndProc = TrayProcStub;
|
|
|
|
cls.cbWndExtra = 0;
|
|
|
|
cls.cbClsExtra = 0;
|
|
|
|
RegisterClass(&cls);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the window
|
|
|
|
MSG msg;
|
|
|
|
HWND hWnd;
|
|
|
|
|
|
|
|
hWnd = CreateWindow(
|
|
|
|
_T("BOINCTrayWndClass"),
|
2009-11-13 21:23:15 +00:00
|
|
|
_T("BOINC System Tray Applet"),
|
2007-10-16 20:53:10 +00:00
|
|
|
WS_OVERLAPPEDWINDOW|WS_HSCROLL|WS_VSCROLL,
|
|
|
|
0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Process the message pump
|
|
|
|
while( GetMessage( &msg, NULL, 0, 0 ) ) {
|
|
|
|
TranslateMessage( &msg );
|
|
|
|
DispatchMessage( &msg );
|
|
|
|
}
|
|
|
|
|
2007-11-30 18:52:41 +00:00
|
|
|
|
2009-11-13 21:23:15 +00:00
|
|
|
// Cleanup and shutdown the BOINC idle tracking system.
|
|
|
|
detach_idle_monitor();
|
2007-11-30 18:52:41 +00:00
|
|
|
|
2007-10-16 20:53:10 +00:00
|
|
|
return msg.wParam;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create the thread that is used to talk to the daemon.
|
|
|
|
//
|
|
|
|
BOOL CBOINCTray::CreateDataManagementThread() {
|
|
|
|
DWORD dwThreadID = 0;
|
|
|
|
m_hDataManagementThread = CreateThread(
|
|
|
|
NULL, // default security attributes
|
|
|
|
0, // use default stack size
|
|
|
|
DataManagementProcStub, // thread function
|
|
|
|
NULL, // argument to thread function
|
|
|
|
0, // use default creation flags
|
|
|
|
&dwThreadID ); // returns the thread identifier
|
|
|
|
|
|
|
|
if (m_hDataManagementThread == NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Terminate the thread that is used to talk to the daemon.
|
|
|
|
//
|
|
|
|
BOOL CBOINCTray::DestroyDataManagementThread() {
|
|
|
|
if (!TerminateThread(m_hDataManagementThread, 0)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Update the time since last input activity every 5 seconds or so.
|
|
|
|
//
|
|
|
|
DWORD WINAPI CBOINCTray::DataManagementProc() {
|
|
|
|
while (true) {
|
2009-11-13 21:23:15 +00:00
|
|
|
// On Vista systems, only elevated processes can create shared memory
|
|
|
|
// area's across various user sessions. In this case we need to wait
|
|
|
|
// for BOINC to create the shared memory area and then boinctray can
|
|
|
|
// successfully attach to it. What a PITA.
|
|
|
|
if (!m_bIdleTrackerInitialized) {
|
|
|
|
m_bIdleTrackerInitialized = attach_idle_monitor();
|
2007-11-30 18:52:41 +00:00
|
|
|
}
|
|
|
|
|
2009-11-13 21:23:15 +00:00
|
|
|
get_idle_tick_count();
|
2007-10-16 20:53:10 +00:00
|
|
|
Sleep(5000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function forwards to DataManagementProc, which has access to the
|
|
|
|
// "this" pointer.
|
|
|
|
//
|
2007-10-17 23:30:05 +00:00
|
|
|
DWORD WINAPI CBOINCTray::DataManagementProcStub(LPVOID) {
|
2007-10-16 20:53:10 +00:00
|
|
|
return gspBOINCTray->DataManagementProc();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle window messages for main screensaver windows.
|
|
|
|
//
|
|
|
|
LRESULT CBOINCTray::TrayProc(
|
|
|
|
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
|
|
|
|
) {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_CREATE:
|
|
|
|
CreateDataManagementThread();
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
DestroyDataManagementThread();
|
|
|
|
return 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DefWindowProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This function forwards all window messages to SaverProc, which has
|
|
|
|
// access to the "this" pointer.
|
|
|
|
//
|
|
|
|
LRESULT CALLBACK CBOINCTray::TrayProcStub(
|
|
|
|
HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam
|
|
|
|
) {
|
|
|
|
return gspBOINCTray->TrayProc(hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|