protected override int EvaluatePoints(WindowHandle handle) { if (!WindowManagerMethods.IsTopLevel(handle.Handle)) { return -1; } int points = 0; //Class exact match if (!string.IsNullOrEmpty(Class)) { string wndClass = handle.Class; if (wndClass.StartsWith(Class, StringComparison.InvariantCulture)){ points += 10; } } //Title match (may not be exact, but let's try) if (!string.IsNullOrEmpty(Title) && !string.IsNullOrEmpty(handle.Title)) { if (handle.Title.StartsWith(Title, StringComparison.InvariantCultureIgnoreCase)) { points += 10; } if (handle.Title.Equals(Title, StringComparison.InvariantCultureIgnoreCase)) { points += 5; } } //Handle match (will probably not work, but anyhow) if (Handle != IntPtr.Zero) { if (Handle == handle.Handle) { points += 10; } } return points; }
protected override int EvaluatePoints(WindowHandle handle) { //Skip empty titles if (string.IsNullOrEmpty(handle.Title)) return -1; //Skip non top-level windows if (!WindowManagerMethods.IsTopLevel(handle.Handle)) return -1; string handleTitle = handle.Title.ToLowerInvariant(); int points = 0; //Give points for partial match if (handleTitle.Equals(TitleMatch)) { points += 20; } else if (handleTitle.StartsWith(TitleMatch)) { points += 15; } else if (handleTitle.Contains(TitleMatch)) { points += 10; } return points; }
protected override bool InspectWindow(WindowHandle handle) { //Code taken from: http://www.thescarms.com/VBasic/alttab.aspx //Reject empty titles if (string.IsNullOrEmpty(handle.Title)) return true; //Accept windows that // - are visible // - do not have a parent // - have no owner and are not Tool windows OR // - have an owner and are App windows if ((long)WindowManagerMethods.GetParent(handle.Handle) == 0) { bool hasOwner = (long)WindowManagerMethods.GetWindow(handle.Handle, WindowManagerMethods.GetWindowMode.GW_OWNER) != 0; WindowMethods.WindowExStyles exStyle = (WindowMethods.WindowExStyles)WindowMethods.GetWindowLong(handle.Handle, WindowMethods.WindowLong.ExStyle); if (((exStyle & WindowMethods.WindowExStyles.ToolWindow) == 0 && !hasOwner) || //unowned non-tool window ((exStyle & WindowMethods.WindowExStyles.AppWindow) == WindowMethods.WindowExStyles.AppWindow && hasOwner)) { //owned application window _list.Add(handle); } } return true; }
protected override bool InspectWindow(WindowHandle handle) { int points = EvaluatePoints(handle); if(points >= 0){ _sortingList.Add(new Tuple<int, WindowHandle>(points, handle)); } return true; }
private bool RefreshCallback(IntPtr hwnd, IntPtr lParam) { //Skip owner if (hwnd == OwnerHandle) return true; if (SkipNotVisibleWindows && !WindowManagerMethods.IsWindowVisible(hwnd)) return true; //Extract basic properties string title = WindowMethods.GetWindowText(hwnd); var handle = new WindowHandle(hwnd, title); return InspectWindow(handle); }
protected override int EvaluatePoints(WindowHandle handle) { if(string.IsNullOrEmpty(handle.Class)) return -1; int points = 0; //Partial match if (handle.Class.StartsWith(ClassName, StringComparison.InvariantCulture)) points += 10; if (handle.Class.Equals(ClassName, StringComparison.InvariantCulture)) points += 10; return points; }
protected override int EvaluatePoints(WindowHandle handle) { //Skip empty titles if (string.IsNullOrEmpty(handle.Title)) return -1; //Skip non top-level windows if (!WindowManagerMethods.IsTopLevel(handle.Handle)) return -1; int points = 0; //Give points for partial match if (handle.Title.StartsWith(TitleMatch, StringComparison.InvariantCultureIgnoreCase)) points += 10; //Give points for exact match if (handle.Title.Equals(TitleMatch, StringComparison.InvariantCultureIgnoreCase)) points += 10; return points; }
public void ReadWriteProperties() { // ReSharper disable ConvertToConstant.Local int height = 123; int width = 456; int x = 789; int y = 246; string title = "AbCdEfGh!!"; // ReSharper restore ConvertToConstant.Local WindowHandle handle = new WindowHandle() { Handle = new IntPtr(1234) }; Window w = new Window {Height = height, Width = width, X = x, Y = y, Title = title, Handle = handle}; Assert.AreEqual(w.Height, height); Assert.AreEqual(w.Width, width); Assert.AreEqual(w.X, x); Assert.AreEqual(w.Y, y); Assert.AreEqual(w.Title, title); Assert.AreEqual(w.Handle, handle); }
public void WindowHandle() { WindowHandle wh1 = new WindowHandle(); Assert.NotNull(wh1); WindowHandle wh2 = new WindowHandle(); Assert.NotNull(wh2); WindowHandle wh3 = new WindowHandle(); Assert.NotNull(wh3); IntPtr ptr1 = new IntPtr(2222); IntPtr ptr2 = new IntPtr(3333); wh1.Handle = ptr1; wh2.Handle = ptr1; wh3.Handle = ptr2; Assert.True(wh1 == wh2); Assert.False(wh1 == wh3); Assert.False(wh1.Equals(wh3)); }
protected unsafe override LResult WindowProcedure(WindowHandle window, MessageType message, WParam wParam, LParam lParam) { const string filter = "*.*"; switch (message) { case MessageType.Create: Size baseUnits = Windows.GetDialogBaseUnits(); rect = Rectangle.FromLTRB(20 * baseUnits.Width, 3 * baseUnits.Height, rect.Right, rect.Bottom); // Create listbox and static text windows. hwndList = Windows.CreateWindow( className: "listbox", style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)ListBoxStyles.Standard, bounds: new Rectangle(baseUnits.Width, baseUnits.Height * 3, baseUnits.Width * 13 + Windows.GetSystemMetrics(SystemMetric.VerticalScrollWidth), baseUnits.Height * 10), parentWindow: window, menuHandle: (MenuHandle)ID_LIST, instance: ModuleInstance); hwndText = Windows.CreateWindow( className: "static", windowName: Storage.GetCurrentDirectory(), style: WindowStyles.Child | WindowStyles.Visible | (WindowStyles)StaticStyles.Left, bounds: new Rectangle(baseUnits.Width, baseUnits.Height, baseUnits.Width * 260, baseUnits.Height), parentWindow: window, menuHandle: (MenuHandle)ID_TEXT, instance: ModuleInstance); _existingListBoxWndProc = hwndList.SetWindowProcedure(_listBoxProcedure = ListBoxProcedure); fixed(char *f = filter) hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f); return(0); case MessageType.Size: rect = Rectangle.FromLTRB(rect.Left, rect.Top, lParam.LowWord, lParam.HighWord); return(0); case MessageType.SetFocus: hwndList.SetFocus(); return(0); case MessageType.Command: if (wParam.LowWord == ID_LIST && (wParam.HighWord == (ushort)ListBoxNotification.DoubleClick)) { uint i = hwndList.SendMessage(ListBoxMessage.GetCurrentSelection, 0, 0); if (i == WindowDefines.LB_ERR) { break; } int iLength = hwndList.SendMessage(ListBoxMessage.GetTextLength, i, 0) + 1; fixed(char *textBuffer = szFile) { int result = hwndList.SendMessage(ListBoxMessage.GetText, i, textBuffer); SafeFileHandle hFile = null; try { using (hFile = Storage.CreateFile(szFile.AsSpan(0, result), CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read)) { if (!hFile.IsInvalid) { bValidFile = true; hwndText.SetWindowText(Storage.GetCurrentDirectory()); } } hFile = null; } catch { } Span <char> dir = stackalloc char[2]; if (hFile == null && szFile[0] == ('[')) { bValidFile = false; // If setting the directory doesn’t work, maybe it’s a drive change, so try that. try { szFile[result - 1] = '\0'; Storage.SetCurrentDirectory(szFile.AsSpan(1, result - 2)); } catch { dir[0] = szFile[2]; dir[1] = ':'; try { Storage.SetCurrentDirectory(dir); } catch { } } // Get the new directory name and fill the list box. hwndText.SetWindowText(Storage.GetCurrentDirectory()); hwndList.SendMessage(ListBoxMessage.ResetContent, 0, 0); fixed(char *f = filter) hwndList.SendMessage(ListBoxMessage.Directory, (uint)DIRATTR, f); } } window.Invalidate(); } return(0); case MessageType.Paint: if (!bValidFile) { break; } uint bytesRead; using (var hFile = Storage.CreateFile(szFile, CreationDisposition.OpenExisting, DesiredAccess.GenericRead, ShareModes.Read)) { if (hFile.IsInvalid) { bValidFile = false; break; } bytesRead = Storage.ReadFile(hFile, _buffer); } using (DeviceContext dc = window.BeginPaint()) { dc.SelectObject(StockFont.SystemFixed); dc.SetTextColor(SystemColor.ButtonText); dc.SetBackgroundColor(SystemColor.ButtonFace); Encoding.UTF8.GetDecoder().Convert(_buffer.AsSpan(0, (int)bytesRead), _decoded.AsSpan(), true, out _, out int charCount, out _); dc.DrawText(_decoded.AsSpan(0, charCount), rect, DTFLAGS); } return(0); } return(base.WindowProcedure(window, message, wParam, lParam)); }
/// <summary> /// Create raw keyevent arguments. /// </summary> /// <param name="VKCode"></param> /// <param name="isSysKey"></param> /// <param name="Character">Character</param> public RawKeyEventArgs(int VKCode, string Character, DateTime DateTime, uint ProcessID, string ProcessName, WindowHandle WindowHandle, string WindowTitle) { this.VKCode = VKCode; this.Character = Character; this.Key = System.Windows.Input.KeyInterop.KeyFromVirtualKey(VKCode); this.DateTime = DateTime; this.ProcessID = ProcessID; this.ProcessName = ProcessName; this.WindowHandle = WindowHandle; this.WindowTitle = WindowTitle; }
static LRESULT WindowProcedure(WindowHandle window, WindowMessage message, WPARAM wParam, LPARAM lParam) { switch (message) { case WindowMessage.Create: using (DeviceContext dc = window.GetDeviceContext()) { dc.GetTextMetrics(out TEXTMETRIC tm); cxChar = tm.tmAveCharWidth; cxCaps = ((tm.tmPitchAndFamily.PitchTypes & FontPitchTypes.VariablePitch) != 0 ? 3 : 2) * cxChar / 2; cyChar = tm.tmHeight + tm.tmExternalLeading; } window.SetScrollRange(ScrollBar.Vertical, 0, SysMets.sysmetrics.Count - 1, false); window.SetScrollPosition(ScrollBar.Vertical, iVscrollPos, true); return(0); case WindowMessage.Size: cyClient = lParam.HighWord; return(0); case WindowMessage.VerticalScroll: switch ((ScrollCommand)wParam.LowWord) { case ScrollCommand.LineUp: iVscrollPos -= 1; break; case ScrollCommand.LineDown: iVscrollPos += 1; break; case ScrollCommand.PageUp: iVscrollPos -= cyClient / cyChar; break; case ScrollCommand.PageDown: iVscrollPos += cyClient / cyChar; break; case ScrollCommand.ThumbPosition: iVscrollPos = wParam.HighWord; break; } iVscrollPos = Math.Max(0, Math.Min(iVscrollPos, SysMets.sysmetrics.Count - 1)); if (iVscrollPos != window.GetScrollPosition(ScrollBar.Vertical)) { window.SetScrollPosition(ScrollBar.Vertical, iVscrollPos, true); window.Invalidate(true); } return(0); case WindowMessage.Paint: using (DeviceContext dc = window.BeginPaint()) { int i = 0; foreach (SystemMetric metric in SysMets.sysmetrics.Keys) { int y = cyChar * (i - iVscrollPos); dc.TextOut(0, y, metric.ToString()); dc.TextOut(22 * cxCaps, y, SysMets.sysmetrics[metric]); dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Right, TextAlignment.Vertical.Top)); dc.TextOut(22 * cxCaps + 40 * cxChar, y, Windows.GetSystemMetrics(metric).ToString()); dc.SetTextAlignment(new TextAlignment(TextAlignment.Horizontal.Left, TextAlignment.Vertical.Top)); i++; } } return(0); case WindowMessage.Destroy: Windows.PostQuitMessage(0); return(0); } return(Windows.DefaultWindowProcedure(window, message, wParam, lParam)); }
/// <summary> /// Evalutes the points for a window handle. /// </summary> /// <param name="handle">Handle to the window.</param> /// <returns> /// Number of points. Higher points identify better suited windows. /// Windows with negative points are discarded altogether. /// </returns> protected abstract int EvaluatePoints(WindowHandle handle);
private void menuProcess_Popup(object sender, EventArgs e) { virtualizationToolStripMenuItem.Checked = false; // Menu item fixup... if (treeProcesses.SelectedTreeNodes.Count == 0) { // If nothing is selected, disable everything. // The Select All menu item will be enabled later if // we have at least one process in the tree. //contextMenuStripProcess.DisableAll(); } else if (treeProcesses.SelectedTreeNodes.Count == 1) { // All actions should work with one process selected. //contextMenuStripProcess.EnableAll(); // Singular nouns. //priorityMenuItem.Text = "&Priority"; //terminateToolStripMenuItem.Text = "&Terminate Process"; //suspendToolStripMenuItem.Text = "&Suspend Process"; //resumeToolStripMenuItem.Text = "&Resume Process"; // Clear the priority menu items. realTimeToolStripMenuItem.Checked = false; highToolStripMenuItem.Checked = false; aboveNormalToolStripMenuItem.Checked = false; normalToolStripMenuItem.Checked = false; belowNormalToolStripMenuItem.Checked = false; idleToolStripMenuItem.Checked = false; // Clear the I/O priority menu items. iOPriorityToolStripMenuItem.Enabled = true; ioPriority0ThreadMenuItem.Checked = false; ioPriority1ThreadMenuItem.Checked = false; ioPriority3ThreadMenuItem.Checked = false; ioPriority3ThreadMenuItem.Checked = false; try { using (ProcessHandle phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) { try { switch (phandle.PriorityClass) { case ProcessPriorityClass.RealTime: realTimeToolStripMenuItem.Checked = true; break; case ProcessPriorityClass.High: highToolStripMenuItem.Checked = true; break; case ProcessPriorityClass.AboveNormal: aboveNormalToolStripMenuItem.Checked = true; break; case ProcessPriorityClass.Normal: normalToolStripMenuItem.Checked = true; break; case ProcessPriorityClass.BelowNormal: belowNormalToolStripMenuItem.Checked = true; break; case ProcessPriorityClass.Idle: idleToolStripMenuItem.Checked = true; break; } } catch { realTimeToolStripMenuItem.Enabled = false; } try { if (OSVersion.HasIoPriority) { switch (phandle.IoPriority) { case 0: ioPriority0ThreadMenuItem.Checked = true; break; case 1: ioPriority1ThreadMenuItem.Checked = true; break; case 2: ioPriority3ThreadMenuItem.Checked = true; break; case 3: ioPriority3ThreadMenuItem.Checked = true; break; } } } catch { iOPriorityToolStripMenuItem.Enabled = false; } } } catch { priorityToolStripMenuItem.Enabled = false; iOPriorityToolStripMenuItem.Enabled = false; } // Check if we think the process exists. If we don't, disable all menu items // to avoid random exceptions occurring when the user clicks on certain things. if (!Program.ProcessProvider.Dictionary.ContainsKey(processSelectedPid)) { //menuProcess.DisableAll(); } else { // Check the virtualization menu item. try { using (ProcessHandle phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) using (TokenHandle thandle = phandle.GetToken(TokenAccess.Query)) { if (virtualizationToolStripMenuItem.Enabled = thandle.IsVirtualizationAllowed) virtualizationToolStripMenuItem.Checked = thandle.IsVirtualizationEnabled; } } catch { virtualizationToolStripMenuItem.Enabled = false; } // Enable/disable DLL injection based on the process' session ID. This only applies // on XP and above. try { if ( OSVersion.IsBelowOrEqual(WindowsVersion.XP) && Program.ProcessProvider.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId ) injectDLLToolStripMenuItem.Enabled = false; else injectDLLToolStripMenuItem.Enabled = true; } catch (Exception ex) { Logging.Log(ex); } // Disable Terminate Process Tree if the selected process doesn't // have any children. Note that this may also happen if the user // is sorting the list (!). try { if (treeProcesses.SelectedTreeNodes[0].IsLeaf && string.IsNullOrEmpty((treeProcesses.Tree.Model as ProcessTreeModel).GetSortColumn())) terminateProcessTreeToolStripMenuItem.Visible = false; else terminateProcessTreeToolStripMenuItem.Visible = true; } catch (Exception ex) { Logging.Log(ex); } // Find the process' window (if any). windowHandle = WindowHandle.Zero; WindowHandle.Enumerate(handle => { // GetWindowLong // Shell_TrayWnd if (handle.IsWindow && handle.IsVisible && handle.IsParent) { int pid; Win32.GetWindowThreadProcessId(handle, out pid); if (pid == processSelectedPid) { windowHandle = handle; return false; } } return true; }); // Enable the Window submenu if we found window owned // by the process. Otherwise, disable the submenu. if (windowHandle.IsInvalid) { windowToolStripMenuItem1.Enabled = false; } else { windowToolStripMenuItem1.Enabled = true; //windowToolStripMenuItem1.EnableAll(); switch (windowHandle.Placement.ShowState) { case ShowWindowType.ShowMinimized: minimizeToolStripMenuItem.Enabled = false; break; case ShowWindowType.ShowMaximized: maximizeToolStripMenuItem.Enabled = false; break; case ShowWindowType.ShowNormal: restoreToolStripMenuItem.Enabled = false; break; } } } } else { // Assume most process actions will not work with more than one process. //menuProcess.DisableAll(); // Use plural nouns. terminateProcessTreeToolStripMenuItem.Text = "&Terminate Processes"; suspendToolStripMenuItem.Text = "&Suspend Processes"; resumeToolStripMenuItem.Text = "&Resume Processes"; // Enable a specific set of actions. terminateToolStripMenuItem.Enabled = true; suspendToolStripMenuItem.Enabled = true; resumeToolStripMenuItem.Enabled = true; reduceWorkingSetToolStripMenuItem.Enabled = true; copyProcessMenuItem.Enabled = true; } // Special case for invalid PIDs. if (processSelectedPid <= 0 && treeProcesses.SelectedNodes.Count == 1) { //priorityMenuItem.Text = "&Priority"; //menuProcess.DisableAll(); propertiesToolStripMenuItem1.Enabled = true; } // Enable/disable the Select All menu item. if (treeProcesses.Model.Nodes.Count == 0) { selectAllToolStripMenuItem.Enabled = false; } else { selectAllToolStripMenuItem.Enabled = true; } }
/// <summary> /// HookCallbackAsync procedure that calls accordingly the KeyDown or KeyUp events. /// </summary> /// <param name="keyEvent">Keyboard event</param> /// <param name="vkCode">VKCode</param> /// <param name="character">Character as string.</param> void KeyboardListener_KeyboardCallbackAsync(WinAPI.KeyEvent keyEvent, int vkCode, string character, DateTime dateTime, WindowHandle windowHandle, uint processID) { string processName = GetProcessName(processID); StringBuilder windowTitle = new StringBuilder(MaxTitleSize); WinAPI.GetWindowText(windowHandle, windowTitle, MaxTitleSize); var eventArgs = new RawKeyEventArgs(vkCode, character, DateTime.Now, processID, processName, windowHandle, windowTitle.ToString()); if (keyEvent == WinAPI.KeyEvent.WM_KEYDOWN || keyEvent == WinAPI.KeyEvent.WM_SYSKEYDOWN) { KeyDown?.BeginInvoke(this, eventArgs, null, null); } else if (keyEvent == WinAPI.KeyEvent.WM_KEYUP || keyEvent == WinAPI.KeyEvent.WM_SYSKEYUP) { KeyUp?.BeginInvoke(this, eventArgs, null, null); } }
private void menuProcess_Popup(object sender, EventArgs e) { virtualizationProcessMenuItem.Checked = false; // Menu item fixup... if (treeProcesses.SelectedTreeNodes.Count == 0) { // If nothing is selected, disable everything. // The Select All menu item will be enabled later if // we have at least one process in the tree. menuProcess.DisableAll(); } else if (treeProcesses.SelectedTreeNodes.Count == 1) { // All actions should work with one process selected. menuProcess.EnableAll(); // Singular nouns. priorityMenuItem.Text = "&Priority"; terminateMenuItem.Text = "&Terminate Process"; suspendMenuItem.Text = "&Suspend Process"; resumeMenuItem.Text = "&Resume Process"; // Check the appropriate priority level menu item. realTimeMenuItem.Checked = false; highMenuItem.Checked = false; aboveNormalMenuItem.Checked = false; normalMenuItem.Checked = false; belowNormalMenuItem.Checked = false; idleMenuItem.Checked = false; try { using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) { switch (phandle.GetPriorityClass()) { case ProcessPriorityClass.RealTime: realTimeMenuItem.Checked = true; break; case ProcessPriorityClass.High: highMenuItem.Checked = true; break; case ProcessPriorityClass.AboveNormal: aboveNormalMenuItem.Checked = true; break; case ProcessPriorityClass.Normal: normalMenuItem.Checked = true; break; case ProcessPriorityClass.BelowNormal: belowNormalMenuItem.Checked = true; break; case ProcessPriorityClass.Idle: idleMenuItem.Checked = true; break; } } } catch (Exception ex) { priorityMenuItem.Text = "(" + ex.Message + ")"; priorityMenuItem.Enabled = false; } // Check the virtualization menu item. try { using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) { try { using (var thandle = phandle.GetToken(TokenAccess.Query)) { if (virtualizationProcessMenuItem.Enabled = thandle.IsVirtualizationAllowed()) virtualizationProcessMenuItem.Checked = thandle.IsVirtualizationEnabled(); } } catch { } } } catch { virtualizationProcessMenuItem.Enabled = false; } // Enable/disable DLL injection based on the process' session ID. This only applies // on XP and above. try { if ( OSVersion.IsBelowOrEqual(WindowsVersion.XP) && processP.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId ) injectDllProcessMenuItem.Enabled = false; else injectDllProcessMenuItem.Enabled = true; } catch (Exception ex) { Logging.Log(ex); } // Disable Terminate Process Tree if the selected process doesn't // have any children. Note that this may also happen if the user // is sorting the list (!). try { if (treeProcesses.SelectedTreeNodes[0].IsLeaf && (treeProcesses.Tree.Model as ProcessTreeModel).GetSortColumn() == "") terminateProcessTreeMenuItem.Visible = false; else terminateProcessTreeMenuItem.Visible = true; } catch (Exception ex) { Logging.Log(ex); } // Find the process' window (if any). windowHandle = WindowHandle.Zero; WindowHandle.Enumerate( (handle) => { // GetWindowLong // Shell_TrayWnd if (handle.IsWindow() && handle.IsVisible() && handle.IsParent()) { int pid; Win32.GetWindowThreadProcessId(handle, out pid); if (pid == processSelectedPid) { windowHandle = handle; return false; } } return true; }); // Enable the Window submenu if we found window owned // by the process. Otherwise, disable the submenu. if (windowHandle.IsInvalid) { windowProcessMenuItem.Enabled = false; } else { windowProcessMenuItem.Enabled = true; windowProcessMenuItem.EnableAll(); switch (windowHandle.GetPlacement().ShowState) { case ShowWindowType.ShowMinimized: minimizeProcessMenuItem.Enabled = false; break; case ShowWindowType.ShowMaximized: maximizeProcessMenuItem.Enabled = false; break; case ShowWindowType.ShowNormal: restoreProcessMenuItem.Enabled = false; break; } } } else { // Assume most process actions will not work with more than one process. menuProcess.DisableAll(); // Use plural nouns. terminateMenuItem.Text = "&Terminate Processes"; suspendMenuItem.Text = "&Suspend Processes"; resumeMenuItem.Text = "&Resume Processes"; // Enable a specific set of actions. terminateMenuItem.Enabled = true; suspendMenuItem.Enabled = true; resumeMenuItem.Enabled = true; reduceWorkingSetProcessMenuItem.Enabled = true; copyProcessMenuItem.Enabled = true; } // Special case for invalid PIDs. if (processSelectedPid <= 0 && treeProcesses.SelectedNodes.Count == 1) { priorityMenuItem.Text = "&Priority"; menuProcess.DisableAll(); propertiesProcessMenuItem.Enabled = true; } // Enable/disable the Select All menu item. if (treeProcesses.Model.Nodes.Count == 0) { selectAllProcessMenuItem.Enabled = false; } else { selectAllProcessMenuItem.Enabled = true; } }
private void menuProcess_Popup(object sender, EventArgs e) { virtualizationProcessMenuItem.Checked = false; if (treeProcesses.SelectedTreeNodes.Count == 0) { menuProcess.DisableAll(); } else if (treeProcesses.SelectedTreeNodes.Count == 1) { menuProcess.EnableAll(); priorityMenuItem.Text = "&Priority"; terminateMenuItem.Text = "&Terminate Process"; suspendMenuItem.Text = "&Suspend Process"; resumeMenuItem.Text = "&Resume Process"; realTimeMenuItem.Checked = false; highMenuItem.Checked = false; aboveNormalMenuItem.Checked = false; normalMenuItem.Checked = false; belowNormalMenuItem.Checked = false; idleMenuItem.Checked = false; try { using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) { switch (phandle.GetPriorityClass()) { case ProcessPriorityClass.RealTime: realTimeMenuItem.Checked = true; break; case ProcessPriorityClass.High: highMenuItem.Checked = true; break; case ProcessPriorityClass.AboveNormal: aboveNormalMenuItem.Checked = true; break; case ProcessPriorityClass.Normal: normalMenuItem.Checked = true; break; case ProcessPriorityClass.BelowNormal: belowNormalMenuItem.Checked = true; break; case ProcessPriorityClass.Idle: idleMenuItem.Checked = true; break; } } } catch (Exception ex) { priorityMenuItem.Text = "(" + ex.Message + ")"; priorityMenuItem.Enabled = false; } try { using (var phandle = new ProcessHandle(processSelectedPid, Program.MinProcessQueryRights)) { try { using (var thandle = phandle.GetToken(TokenAccess.Query)) { if (virtualizationProcessMenuItem.Enabled = thandle.IsVirtualizationAllowed()) virtualizationProcessMenuItem.Checked = thandle.IsVirtualizationEnabled(); } } catch { } } } catch { virtualizationProcessMenuItem.Enabled = false; } try { if ( OSVersion.IsBelowOrEqual(WindowsVersion.XP) && processP.Dictionary[processSelectedPid].SessionId != Program.CurrentSessionId ) injectDllProcessMenuItem.Enabled = false; else injectDllProcessMenuItem.Enabled = true; } catch (Exception ex) { Logging.Log(ex); } try { if (treeProcesses.SelectedTreeNodes[0].IsLeaf && (treeProcesses.Tree.Model as ProcessTreeModel).GetSortColumn() == "") terminateProcessTreeMenuItem.Visible = false; else terminateProcessTreeMenuItem.Visible = true; } catch (Exception ex) { Logging.Log(ex); } windowHandle = WindowHandle.Zero; WindowHandle.Enumerate( (handle) => { if (handle.IsWindow() && handle.IsVisible() && handle.IsParent()) { int pid; Win32.GetWindowThreadProcessId(handle, out pid); if (pid == processSelectedPid) { windowHandle = handle; return false; } } return true; }); if (windowHandle.IsInvalid) { windowProcessMenuItem.Enabled = false; } else { windowProcessMenuItem.Enabled = true; windowProcessMenuItem.EnableAll(); switch (windowHandle.GetPlacement().ShowState) { case ShowWindowType.ShowMinimized: minimizeProcessMenuItem.Enabled = false; break; case ShowWindowType.ShowMaximized: maximizeProcessMenuItem.Enabled = false; break; case ShowWindowType.ShowNormal: restoreProcessMenuItem.Enabled = false; break; } } } else { menuProcess.DisableAll(); terminateMenuItem.Text = "&Terminate Processes"; suspendMenuItem.Text = "&Suspend Processes"; resumeMenuItem.Text = "&Resume Processes"; terminateMenuItem.Enabled = true; suspendMenuItem.Enabled = true; resumeMenuItem.Enabled = true; reduceWorkingSetProcessMenuItem.Enabled = true; copyProcessMenuItem.Enabled = true; } if (processSelectedPid <= 0 && treeProcesses.SelectedNodes.Count == 1) { priorityMenuItem.Text = "&Priority"; menuProcess.DisableAll(); propertiesProcessMenuItem.Enabled = true; } if (treeProcesses.Model.Nodes.Count == 0) { selectAllProcessMenuItem.Enabled = false; } else { selectAllProcessMenuItem.Enabled = true; } }
/// <summary>Adds a new handle</summary> public void Handle(Window w, string name, bool includeScaling = false) { var handle = Handles.FirstOrDefault(x => x.Name == name); if (handle != null) { handle.ApplyWindow(w); if (w.IsLoaded == false) { var fittingRectangle = GetFittingRectangle(handle.Left, handle.Top, handle.Width, handle.Height); w.WindowStartupLocation = WindowStartupLocation.Manual; w.Width = fittingRectangle.Width; w.Height = fittingRectangle.Height; w.Left = fittingRectangle.Left; w.Top = fittingRectangle.Top; w.Topmost = handle.Topmost; if (w is CsWindow && includeScaling) ((CsWindow) w).Scale = handle.Scale; } } else { handle = new WindowHandle(w, name); Handles.Add(handle); } }
/// <summary> /// Inspects a window and return whether inspection should continue. /// </summary> /// <param name="handle">Handle of the window.</param> /// <returns>True if inspection should continue. False stops current refresh operation.</returns> protected abstract bool InspectWindow(WindowHandle handle);
internal static Result Startup() { if (core is null) { // Load RhinoCore try { core = new RhinoCore ( new string[] { "/nosplash", "/notemplate", "/captureprintcalls", "/stopwatch", $"/scheme={SchemeName}", $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}" }, WindowStyle.Hidden ); } catch { Addin.CurrentStatus = Addin.Status.Failed; return(Result.Failed); } finally { StartupLog = RhinoApp.CapturedCommandWindowStrings(true); RhinoApp.CommandWindowCaptureEnabled = false; } MainWindow = new WindowHandle(RhinoApp.MainWindowHandle()); External.ActivationGate.AddGateWindow(MainWindow.Handle); RhinoApp.MainLoop += MainLoop; RhinoDoc.NewDocument += OnNewDocument; RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate; Command.BeginCommand += BeginCommand; Command.EndCommand += EndCommand; // Alternative to /runscript= Rhino command line option RunScriptAsync ( script: Environment.GetEnvironmentVariable("RhinoInside_RunScript"), activate: Addin.StartupMode == AddinStartupMode.AtStartup ); // Reset document units UpdateDocumentUnits(RhinoDoc.ActiveDoc); UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument); Type[] types = default; try { types = Assembly.GetCallingAssembly().GetTypes(); } catch (ReflectionTypeLoadException ex) { types = ex.Types?.Where(x => x is object).ToArray(); } // Look for Guests guests = types. Where(x => typeof(IGuest).IsAssignableFrom(x)). Where(x => !x.IsInterface). Select(x => new GuestInfo(x)). ToList(); CheckInGuests(); } return(Result.Succeeded); }