2012-03-08 22:42:44 +00:00
|
|
|
// DEPRECATED - DO NOT USE
|
|
|
|
|
2003-10-02 21:16:37 +00:00
|
|
|
// Event loop and support functions for Windows versions
|
|
|
|
// of BOINC applications w/ graphics.
|
|
|
|
// Platform-independent code should NOT be here.
|
|
|
|
//
|
2002-10-25 18:23:59 +00:00
|
|
|
|
2004-07-09 15:12:17 +00:00
|
|
|
/* This Code Was Created By Jeff Molofee 2000.
|
|
|
|
* A HUGE thanks to fredric echols for cleaning up
|
|
|
|
* and optimizing this code, making it more flexible!
|
|
|
|
* If you've found this code useful, please let me know.
|
|
|
|
* Visit My Site At nehe.gamedev.net
|
|
|
|
* Adapted to BOINC by Eric Heien
|
2002-09-18 22:15:49 +00:00
|
|
|
*/
|
2005-07-14 16:46:38 +00:00
|
|
|
#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_)
|
2004-06-17 00:05:18 +00:00
|
|
|
#include "boinc_win.h"
|
2005-11-21 18:34:44 +00:00
|
|
|
#else
|
|
|
|
#include "config.h"
|
2005-07-14 16:46:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-11-15 06:44:50 +00:00
|
|
|
#include "diagnostics.h"
|
2003-05-29 20:27:40 +00:00
|
|
|
#include "boinc_api.h"
|
2002-09-18 22:15:49 +00:00
|
|
|
#include "graphics_api.h"
|
2003-05-07 23:42:17 +00:00
|
|
|
#include "app_ipc.h"
|
2003-03-04 23:57:25 +00:00
|
|
|
#include "util.h"
|
2005-10-14 14:45:40 +00:00
|
|
|
#include "graphics_impl.h"
|
|
|
|
|
2006-02-23 07:54:11 +00:00
|
|
|
#define BOINC_WINDOW_CLASS_NAME "BOINC_app"
|
|
|
|
#define WM_SHUTDOWNGFX WM_USER+1
|
2004-01-17 18:36:17 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
const UINT WM_BOINCSFW = RegisterWindowMessage(TEXT("BOINCSetForegroundWindow"));
|
|
|
|
|
|
|
|
static BOOL is_windows_9x = FALSE;
|
|
|
|
static HDC hDC = NULL;
|
|
|
|
static HGLRC hRC = NULL;
|
|
|
|
static HWND hWnd = NULL; // Holds Our Window Handle
|
|
|
|
static HINSTANCE hInstance; // Holds The Instance Of The Application
|
|
|
|
static RECT rect = {50, 50, 50+640, 50+480};
|
|
|
|
static int current_graphics_mode = MODE_HIDE_GRAPHICS;
|
|
|
|
static int acked_graphics_mode = -1;
|
|
|
|
static POINT mousePos;
|
|
|
|
static HDC myhDC;
|
|
|
|
static GRAPHICS_MSG graphics_msg;
|
|
|
|
static HWINSTA hOriginalWindowStation = NULL;
|
|
|
|
static HDESK hOriginalDesktop = NULL;
|
|
|
|
static HWINSTA hInteractiveWindowStation = NULL;
|
|
|
|
static HDESK hInteractiveDesktop = NULL;
|
2004-01-17 18:36:17 +00:00
|
|
|
static bool visible = true;
|
2005-06-22 17:42:10 +00:00
|
|
|
static bool window_ready=false;
|
2005-09-16 18:16:49 +00:00
|
|
|
static UINT_PTR gfx_timer_id = 0;
|
2007-08-10 01:51:14 +00:00
|
|
|
HANDLE graphics_threadh;
|
2003-09-18 23:55:11 +00:00
|
|
|
|
2005-05-01 04:49:51 +00:00
|
|
|
#define GLUT_CTRL_KEY 17
|
|
|
|
|
2004-11-14 08:29:32 +00:00
|
|
|
void KillWindow() {
|
2005-06-22 17:42:10 +00:00
|
|
|
window_ready=false;
|
|
|
|
wglMakeCurrent(NULL,NULL); // release GL rendering context
|
|
|
|
if (hRC) {
|
|
|
|
wglDeleteContext(hRC);
|
|
|
|
hRC=NULL;
|
|
|
|
}
|
2004-11-14 08:29:32 +00:00
|
|
|
|
|
|
|
if (hWnd && hDC) {
|
|
|
|
ReleaseDC(hWnd,hDC);
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
2004-11-14 08:29:32 +00:00
|
|
|
hDC = NULL;
|
|
|
|
|
|
|
|
if (hWnd) {
|
|
|
|
DestroyWindow(hWnd);
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
2004-11-14 08:29:32 +00:00
|
|
|
hWnd = NULL;
|
2004-11-15 06:44:50 +00:00
|
|
|
|
|
|
|
if (hOriginalWindowStation) {
|
|
|
|
SetProcessWindowStation(hOriginalWindowStation);
|
2004-11-17 09:27:06 +00:00
|
|
|
CloseWindowStation(hInteractiveWindowStation);
|
|
|
|
hInteractiveWindowStation = NULL;
|
2004-11-15 06:44:50 +00:00
|
|
|
}
|
2004-11-18 04:52:34 +00:00
|
|
|
|
|
|
|
if (hOriginalDesktop) {
|
|
|
|
SetThreadDesktop(hOriginalDesktop);
|
|
|
|
CloseDesktop(hInteractiveDesktop);
|
|
|
|
hInteractiveDesktop = NULL;
|
|
|
|
}
|
2004-11-14 08:29:32 +00:00
|
|
|
}
|
2004-03-26 20:32:39 +00:00
|
|
|
|
2007-08-10 01:51:14 +00:00
|
|
|
|
2004-01-17 18:36:17 +00:00
|
|
|
void SetupPixelFormat(HDC hDC) {
|
|
|
|
int nPixelFormat;
|
2002-09-18 22:15:49 +00:00
|
|
|
|
2004-01-17 18:36:17 +00:00
|
|
|
static PIXELFORMATDESCRIPTOR pfd = {
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR), // size of structure.
|
|
|
|
1, // always 1.
|
|
|
|
PFD_DRAW_TO_WINDOW | // support window
|
|
|
|
PFD_SUPPORT_OPENGL | // support OpenGl
|
|
|
|
PFD_DOUBLEBUFFER, // support double buffering
|
|
|
|
PFD_TYPE_RGBA, // support RGBA
|
|
|
|
32, // 32 bit color mode
|
|
|
|
0, 0, 0, 0, 0, 0, // ignore color bits
|
|
|
|
0, // no alpha buffer
|
|
|
|
0, // ignore shift bit
|
|
|
|
0, // no accumulation buffer
|
|
|
|
0, 0, 0, 0, // ignore accumulation bits.
|
|
|
|
16, // number of depth buffer bits.
|
|
|
|
0, // number of stencil buffer bits.
|
|
|
|
0, // 0 means no auxiliary buffer
|
|
|
|
PFD_MAIN_PLANE, // The main drawing plane
|
|
|
|
0, // this is reserved
|
|
|
|
0, 0, 0 }; // layer masks ignored.
|
2003-09-19 22:40:32 +00:00
|
|
|
|
2004-01-17 18:36:17 +00:00
|
|
|
// this chooses the best pixel format and returns index.
|
|
|
|
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
|
2003-05-14 23:33:03 +00:00
|
|
|
|
2004-01-17 18:36:17 +00:00
|
|
|
// This set pixel format to device context.
|
|
|
|
SetPixelFormat(hDC, nPixelFormat, &pfd);
|
2003-05-14 23:33:03 +00:00
|
|
|
}
|
|
|
|
|
2004-11-17 09:27:06 +00:00
|
|
|
static void make_new_window() {
|
2005-06-22 17:42:10 +00:00
|
|
|
RECT WindowRect = {0,0,0,0};
|
|
|
|
int width, height;
|
|
|
|
DWORD dwExStyle;
|
|
|
|
DWORD dwStyle;
|
|
|
|
|
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
|
|
|
HDC screenDC=GetDC(NULL);
|
|
|
|
WindowRect.left = WindowRect.top = 0;
|
|
|
|
WindowRect.right=GetDeviceCaps(screenDC, HORZRES);
|
|
|
|
WindowRect.bottom=GetDeviceCaps(screenDC, VERTRES);
|
|
|
|
ReleaseDC(NULL, screenDC);
|
|
|
|
dwExStyle=WS_EX_TOPMOST;
|
|
|
|
dwStyle=WS_POPUP;
|
|
|
|
while(ShowCursor(false) >= 0);
|
|
|
|
} else {
|
|
|
|
WindowRect = rect;
|
|
|
|
dwExStyle=WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
|
|
|
|
dwStyle=WS_OVERLAPPEDWINDOW;
|
|
|
|
while(ShowCursor(true) < 0);
|
|
|
|
}
|
2003-03-04 06:01:46 +00:00
|
|
|
|
2004-12-14 19:23:46 +00:00
|
|
|
APP_INIT_DATA aid;
|
|
|
|
boinc_get_init_data(aid);
|
2003-09-27 17:53:43 +00:00
|
|
|
if (!strlen(aid.app_name)) strcpy(aid.app_name, "BOINC Application");
|
2005-10-12 02:19:28 +00:00
|
|
|
char window_title[256];
|
2005-10-12 18:40:53 +00:00
|
|
|
get_window_title(aid, window_title, 256);
|
2005-10-12 02:23:19 +00:00
|
|
|
hWnd = CreateWindowEx(dwExStyle, BOINC_WINDOW_CLASS_NAME, window_title,
|
2005-06-22 17:42:10 +00:00
|
|
|
dwStyle|WS_CLIPSIBLINGS|WS_CLIPCHILDREN, WindowRect.left, WindowRect.top,
|
|
|
|
WindowRect.right-WindowRect.left,WindowRect.bottom-WindowRect.top,
|
|
|
|
NULL, NULL, hInstance, NULL
|
2003-10-02 21:16:37 +00:00
|
|
|
);
|
2003-09-17 23:17:09 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
SetForegroundWindow(hWnd);
|
2003-06-03 21:30:40 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
GetCursorPos(&mousePos);
|
2004-07-09 15:12:17 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
hDC = GetDC(hWnd);
|
|
|
|
myhDC=hDC;
|
|
|
|
SetupPixelFormat(myhDC);
|
2004-07-09 15:12:17 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
hRC = wglCreateContext(hDC);
|
|
|
|
if (hRC == 0) {
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-19 18:42:51 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
if(!wglMakeCurrent(hDC, hRC)) {
|
|
|
|
ReleaseDC(hWnd, hDC);
|
|
|
|
wglDeleteContext(hRC);
|
|
|
|
return;
|
|
|
|
}
|
2003-03-19 18:42:51 +00:00
|
|
|
|
2005-09-16 23:28:28 +00:00
|
|
|
// use client area for resize when not fullscreen
|
|
|
|
if (current_graphics_mode != MODE_FULLSCREEN) {
|
|
|
|
GetClientRect(hWnd, &WindowRect);
|
|
|
|
}
|
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
width = WindowRect.right-WindowRect.left;
|
|
|
|
height = WindowRect.bottom-WindowRect.top;
|
2003-03-19 18:42:51 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
ShowWindow(hWnd, SW_SHOW);
|
|
|
|
SetFocus(hWnd);
|
2004-07-09 15:12:17 +00:00
|
|
|
|
2003-10-31 22:37:46 +00:00
|
|
|
app_graphics_init();
|
2005-06-22 17:42:10 +00:00
|
|
|
app_graphics_resize(width, height);
|
|
|
|
window_ready=true;
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// switch to the given graphics mode. This is called:
|
|
|
|
// - on initialization
|
|
|
|
// - when get mode change msg (via shared mem)
|
|
|
|
// - when in SS mode and get user input
|
|
|
|
//
|
2004-06-12 05:10:54 +00:00
|
|
|
static void set_mode(int mode) {
|
2004-11-18 01:52:07 +00:00
|
|
|
int new_mode = mode;
|
2005-05-22 02:12:31 +00:00
|
|
|
GRAPHICS_MSG current_desktop;
|
2004-11-18 01:52:07 +00:00
|
|
|
|
2004-07-18 04:41:27 +00:00
|
|
|
if (mode == current_graphics_mode) return;
|
2005-06-22 17:42:10 +00:00
|
|
|
if (current_graphics_mode != MODE_FULLSCREEN) {
|
|
|
|
if (IsIconic(hWnd) || IsZoomed(hWnd)){
|
2004-12-26 06:08:11 +00:00
|
|
|
// If graphics window is minimized or maximized
|
|
|
|
// then set default values of window size
|
2005-06-22 17:42:10 +00:00
|
|
|
rect.left = 50;
|
2004-12-26 06:08:11 +00:00
|
|
|
rect.top = 50;
|
|
|
|
rect.right = 50+640;
|
|
|
|
rect.bottom = 50+480;
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
|
|
|
else GetWindowRect(hWnd, &rect); // else get current values
|
|
|
|
}
|
2004-11-18 01:52:07 +00:00
|
|
|
|
|
|
|
KillWindow();
|
|
|
|
|
2005-05-22 02:12:31 +00:00
|
|
|
// Detect our current desktop and window station.
|
|
|
|
memset(current_desktop.window_station, 0, sizeof(current_desktop.window_station)/sizeof(char));
|
|
|
|
memset(current_desktop.desktop, 0, sizeof(current_desktop.desktop)/sizeof(char));
|
|
|
|
|
|
|
|
if (!is_windows_9x) {
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetProcessWindowStation(),
|
|
|
|
UOI_NAME,
|
|
|
|
current_desktop.window_station,
|
|
|
|
(sizeof(current_desktop.window_station) / sizeof(char)),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
GetUserObjectInformation(
|
|
|
|
GetThreadDesktop(GetCurrentThreadId()),
|
|
|
|
UOI_NAME,
|
|
|
|
current_desktop.desktop,
|
|
|
|
(sizeof(current_desktop.desktop) / sizeof(char)),
|
|
|
|
NULL
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!is_windows_9x &&
|
|
|
|
!boinc_is_standalone() &&
|
2004-11-21 04:18:26 +00:00
|
|
|
strlen(graphics_msg.window_station) > 0 &&
|
2005-05-22 02:12:31 +00:00
|
|
|
strlen(graphics_msg.desktop) > 0 &&
|
|
|
|
(strcmp(current_desktop.window_station, graphics_msg.window_station) ||
|
|
|
|
strcmp(current_desktop.desktop, graphics_msg.desktop))) {
|
|
|
|
|
2007-09-17 18:11:23 +00:00
|
|
|
BOINCINFO("Checking Desktop and Window Station Parameters\n");
|
2004-11-18 01:52:07 +00:00
|
|
|
GetDesktopWindow();
|
|
|
|
|
|
|
|
if (NULL == hOriginalWindowStation) {
|
|
|
|
hOriginalWindowStation = GetProcessWindowStation();
|
|
|
|
if (NULL == hOriginalWindowStation) {
|
2006-06-07 08:56:55 +00:00
|
|
|
BOINCINFO("Failed to retrieve the orginal window station\n");
|
2004-11-18 01:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NULL == hOriginalDesktop) {
|
|
|
|
hOriginalDesktop = GetThreadDesktop(GetCurrentThreadId());
|
|
|
|
if (NULL == hOriginalDesktop) {
|
2006-06-07 08:56:55 +00:00
|
|
|
BOINCINFO("Failed to retrieve the orginal desktop\n");
|
2004-11-18 01:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-11-18 06:38:30 +00:00
|
|
|
hInteractiveWindowStation = OpenWindowStation( graphics_msg.window_station, FALSE, GENERIC_READ );
|
2004-11-18 01:52:07 +00:00
|
|
|
if (NULL == hInteractiveWindowStation) {
|
2006-06-07 08:56:55 +00:00
|
|
|
BOINCINFO("Failed to retrieve the required window station\n");
|
2004-11-18 06:38:30 +00:00
|
|
|
new_mode = MODE_UNSUPPORTED;
|
2004-11-18 01:52:07 +00:00
|
|
|
} else {
|
2007-09-17 18:11:23 +00:00
|
|
|
BOINCINFO("Retrieved the required window station\n");
|
|
|
|
if (!SetProcessWindowStation(hInteractiveWindowStation)) {
|
|
|
|
BOINCINFO("Failed to SetProcessWindowStation (GLE: '%d')\n", GetLastError());
|
|
|
|
}
|
2005-06-22 17:42:10 +00:00
|
|
|
hInteractiveDesktop = OpenDesktop(
|
2007-08-10 01:51:14 +00:00
|
|
|
graphics_msg.desktop, (DWORD)NULL, FALSE,
|
2005-06-22 17:42:10 +00:00
|
|
|
GENERIC_READ | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU
|
|
|
|
);
|
2004-11-18 01:52:07 +00:00
|
|
|
if (NULL == hInteractiveDesktop) {
|
2006-06-07 08:56:55 +00:00
|
|
|
BOINCINFO("Failed to retrieve the required desktop\n");
|
2004-11-18 01:52:07 +00:00
|
|
|
new_mode = MODE_UNSUPPORTED;
|
|
|
|
} else {
|
2007-09-17 18:11:23 +00:00
|
|
|
BOINCINFO("Retrieved the required desktop\n");
|
|
|
|
if (!SetThreadDesktop(hInteractiveDesktop)) {
|
|
|
|
BOINCINFO("Failed to SetThreadDesktop (GLE: '%d')\n", GetLastError());
|
|
|
|
}
|
2004-11-18 01:52:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
current_graphics_mode = new_mode;
|
2005-05-13 00:33:04 +00:00
|
|
|
if (new_mode != MODE_HIDE_GRAPHICS && new_mode != MODE_UNSUPPORTED) {
|
2004-11-17 09:27:06 +00:00
|
|
|
make_new_window();
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
2003-10-25 20:58:27 +00:00
|
|
|
|
2003-03-04 06:01:46 +00:00
|
|
|
}
|
|
|
|
|
2004-04-02 06:04:16 +00:00
|
|
|
void parse_mouse_event(UINT uMsg, int& which, bool& down) {
|
2005-06-22 17:42:10 +00:00
|
|
|
switch(uMsg) {
|
|
|
|
case WM_LBUTTONDOWN: which = 0; down = true; break;
|
|
|
|
case WM_MBUTTONDOWN: which = 1; down = true; break;
|
|
|
|
case WM_RBUTTONDOWN: which = 2; down = true; break;
|
|
|
|
case WM_LBUTTONUP: which = 0; down = false; break;
|
|
|
|
case WM_MBUTTONUP: which = 1; down = false; break;
|
|
|
|
case WM_RBUTTONUP: which = 2; down = false; break;
|
2004-04-02 06:04:16 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-09 15:12:17 +00:00
|
|
|
|
2003-05-07 23:42:17 +00:00
|
|
|
// message handler (includes timer, Windows msgs)
|
|
|
|
//
|
2004-01-17 18:36:17 +00:00
|
|
|
LRESULT CALLBACK WndProc(
|
2005-06-22 17:42:10 +00:00
|
|
|
HWND hWnd, // Handle For This Window
|
|
|
|
UINT uMsg, // Message For This Window
|
|
|
|
WPARAM wParam, // Additional Message Information
|
|
|
|
LPARAM lParam // Additional Message Information
|
2004-01-17 18:36:17 +00:00
|
|
|
) {
|
2005-06-22 17:42:10 +00:00
|
|
|
switch(uMsg) {
|
|
|
|
case WM_ERASEBKGND: // Check To See If Windows Is Trying To Erase The Background
|
|
|
|
return 0;
|
|
|
|
case WM_KEYDOWN:
|
|
|
|
if(!window_ready) return 0;
|
2006-06-14 23:17:37 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
2005-05-13 00:33:04 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2005-05-01 04:49:51 +00:00
|
|
|
} else {
|
|
|
|
boinc_app_key_press((int)wParam, (int)lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
2005-06-22 17:42:10 +00:00
|
|
|
case WM_KEYUP:
|
|
|
|
if(!window_ready) return 0;
|
2006-06-14 23:17:37 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
2005-06-22 17:42:10 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2004-05-11 05:32:08 +00:00
|
|
|
} else {
|
2005-05-01 04:49:51 +00:00
|
|
|
boinc_app_key_release((int)wParam, (int)lParam);
|
|
|
|
}
|
2004-04-02 06:04:16 +00:00
|
|
|
return 0;
|
2005-06-22 17:42:10 +00:00
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
if(!window_ready) return 0;
|
|
|
|
|
2006-06-14 23:17:37 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
2005-05-13 00:33:04 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2005-06-22 17:42:10 +00:00
|
|
|
} else {
|
2004-04-02 06:04:16 +00:00
|
|
|
int which;
|
|
|
|
bool down;
|
2005-06-22 17:42:10 +00:00
|
|
|
POINT cPos;
|
|
|
|
GetCursorPos(&cPos);
|
2004-04-02 06:04:16 +00:00
|
|
|
parse_mouse_event(uMsg, which, down);
|
2005-06-22 17:42:10 +00:00
|
|
|
boinc_app_mouse_button(cPos.x, cPos.y, which, down);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
if(!window_ready) return 0;
|
|
|
|
POINT cPos;
|
|
|
|
GetCursorPos(&cPos);
|
2006-06-14 23:17:37 +00:00
|
|
|
if (current_graphics_mode == MODE_FULLSCREEN) {
|
2005-05-01 04:49:51 +00:00
|
|
|
if(cPos.x != mousePos.x || cPos.y != mousePos.y) {
|
2005-06-22 17:42:10 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
boinc_app_mouse_move(
|
2004-04-02 06:04:16 +00:00
|
|
|
cPos.x, cPos.y,
|
|
|
|
(wParam&MK_LBUTTON)!=0,
|
|
|
|
(wParam&MK_MBUTTON)!=0,
|
|
|
|
(wParam&MK_RBUTTON)!=0
|
|
|
|
);
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case WM_CLOSE:
|
2003-11-06 20:27:07 +00:00
|
|
|
if (boinc_is_standalone()) {
|
2006-03-11 21:30:26 +00:00
|
|
|
boinc_exit(0);
|
2003-10-14 20:37:02 +00:00
|
|
|
} else {
|
2005-05-13 19:41:11 +00:00
|
|
|
if (current_graphics_mode != MODE_FULLSCREEN) {
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
case WM_POWERBROADCAST:
|
2006-02-23 07:54:11 +00:00
|
|
|
if (PBT_APMSUSPEND == wParam) {
|
2005-05-13 19:41:11 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2006-02-23 07:54:11 +00:00
|
|
|
suspend_activities();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (PBT_APMQUERYSUSPENDFAILED == wParam || PBT_APMRESUMESUSPEND == wParam) {
|
|
|
|
set_mode(acked_graphics_mode);
|
2006-03-02 08:28:23 +00:00
|
|
|
restore_activities();
|
2006-02-23 07:54:11 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (PBT_APMQUERYSUSPEND == wParam) {
|
2005-05-13 19:41:11 +00:00
|
|
|
return TRUE;
|
2003-10-14 20:37:02 +00:00
|
|
|
}
|
2005-05-13 19:41:11 +00:00
|
|
|
break;
|
2005-06-22 17:42:10 +00:00
|
|
|
case WM_PAINT:
|
|
|
|
PAINTSTRUCT ps;
|
|
|
|
RECT winRect;
|
|
|
|
HDC pdc;
|
2007-08-10 01:51:14 +00:00
|
|
|
if (!graphics_threadh) graphics_threadh=(HANDLE)GetCurrentThreadId();
|
2005-06-22 17:42:10 +00:00
|
|
|
pdc = BeginPaint(hWnd, &ps);
|
|
|
|
GetClientRect(hWnd, &winRect);
|
|
|
|
FillRect(pdc, &winRect, (HBRUSH)GetStockObject(BLACK_BRUSH));
|
|
|
|
EndPaint(hWnd, &ps);
|
|
|
|
return 0;
|
|
|
|
case WM_SIZE:
|
2004-03-24 22:43:10 +00:00
|
|
|
if ( SIZE_MINIMIZED == wParam ) {
|
|
|
|
visible = FALSE;
|
|
|
|
} else {
|
|
|
|
visible = TRUE;
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
|
|
|
if(!window_ready) return 0;
|
|
|
|
app_graphics_resize(LOWORD(lParam), HIWORD(lParam));
|
|
|
|
return 0;
|
2006-02-23 07:54:11 +00:00
|
|
|
case WM_SHUTDOWNGFX:
|
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
|
|
|
return 0;
|
2004-12-19 04:27:02 +00:00
|
|
|
default:
|
|
|
|
if ( WM_BOINCSFW == uMsg ) {
|
|
|
|
SetForegroundWindow(hWnd);
|
|
|
|
}
|
2005-06-22 17:42:10 +00:00
|
|
|
}
|
2003-10-09 06:00:05 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
// Pass All Unhandled Messages To DefWindowProc
|
|
|
|
return DefWindowProc(hWnd,uMsg,wParam,lParam);
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL reg_win_class() {
|
2005-06-22 17:42:10 +00:00
|
|
|
WNDCLASS wc; // Windows Class Structure
|
|
|
|
|
|
|
|
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
|
|
|
// Redraw On Size, And Own DC For Window.
|
|
|
|
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
|
|
|
|
wc.cbClsExtra = 0; // No Extra Window Data
|
|
|
|
wc.cbWndExtra = 0; // No Extra Window Data
|
|
|
|
wc.hInstance = hInstance; // Set The Instance
|
|
|
|
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
|
|
|
|
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
|
|
|
|
wc.hbrBackground = NULL; // No Background Required For GL
|
|
|
|
wc.lpszMenuName = NULL; // We Don't Want A Menu
|
|
|
|
wc.lpszClassName = BOINC_WINDOW_CLASS_NAME; // Set The Class Name
|
|
|
|
|
|
|
|
// Attempt To Register The Window Class
|
|
|
|
if (!RegisterClass(&wc)) {
|
|
|
|
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
|
|
|
|
return FALSE; // Return FALSE
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL unreg_win_class() {
|
2005-06-22 17:42:10 +00:00
|
|
|
if (!UnregisterClass(BOINC_WINDOW_CLASS_NAME,hInstance)) {
|
|
|
|
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
|
|
|
|
hInstance=NULL; // Set hInstance To NULL
|
|
|
|
}
|
2003-10-09 06:00:05 +00:00
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
return TRUE;
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static VOID CALLBACK timer_handler(HWND, UINT, UINT, DWORD) {
|
2005-06-22 17:42:10 +00:00
|
|
|
RECT rt;
|
|
|
|
int width, height;
|
2004-07-08 03:38:52 +00:00
|
|
|
char buf[MSG_CHANNEL_SIZE];
|
2006-12-07 17:30:48 +00:00
|
|
|
if (g_sleep) return;
|
2004-06-12 05:10:54 +00:00
|
|
|
|
|
|
|
// check for graphics-related message from core client
|
|
|
|
//
|
2004-01-17 18:36:17 +00:00
|
|
|
if (app_client_shm) {
|
2004-07-08 03:38:52 +00:00
|
|
|
if (app_client_shm->shm->graphics_request.get_msg(buf)) {
|
2006-06-07 08:56:55 +00:00
|
|
|
BOINCINFO("Received Graphics Message: %s", buf);
|
2004-11-17 19:19:26 +00:00
|
|
|
app_client_shm->decode_graphics_msg(buf, graphics_msg);
|
|
|
|
switch (graphics_msg.mode) {
|
2004-07-08 03:38:52 +00:00
|
|
|
case MODE_REREAD_PREFS:
|
2005-06-22 17:42:10 +00:00
|
|
|
// only reread graphics prefs if we have a window open
|
|
|
|
//
|
|
|
|
switch(current_graphics_mode) {
|
|
|
|
case MODE_WINDOW:
|
|
|
|
case MODE_FULLSCREEN:
|
|
|
|
app_graphics_reread_prefs();
|
|
|
|
break;
|
|
|
|
}
|
2004-01-17 18:36:17 +00:00
|
|
|
break;
|
2004-07-08 03:38:52 +00:00
|
|
|
case MODE_HIDE_GRAPHICS:
|
|
|
|
case MODE_WINDOW:
|
|
|
|
case MODE_FULLSCREEN:
|
|
|
|
case MODE_BLANKSCREEN:
|
2004-11-17 19:19:26 +00:00
|
|
|
set_mode(graphics_msg.mode);
|
2004-07-08 03:38:52 +00:00
|
|
|
break;
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
2003-10-09 06:00:05 +00:00
|
|
|
}
|
2004-07-18 04:41:27 +00:00
|
|
|
// ack graphics mode
|
|
|
|
//
|
|
|
|
if (acked_graphics_mode != current_graphics_mode) {
|
|
|
|
bool sent = app_client_shm->shm->graphics_reply.send_msg(
|
2004-11-18 01:52:07 +00:00
|
|
|
xml_graphics_modes[current_graphics_mode]
|
2004-07-18 04:41:27 +00:00
|
|
|
);
|
|
|
|
if (sent) acked_graphics_mode = current_graphics_mode;
|
|
|
|
}
|
|
|
|
}
|
2004-01-17 18:36:17 +00:00
|
|
|
if (!visible) return;
|
2005-06-22 17:42:10 +00:00
|
|
|
if (current_graphics_mode == MODE_HIDE_GRAPHICS) return;
|
2004-01-17 18:36:17 +00:00
|
|
|
if (!hWnd) return;
|
2003-02-25 00:25:07 +00:00
|
|
|
|
2004-01-17 18:36:17 +00:00
|
|
|
// TODO: remove width, height from API
|
|
|
|
//
|
2005-06-22 17:42:10 +00:00
|
|
|
GetClientRect(hWnd, &rt);
|
|
|
|
width = rt.right-rt.left;
|
|
|
|
height = rt.bottom-rt.top;
|
2004-01-17 18:36:17 +00:00
|
|
|
|
|
|
|
if (throttled_app_render(width, height, dtime())) {
|
2005-06-22 17:42:10 +00:00
|
|
|
SwapBuffers(hDC);
|
2004-01-17 18:36:17 +00:00
|
|
|
}
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
2004-10-11 23:57:07 +00:00
|
|
|
void win_graphics_event_loop() {
|
2007-01-24 19:31:49 +00:00
|
|
|
MSG msg;
|
2003-03-04 06:01:46 +00:00
|
|
|
|
2007-01-24 19:31:49 +00:00
|
|
|
// Get platform information
|
|
|
|
//
|
2005-05-22 02:12:31 +00:00
|
|
|
OSVERSIONINFO osvi;
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof(osvi);
|
|
|
|
GetVersionEx(&osvi);
|
|
|
|
is_windows_9x = (osvi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS);
|
|
|
|
|
2005-06-22 17:42:10 +00:00
|
|
|
// Register window class and graphics mode message
|
2007-01-24 19:31:49 +00:00
|
|
|
//
|
2005-06-22 17:42:10 +00:00
|
|
|
reg_win_class();
|
2003-03-04 06:01:46 +00:00
|
|
|
|
2007-04-19 20:53:16 +00:00
|
|
|
gfx_timer_id = SetTimer(NULL, 1, 30, (TIMERPROC)&timer_handler);
|
2004-01-17 18:36:17 +00:00
|
|
|
|
2003-11-06 20:27:07 +00:00
|
|
|
if (boinc_is_standalone()) {
|
2004-06-12 05:10:54 +00:00
|
|
|
set_mode(MODE_WINDOW);
|
2003-08-21 23:44:57 +00:00
|
|
|
} else {
|
2004-06-12 05:10:54 +00:00
|
|
|
set_mode(MODE_HIDE_GRAPHICS);
|
2003-08-21 23:44:57 +00:00
|
|
|
}
|
2007-01-24 19:31:49 +00:00
|
|
|
while (1) {
|
2005-06-22 17:42:10 +00:00
|
|
|
if (GetMessage(&msg,NULL,0,0)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unreg_win_class();
|
|
|
|
|
|
|
|
SetEvent(hQuitEvent); // Signal the worker thread that we're quitting
|
2002-09-18 22:15:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_462f482d81 = "$Id$";
|