void set_mode(int mode) { if (mode == current_graphics_mode) { // Bring graphics window to front whenever user presses "Show graphics" if (mode == MODE_WINDOW) { #ifdef __APPLE__ BringAppToFront(); #else if (glut_is_freeglut && FREEGLUT_IS_INITIALIZED && (GLUT_HAVE_WINDOW > 0)) { // glutPopWindow(); glutShowWindow(); } #endif } return; } if (debug) fprintf(stderr, "set_mode(%d): current_mode = %d.\n", mode, current_graphics_mode); if (glut_is_initialized) { if (debug) fprintf(stderr, "Calling KillWindow(): win = %d\n", win); KillWindow(); if (debug) fprintf(stderr, "KillWindow() survived.\n"); } if (mode != MODE_HIDE_GRAPHICS) { if (debug) fprintf(stderr, "set_mode(): Calling make_new_window(%d)\n", mode); make_new_window(mode); if (debug) fprintf(stderr, "make_new_window() survived.\n"); } #ifdef __APPLE__ else HideThisApp(); #endif current_graphics_mode = mode; return; }
// 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 // static void set_mode(int mode) { int new_mode = mode; GRAPHICS_MSG current_desktop; if (mode == current_graphics_mode) return; if (current_graphics_mode != MODE_FULLSCREEN) { if (IsIconic(hWnd) || IsZoomed(hWnd)){ // If graphics window is minimized or maximized // then set default values of window size rect.left = 50; rect.top = 50; rect.right = 50+640; rect.bottom = 50+480; } else GetWindowRect(hWnd, &rect); // else get current values } KillWindow(); // 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() && strlen(graphics_msg.window_station) > 0 && strlen(graphics_msg.desktop) > 0 && (strcmp(current_desktop.window_station, graphics_msg.window_station) || strcmp(current_desktop.desktop, graphics_msg.desktop))) { BOINCINFO("Checking Desktop and Window Station Parameters\n"); GetDesktopWindow(); if (NULL == hOriginalWindowStation) { hOriginalWindowStation = GetProcessWindowStation(); if (NULL == hOriginalWindowStation) { BOINCINFO("Failed to retrieve the orginal window station\n"); } } if (NULL == hOriginalDesktop) { hOriginalDesktop = GetThreadDesktop(GetCurrentThreadId()); if (NULL == hOriginalDesktop) { BOINCINFO("Failed to retrieve the orginal desktop\n"); } } hInteractiveWindowStation = OpenWindowStation( graphics_msg.window_station, FALSE, GENERIC_READ ); if (NULL == hInteractiveWindowStation) { BOINCINFO("Failed to retrieve the required window station\n"); new_mode = MODE_UNSUPPORTED; } else { BOINCINFO("Retrieved the required window station\n"); if (!SetProcessWindowStation(hInteractiveWindowStation)) { BOINCINFO("Failed to SetProcessWindowStation (GLE: '%d')\n", GetLastError()); } hInteractiveDesktop = OpenDesktop( graphics_msg.desktop, (DWORD)NULL, FALSE, GENERIC_READ | DESKTOP_CREATEWINDOW | DESKTOP_CREATEMENU ); if (NULL == hInteractiveDesktop) { BOINCINFO("Failed to retrieve the required desktop\n"); new_mode = MODE_UNSUPPORTED; } else { BOINCINFO("Retrieved the required desktop\n"); if (!SetThreadDesktop(hInteractiveDesktop)) { BOINCINFO("Failed to SetThreadDesktop (GLE: '%d')\n", GetLastError()); } } } } current_graphics_mode = new_mode; if (new_mode != MODE_HIDE_GRAPHICS && new_mode != MODE_UNSUPPORTED) { make_new_window(); } }