protected override void OnClick(EventArgs e) { try { SEBWindowHandler.BringWindowToTop( SEBWindowHandler.GetOpenWindows() .First(w => w.Key.GetProcess().GetExecutableName().Contains("xul")).Key); if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyTouchOptimized]) { if ((bool)SEBSettings.settingsCurrent[SEBSettings.KeyShowReloadWarning]) { if ( SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage, MessageBoxIcon.Warning, MessageBoxButtons.YesNo) == DialogResult.Yes) { SEBXULRunnerWebSocketServer.SendReloadPage(); } } else { SEBXULRunnerWebSocketServer.SendReloadPage(); } } else { SEBXULRunnerWebSocketServer.SendReloadPage(); } } catch {} }
protected override void OnClick(EventArgs e) { try { SEBWindowHandler.BringWindowToTop(SEBWindowHandler.GetOpenWindows().First <KeyValuePair <IntPtr, string> >((Func <KeyValuePair <IntPtr, string>, bool>)(w => w.Key.GetProcess().GetExecutableName().Contains("xul"))).Key); if ((bool)SEBSettings.settingsCurrent["touchOptimized"]) { if ((bool)SEBSettings.settingsCurrent["showReloadWarning"]) { if (SEBMessageBox.Show(SEBUIStrings.reloadPage, SEBUIStrings.reloadPageMessage, MessageBoxIcon.Exclamation, MessageBoxButtons.YesNo, false) != DialogResult.Yes) { return; } SEBXULRunnerWebSocketServer.SendReloadPage(); } else { SEBXULRunnerWebSocketServer.SendReloadPage(); } } else { SEBXULRunnerWebSocketServer.SendReloadPage(); } } catch { } }
private void SetKeyboardLayoutAccordingToIndex() { try { InputLanguage.CurrentInputLanguage = InputLanguage.InstalledInputLanguages[currentIndex]; var threadIdOfCurrentForegroundWindow = GetWindowThreadProcessId(SEBWindowHandler.GetForegroundWindow(), IntPtr.Zero); var currentKeyboardLayout = GetKeyboardLayout(threadIdOfCurrentForegroundWindow); //This is for Windows 7 if (languages[currentIndex].ToInt32() != currentKeyboardLayout) { PostMessage(SEBWindowHandler.GetForegroundWindow(), WM_INPUTLANGCHANGEREQUEST, IntPtr.Zero, languages[currentIndex] ); } } catch (Exception ex) { Logger.AddError("Could not change InputLanguage", this, ex); } UpdateDisplayText(); }
/// ---------------------------------------------------------------------------------------- /// <summary> /// Fill listApplications with running Applications, lWindowHandles with Window Handles /// of running Applications and ilApplicationIcons with running Applications Icons. /// </summary> /// ---------------------------------------------------------------------------------------- public void SelectNextListItem() { //this.Focus(); if (this.listApplications.Items.Count > 0) { if (selectedItemIndex >= listApplications.Items.Count) { selectedItemIndex = 0; } //int lastSelectedItemIndex = selectedItemIndex - 1; //if (lastSelectedItemIndex < 0) //{ // lastSelectedItemIndex = listApplications.Items.Count - 1; //} this.listApplications.Items[selectedItemIndex].Selected = true; this.listApplications.Items[selectedItemIndex].Focused = true; string selectedThreadName = this.listApplications.Items[selectedItemIndex].Text; //if (!selectedThreadName.Contains("xulrunner")) //{ //this.listApplications.Items[selectedItemIndex].ForeColor = Color.White; //this.listApplications.Items[lastSelectedItemIndex].ForeColor = Color.Black; ; //uint selectedWindowThreadId = GetWindowThreadProcessId(this.Handle, IntPtr.Zero); IntPtr hWndForegroundWindow = GetForegroundWindow(); uint activeThreadID = GetWindowThreadProcessId(hWndForegroundWindow, IntPtr.Zero); uint currentThreadID = GetCurrentThreadId(); //GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero); AttachThreadInput(activeThreadID, currentThreadID, true); var hwnd = lWindowHandles[selectedItemIndex]; if (hwnd == IntPtr.Zero) { //Try open by window name comparing with title set in config which then is set to the tooltip of the button :) foreach ( var windowHandle in SEBWindowHandler.GetWindowHandlesByTitle(this.lWindowTitles[selectedItemIndex])) { windowHandle.BringToTop(); } } else { hwnd.BringToTop(); } AttachThreadInput(activeThreadID, currentThreadID, false); //} //else //{ // IntPtr hWndForegroundWindow = GetForegroundWindow(); // uint activeThreadID = GetWindowThreadProcessId(hWndForegroundWindow, IntPtr.Zero); // uint currentThreadID = GetCurrentThreadId(); //GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero); // AttachThreadInput(activeThreadID, currentThreadID, true); // SetForegroundWindow(lWindowHandles[selectedItemIndex]); // //BringWindowToTop(lWindowHandles[selectedItemIndex]); // //ShowWindow(lWindowHandles[selectedItemIndex], WindowShowStyle.ShowNormal); // AttachThreadInput(activeThreadID, currentThreadID, false); //} selectedItemIndex++; this.listApplications.Focus(); } }
protected override void OnClick(EventArgs e) { try { SEBWindowHandler.BringWindowToTop( SEBWindowHandler.GetOpenWindows() .First(w => w.Key.GetProcess().GetExecutableName().Contains("firefox")).Key); } catch { } }
private void btnCancel_Click(object sender, EventArgs e) { this.txtQuitPassword.Text = ""; this.Visible = false; if ((bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyTouchOptimized)) { var topWindow = SEBWindowHandler.GetOpenWindows().FirstOrDefault(); if (topWindow.Value != null) { topWindow.Key.AdaptWindowToWorkingArea(); } } }
private void btnCancel_Click(object sender, EventArgs e) { this.txtQuitPassword.Text = ""; this.Visible = false; if (!(bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "touchOptimized")) { return; } KeyValuePair <IntPtr, string> keyValuePair = SEBWindowHandler.GetOpenWindows().FirstOrDefault <KeyValuePair <IntPtr, string> >(); if (keyValuePair.Value == null) { return; } keyValuePair.Key.AdaptWindowToWorkingArea(new int?()); }
private void SetKeyboardLayoutAccordingToIndex() { try { InputLanguage.CurrentInputLanguage = InputLanguage.InstalledInputLanguages[this.currentIndex]; if ((long)this.languages[this.currentIndex].ToInt32() != (long)SEBInputLanguageToolStripButton.GetKeyboardLayout(SEBInputLanguageToolStripButton.GetWindowThreadProcessId(SEBWindowHandler.GetForegroundWindow(), IntPtr.Zero))) { SEBInputLanguageToolStripButton.PostMessage(SEBWindowHandler.GetForegroundWindow(), 80U, IntPtr.Zero, this.languages[this.currentIndex]); } } catch (Exception ex) { Logger.AddError("Could not change InputLanguage", (object)this, ex, (string)null); } this.UpdateDisplayText(); }
private void ResizeTopOpenWindow() { try { if ((bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, SEBSettings.KeyTouchOptimized)) { var topWindow = SEBWindowHandler.GetOpenWindows().FirstOrDefault(); if (topWindow.Value != null) { topWindow.Key.AdaptWindowToWorkingArea(); } } } catch { } }
private void ResizeTopOpenWindow() { try { if (!(bool)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "touchOptimized")) { return; } KeyValuePair <IntPtr, string> keyValuePair = SEBWindowHandler.GetOpenWindows().FirstOrDefault <KeyValuePair <IntPtr, string> >(); if (keyValuePair.Value == null) { return; } keyValuePair.Key.AdaptWindowToWorkingArea(new int?()); } catch { } }
private static void KillExplorerShell() { SEBClientInfo.ExplorerShellWasKilled = false; //Minimize all Open Windows try { SEBWindowHandler.MinimizeAllOpenWindows(); } catch (Exception ex) { Logger.AddError("Unable to MinimizeAllOpenWindows", null, ex); } //Kill the explorer Shell try { SEBClientInfo.ExplorerShellWasKilled = SEBProcessHandler.KillExplorerShell(); } catch (Exception ex) { Logger.AddError("Unable to KillExplorerShell", null, ex); } }
public static bool InitSEBDesktop() { Logger.AddInformation("Attempting to InitSEBDesktop", (object)null, (Exception)null, (string)null); SEBDesktopWallpaper.BlankWallpaper(); SEBClipboard.CleanClipboard(); Logger.AddInformation("Clipboard cleaned.", (object)null, (Exception)null, (string)null); SEBWindowHandler.AllowedExecutables.Clear(); SEBWindowHandler.AllowedExecutables.Add("safeexambrowser"); foreach (Dictionary <string, object> permittedProcess in SEBSettings.permittedProcessList) { if ((bool)permittedProcess["active"]) { SEBWindowHandler.AllowedExecutables.Add(((string)permittedProcess["executable"]).ToLower()); if (!string.IsNullOrWhiteSpace(permittedProcess["windowHandlingProcess"].ToString())) { SEBWindowHandler.AllowedExecutables.Add(((string)permittedProcess["windowHandlingProcess"]).ToLower()); } } } if ((bool)SEBClientInfo.getSebSetting("monitorProcesses")["monitorProcesses"]) { try { SEBWindowHandler.EnableForegroundWatchDog(); } catch (Exception ex) { Logger.AddError("Unable to EnableForegroundWatchDog", (object)null, ex, (string)null); } SEBProcessHandler.ProhibitedExecutables.Clear(); foreach (Dictionary <string, object> prohibitedProcess in SEBSettings.prohibitedProcessList) { if ((bool)prohibitedProcess["active"]) { SEBProcessHandler.ProhibitedExecutables.Add(((string)prohibitedProcess["executable"]).ToLower()); } } try { SEBProcessHandler.EnableProcessWatchDog(); } catch (Exception ex) { Logger.AddError("Unable to EnableProcessWatchDog", (object)null, ex, (string)null); } } SEBClientInfo.ExplorerShellWasKilled = false; if ((bool)SEBClientInfo.getSebSetting("killExplorerShell")["killExplorerShell"]) { try { SEBWindowHandler.MinimizeAllOpenWindows(false); } catch (Exception ex) { Logger.AddError("Unable to MinimizeAllOpenWindows", (object)null, ex, (string)null); } try { SEBClientInfo.ExplorerShellWasKilled = SEBProcessHandler.KillExplorerShell(); } catch (Exception ex) { Logger.AddError("Unable to KillExplorerShell", (object)null, ex, (string)null); } } Logger.AddInformation("Successfully InitSEBDesktop", (object)null, (Exception)null, (string)null); return(true); }
/// ---------------------------------------------------------------------------------------- /// <summary> /// Create and initialize new desktop. /// </summary> /// <returns>true if succeeded</returns> /// ---------------------------------------------------------------------------------------- public static bool InitSEBDesktop() { //Info: For reverting this actions see SebWindowsClientForm::CloseSEBForm() Logger.AddInformation("Attempting to InitSEBDesktop"); //Blank the Wallpaper SEBDesktopWallpaper.BlankWallpaper(); // Clean clipboard SEBClipboard.CleanClipboard(); Logger.AddInformation("Clipboard cleaned.", null, null); //Search for permitted Applications (used in Taskswitcher (ALT-TAB) and in foreground watchdog SEBWindowHandler.AllowedExecutables.Clear(); //Add the SafeExamBrowser to the allowed executables SEBWindowHandler.AllowedExecutables.Add("safeexambrowser"); //Add allowed executables from all allowedProcessList foreach (Dictionary <string, object> process in SEBSettings.permittedProcessList) { if ((bool)process[SEBSettings.KeyActive]) { //First add the executable itself SEBWindowHandler.AllowedExecutables.Add( ((string)process[SEBSettings.KeyExecutable]).ToLower()); if (!String.IsNullOrWhiteSpace(process[SEBSettings.KeyWindowHandlingProcess].ToString())) { SEBWindowHandler.AllowedExecutables.Add( ((string)process[SEBSettings.KeyWindowHandlingProcess]).ToLower()); } } } #if DEBUG //Add visual studio to allowed executables for debugging SEBWindowHandler.AllowedExecutables.Add("devenv"); #endif //Process watching if ((Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyMonitorProcesses)[SEBSettings.KeyMonitorProcesses] || (Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyKillExplorerShell)[SEBSettings.KeyKillExplorerShell]) { #region Foreground Window Watching (Allowed Executables) //This prevents the not allowed executables from poping up try { SEBWindowHandler.EnableForegroundWatchDog(); } catch (Exception ex) { Logger.AddError("Unable to EnableForegroundWatchDog", null, ex); } #endregion #region Prohibited Executables watching //Handle prohibited executables watching SEBProcessHandler.ProhibitedExecutables.Clear(); //Add prohibited executables foreach (Dictionary <string, object> process in SEBSettings.prohibitedProcessList) { if ((bool)process[SEBSettings.KeyActive]) { //First add the executable itself SEBProcessHandler.ProhibitedExecutables.Add( ((string)process[SEBSettings.KeyExecutable]).ToLower()); } } //This prevents the prohibited executables from starting up try { SEBProcessHandler.EnableProcessWatchDog(); } catch (Exception ex) { Logger.AddError("Unable to EnableProcessWatchDog", null, ex); } #endregion } //Kill Explorer Shell // Global variable indicating if the explorer shell has been killed SEBClientInfo.ExplorerShellWasKilled = false; if ((Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyKillExplorerShell)[SEBSettings.KeyKillExplorerShell]) { //Minimize all Open Windows try { SEBWindowHandler.MinimizeAllOpenWindows(); } catch (Exception ex) { Logger.AddError("Unable to MinimizeAllOpenWindows", null, ex); } //Kill the explorer Shell try { SEBClientInfo.ExplorerShellWasKilled = SEBProcessHandler.KillExplorerShell(); } catch (Exception ex) { Logger.AddError("Unable to KillExplorerShell", null, ex); } } Logger.AddInformation("Successfully InitSEBDesktop"); return(true); }
/// ---------------------------------------------------------------------------------------- /// <summary> /// Fill listApplications with running Applications, lWindowHandles with Window Handles /// of running Applications and ilApplicationIcons with running Applications Icons. /// </summary> /// ---------------------------------------------------------------------------------------- public void fillListApplications() { List <string> lRunningApplications = new List <string>(); ImageList ilApplicationIcons = new ImageList(); int iconSize = (int)(32 * SEBClientInfo.scaleFactor); if ((Boolean)SEBClientInfo.getSebSetting(SEBSettings.KeyTouchOptimized)[SEBSettings.KeyTouchOptimized] == true) { iconSize = (int)(48 * SEBClientInfo.scaleFactor); } ilApplicationIcons.ImageSize = new Size(iconSize, iconSize); ilApplicationIcons.ColorDepth = ColorDepth.Depth32Bit; this.lWindowHandles.Clear(); int index = 0; foreach (var oW in SEBWindowHandler.GetOpenWindows()) { if (oW.Key.IsAllowed()) { this.lWindowHandles.Add(oW.Key); this.lWindowTitles.Add(oW.Value); lRunningApplications.Add(oW.Value); if (oW.Key.GetProcess().ProcessName.Contains("xulrunner")) { Bitmap sebIconBitmap = Icon.ExtractAssociatedIcon(Application.ExecutablePath).ToBitmap(); //sebIconBitmap.MakeTransparent(BackColor); ilApplicationIcons.Images.Add(sebIconBitmap); } else { Image image = GetSmallWindowIcon(oW.Key); ilApplicationIcons.Images.Add("rAppIcon" + index, image); } index++; } } // Suspending automatic refreshes as items are added/removed. this.listApplications.BeginUpdate(); this.listApplications.Clear(); this.listApplications.View = View.LargeIcon; this.listApplications.LargeImageList = ilApplicationIcons; this.listApplications.Scrollable = false; //listApplications.SmallImageList = imagesSmall; //listApplications.LargeImageList = imagesLarge; int appItemsTotalWidth = 0; int appItemsMaxHeight = 0; for (int i = 0; i < lRunningApplications.Count(); i++) { ListViewItem listItem = new ListViewItem(lRunningApplications[i]); listItem.ImageIndex = i; this.listApplications.Items.Add(listItem); Rectangle listItemRect = this.listApplications.GetItemRect(i); Logger.AddInformation("ListView.GetItemRect: " + listItemRect.ToString(), null, null); appItemsTotalWidth += listItemRect.Width; if (listItemRect.Height > appItemsMaxHeight) { appItemsMaxHeight = listItemRect.Height; } } this.listApplications.Dock = DockStyle.Fill; this.listApplications.AutoSize = true; //this.Width = listApplications.Items.Count*128; // Calculate necessary size of the app chooser form according to number of applications/icons int numberIcons = lRunningApplications.Count(); int formWidth; float scaleFactor = SEBClientInfo.scaleFactor; //if (numberIcons > 0) formWidth = (int)Math.Round(2 * appChooserFormXPadding * scaleFactor + numberIcons * 32 + (numberIcons - 1) * appChooserFormXGap * scaleFactor); //else formWidth = (int)Math.Round(2 * appChooserFormXPadding * scaleFactor); //if (numberIcons > 0) formWidth = (int)Math.Round((2 * appChooserFormXPadding + appItemsTotalWidth) * scaleFactor); if (numberIcons > 0) { formWidth = (int)Math.Round(2 * appChooserFormXPadding * scaleFactor + appItemsTotalWidth); } else { formWidth = (int)Math.Round(2 * appChooserFormXPadding * scaleFactor); } // Check if calculated width is larger that current screen width, if yes, adjust height accordingly if (Screen.PrimaryScreen.Bounds.Width < formWidth) { formWidth = Screen.PrimaryScreen.Bounds.Width; this.Height = (int)Math.Round((2 * appChooserFormXPadding + 2 * appItemsMaxHeight + appChooserFormXPadding) * scaleFactor); } else { this.Width = formWidth; this.Height = (int)Math.Round(2 * appChooserFormXPadding * scaleFactor + appItemsMaxHeight); //this.Height = (int)Math.Round(SEBClientInfo.appChooserHeight * scaleFactor); } int formHeight = this.Height; listApplications.Height = formHeight - 24; this.CenterToScreen(); // Re-enable the display. this.listApplications.EndUpdate(); if (this.listApplications.Items.Count == 1) { //this.listApplications.Items[0].Selected = true; selectedItemIndex = 0; } if (this.listApplications.Items.Count > 1) { //this.listApplications.Items[1].Selected = true; selectedItemIndex = 1; } SelectNextListItem(); }