public void Exit() { this.OnExiting?.Invoke(this, EventArgs.Empty); this.TrayIcon.Visible = false; WindowsFunctions.UnregisterHotKey(this.Handle, 0); this._bufermanApplication = null; Application.Exit(); }
public int ShowWindow(int windowHandle) { Console.WriteLine(windowHandle); var isSuccessful = WindowsFunctions.ShowWindow( new IntPtr(windowHandle), WindowsFunctions.ShowWindowCommand.SW_RESTORE ); return(!isSuccessful?Marshal.GetLastWin32Error() : 0); }
private void addEntity(object sender, MouseButtonEventArgs e) { try { var wnd = new WndMaterialEdit(new Material()); wnd.EditFinished += (sender2, e2) => RefreshData(); wnd.Owner = this; WindowsFunctions.ShowSecondary(wnd); } catch (System.Exception ex) { MessageBox.Show(WindowsMessages.messageForAdmin); MessageBox.Show(ex.Message + "/n" + ex.StackTrace); } }
private void registerEvents() { this.Loaded += load; lsbEntities.SelectionChanged += getEntityData; txtbEdit.PreviewMouseDown += editEntity; txtSearch.KeyUp += filterEntitiesByName; cmbSearch.SelectionChanged += filterEntitiesByCity; imgExit.PreviewMouseDown += (sender, e) => WindowsFunctions.Exit(this); imgAdd.PreviewMouseDown += addEntity; txtbShowData.PreviewMouseDown += (sender, e) => showStackPanel(stkData); txtbShowNotes.PreviewMouseDown += (sender, e) => showStackPanel(stkNotes); txtSearch.GotFocus += clear; }
public int StopWindowAlwaysOnTop(int windowHandle) { Console.WriteLine(windowHandle); var isSuccessful = WindowsFunctions.SetWindowPos( new IntPtr(windowHandle), (IntPtr)WindowsFunctions.SpecialWindowHandles.HWND_TOP, 0, 0, 0, 0, WindowsFunctions.SetWindowPosFlags.SWP_NOMOVE | WindowsFunctions.SetWindowPosFlags.SWP_NOSIZE ); return(!isSuccessful?Marshal.GetLastWin32Error() : 0); }
public bool HandleMoveWindow(MoveWindowRequestBody body) { Console.WriteLine(body.WindowHandle); Console.WriteLine(body.X); Console.WriteLine(body.Y); Console.WriteLine(body.Width); Console.WriteLine(body.Height); return(WindowsFunctions.MoveWindow( new IntPtr(body.WindowHandle), body.X, body.Y, body.Width, body.Height, false)); }
private void editEntity(object sender, MouseButtonEventArgs e) { try { if (lsbEntities.SelectedItem != null) { var wnd = new WndCustomerEdit((Customer)lsbEntities.SelectedItem); wnd.EditFinished += (sender2, e2) => RefreshData(); wnd.Owner = this; WindowsFunctions.Show(wnd); } } catch (System.Exception ex) { MessageBox.Show(WindowsMessages.messageForAdmin); MessageBox.Show(ex.Message + "/n" + ex.StackTrace); } }
private void saveEntity(object sender, MouseButtonEventArgs e) { try { using (var uow = Builders.UnitOfWorkBuilder.GetUnitOfWork()) { uow.BindingRepository.Save(entity); uow.Complete(); } EditFinished(this, EventArgs.Empty); MessageBox.Show(WindowsMessages.messageForSaveInsert); WindowsFunctions.Exit(this); } catch (System.Exception ex) { MessageBox.Show(WindowsMessages.messageForAdmin); MessageBox.Show(ex.Message + "/n" + ex.StackTrace); } }
private void OnHookEvent(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { var windowTitle = WindowsFunctions.GetWindowTitle(hwnd); if (string.IsNullOrEmpty(windowTitle)) { return; } var processName = WindowsFunctions.GetProcessName(hwnd); if (string.IsNullOrEmpty(processName)) { return; } Fire(new AppTitleChanged(processName, windowTitle)); }
public ActionResult <IEnumerable <WindowInfo> > GetWindowInfos() { var windowInfos = new List <WindowInfo>(); WindowsFunctions.EnumWindows(((windowHandle, param) => { if (!IsAltTabWindow(windowHandle)) { return(true); } var stringBuilder = new StringBuilder(1024); WindowsFunctions.GetWindowText(windowHandle, stringBuilder, stringBuilder.MaxCapacity); if (stringBuilder.Length == 0) { return(true); } WindowsFunctions.GetWindowThreadProcessId(windowHandle, out var processId); var process = Process.GetProcessById((int)processId); try { windowInfos.Add(new WindowInfo { WindowHandle = windowHandle.ToInt32(), WindowTitle = stringBuilder.ToString(), ProcessFileLocation = process.MainModule?.FileName, }); } catch { Console.WriteLine($"Cannot get window info - processId: {processId}, windowHandle: {windowHandle}"); } return(true); }), IntPtr.Zero); return(windowInfos); }
public static Bitmap GetScreenShot(IntPtr windowHandle) { WindowsFunctions.GetWindowRect(new HandleRef(null, windowHandle), out var rc); var bmp = new Bitmap(rc.Right - rc.Left, rc.Bottom - rc.Top, PixelFormat.Format32bppArgb); var gfxBmp = Graphics.FromImage(bmp); IntPtr hdcBitmap; try { hdcBitmap = gfxBmp.GetHdc(); } catch { return(null); } var succeeded = WindowsFunctions.PrintWindow(windowHandle, hdcBitmap, 0x02); /// flag for hardware acceleration window. gfxBmp.ReleaseHdc(hdcBitmap); if (!succeeded) { gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(Point.Empty, bmp.Size)); } var hRgn = WindowsFunctions.CreateRectRgn(0, 0, 0, 0); WindowsFunctions.GetWindowRgn(windowHandle, hRgn); var region = Region.FromHrgn(hRgn); //err here once if (!region.IsEmpty(gfxBmp)) { gfxBmp.ExcludeClip(region); gfxBmp.Clear(Color.Transparent); } gfxBmp.Dispose(); return(bmp); }
protected override void WndProc(ref Message m) { if (m.Msg == Messages.WM_CREATE) { this._clipboardViewer = new ClipboardViewer(this.Handle); this._clipboardViewer.ClipboardUpdated += (object sender, EventArgs e) => { this.ClipbordUpdated?.Invoke(this, EventArgs.Empty); }; WindowsFunctions.RegisterHotKey(this.Handle, 0, 1, (int)Keys.C); this._StartTrickTimer(23); } else if (this._clipboardViewer != null) { this._clipboardViewer.HandleWindowsMessage(m.Msg, m.WParam, m.LParam); } if (m.Msg == Messages.WM_HOTKEY) { Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF); var modifier = (ModifierKeys)((int)m.LParam & 0xFFFF); if (key == Keys.C && modifier == System.Windows.Input.ModifierKeys.Alt) { this.Activate(); } } if (m.Msg == Messages.WM_QUERYENDSESSION) { this.Exit(); } base.WndProc(ref m); }
static void Main(string[] args) { var funcs = new WindowsFunctions(); funcs.SetWallpaper("cage.jpg"); }
private void registerEvents() { this.Loaded += load; imgAdd.PreviewMouseDown += addEntity; imgExit.PreviewMouseDown += (sender, e) => WindowsFunctions.Exit(this); }
internal static bool IsAltTabWindow(IntPtr windowHandle) { if (!WindowsFunctions.IsWindowVisible(windowHandle)) { return(false); } const int GA_ROOTOWNER = 3; var hwndTry = WindowsFunctions.GetAncestor(windowHandle, GA_ROOTOWNER); var hwndWalk = IntPtr.Zero; while (hwndTry != hwndWalk) { hwndWalk = hwndTry; hwndTry = WindowsFunctions.GetLastActivePopup(hwndWalk); if (WindowsFunctions.IsWindowVisible(hwndTry)) { break; } } if (hwndWalk != windowHandle) { return(false); } // the following removes some task tray programs and "Program Manager" var titleBarInfo = new WindowsFunctions.TITLEBARINFO(); titleBarInfo.cbSize = Marshal.SizeOf(titleBarInfo); WindowsFunctions.GetTitleBarInfo(windowHandle, ref titleBarInfo); const int STATE_SYSTEM_INVISIBLE = 0x00008000; if ((titleBarInfo.rgstate[0] & STATE_SYSTEM_INVISIBLE) != 0) { return(false); } // Tool windows should not be displayed either, these do not appear in the // task bar. const int GWL_EXSTYLE = -20; const long WS_EX_TOOLWINDOW = 0x00000080L; if ((WindowsFunctions.GetWindowLong(windowHandle, GWL_EXSTYLE) & WS_EX_TOOLWINDOW) != 0) { return(false); } WindowsFunctions.DwmGetWindowAttribute(windowHandle, WindowsFunctions.DWMWINDOWATTRIBUTE.Cloaked, out var isCloaked, Marshal.SizeOf(typeof(bool))); if (isCloaked) { return(false); } return(true); }
private void registerEvents() { this.Loaded += loaded; brdDelete.PreviewMouseDown += deactivate; imgExit.PreviewMouseDown += (sender, e) => WindowsFunctions.Exit(this); }