private string GetTitle() { StringBuilder builder = new StringBuilder(200); WindowInterop.GetWindowText(Hwnd, builder, builder.Capacity); return(builder.ToString()); }
void WindowManager_WindowListChanged(object sender, EventArgs e) { List <IntPtr> hwnds = new List <IntPtr>(); WindowInterop.EnumWindows((h, p) => { if (isTaskBarWindow(h)) { hwnds.Add(h); } return(true); }, 0); List <IntPtr> chwnds = (from w in Windows select w.Hwnd).ToList(); foreach (var h in hwnds.Except(chwnds)) // Get removed windows { Window window = new Window(h); Windows.Add(window); if (WindowAdded != null) { WindowAdded(this, new WindowEventArgs(window)); } } foreach (var h in chwnds.Except(hwnds)) // Get added windows { Window window = Windows.Find(w => w.Hwnd == h); if (WindowRemoved != null) { WindowRemoved(this, new WindowEventArgs(window)); } Windows.Remove(window); } }
private void WindowLoadedAction(Window _window) { Window = _window; var handle = new WindowInteropHelper(Window).Handle; WindowManager.Manager.SetDockHwnd(handle); WindowManager.Manager.Start(); ThemeManager.Manager.ThemeWindow(); if (VMLocator.Main.RemoveTaskbar) { TaskbarManager.SetTaskbarVisibility(false); } SetWorkingArea(VMLocator.Main.ReserveScreenSpace); // Subscribe to window events. Application.Current.Exit += Current_Exit; WindowManager.Manager.ActiveWindowChanged += Manager_ActiveWindowChanged; SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; // Add a hook to receive window events from Windows. HwndSource source = PresentationSource.FromVisual(Window) as HwndSource; source.AddHook(WndProc); // These two lines are necessary to capture the window events in the above hook. WindowInterop.RegisterShellHookWindow(handle); WindowInterop.RegisterWindowMessage("SHELLHOOK"); SetWindowPosition(); // Show the widgets window ShowWidgets(); }
public void Restore() { WindowInterop.SetForegroundWindow(Hwnd); if (IsMinimized()) { WindowInterop.ShowWindow(Hwnd, WindowInterop.ShowStyle.Restore); } }
public void SetTopmost() { Application.Current.Dispatcher.Invoke(() => { var hwnd = new WindowInteropHelper(this).Handle; WindowInterop.SetWindowPos(hwnd, WindowInterop.HWND_TOPMOST, 0, 0, 0, 0, WindowInterop.SWP_NOMOVE | WindowInterop.SWP_NOSIZE); }); }
protected override void OnResize(EventArgs e) { if (this.Client != null) { WindowInterop.MoveWindow(this.Client.MainWindowHandle, 0, 0, this.Width, this.Height, true); } base.OnResize(e); }
public void SetTopmost() { Application.Current.Dispatcher.Invoke(() => { // Uses interop to place the window at topmost position. var hwnd = new WindowInteropHelper(this).Handle; WindowInterop.SetWindowPos(hwnd, WindowInterop.HWND_BOTTOM, 0, 0, 0, 0, WindowInterop.SWP_NOMOVE | WindowInterop.SWP_NOSIZE); }); }
protected override async Task OnAfterRenderAsync(bool firstRender) { /*string title = BlogOptions.Name; * if (!string.IsNullOrEmpty(Title)) * title = $"{Title} - {BlogOptions.Name}"; * await WindowInterop.SetTitle(JSRuntime, title);*/ if (!string.IsNullOrEmpty(LocalAnchorJump)) { await WindowInterop.ScrollTo(JSRuntime, LocalAnchorJump); LocalAnchorJump = null; } }
private bool isTaskBarWindow(IntPtr hwnd) { //long style = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_STYLE); // Get style. if ( //HasFlag(style, TARGETWINDOW) && WindowInterop.IsWindowVisible(hwnd)) // && //WindowInvoke.GetParent(hwnd) == IntPtr.Zero) { bool noOwner = WindowInterop.GetWindow(hwnd, WindowInterop.GW_OWNER) == IntPtr.Zero; long exStyle = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_EXSTYLE); // Get extended style. return(noOwner && (exStyle & WS_EX_TOOLWINDOW) == 0); } return(false); }
public void Start() { Stop(); checkWindowsThread = new Thread(() => { while (true) { // Check windows list int windowCount = 0; WindowInterop.EnumWindows((h, p) => { if (isTaskBarWindow(h)) { windowCount++; } return(true); }, 0); if (windowCount != Windows.Count && WindowListChanged != null) { WindowListChanged(this, new EventArgs()); } // Check active window IntPtr activeWindow = WindowInterop.GetForegroundWindow(); if (ActiveWindow != activeWindow && ActiveWindowChanged != null && activeWindow != dockHwnd) { ActiveWindowChanged(activeWindow, new EventArgs()); } // Check active window location if (activeWindow != IntPtr.Zero && activeWindow != dockHwnd) { WindowInterop.Rect windowRect = new WindowInterop.Rect(); WindowInterop.GetWindowRect(activeWindow, ref windowRect); if (windowRect != ActiveWindowRect && ActiveWindowRectChanged != null) { ActiveWindowRectChanged(this, new WindowRectEventArgs(ActiveWindowRect = windowRect)); } } // Check current cursor position WindowInterop.Point cPos; WindowInterop.GetCursorPos(out cPos); if (CursorPosition != cPos && CursorPositionChanged != null) { CursorPositionChanged(this, new CursorPosEventArgs(CursorPosition = cPos)); } Thread.Sleep(40); // ~25ips } }); checkWindowsThread.Start(); }
public static void SetTaskbarVisibility(bool visible) { var taskBarHwnd = WindowInterop.FindWindow("Shell_TrayWnd", ""); var startHwnd = WindowInterop.FindWindowEx(taskBarHwnd, IntPtr.Zero, "Button", "Start"); if (startHwnd == IntPtr.Zero) { // Tente de trouver le bouton démarrer de Vista/Win7/Win8 startHwnd = GetVistaStartMenuHwnd(taskBarHwnd); } var showStyle = visible ? WindowInterop.ShowStyle.Show : WindowInterop.ShowStyle.Hide; WindowInterop.ShowWindow(taskBarHwnd, showStyle); WindowInterop.ShowWindow(startHwnd, showStyle); }
private static bool EnumThreadWindowsCallback(IntPtr Hwnd, IntPtr lParam) { StringBuilder buffer = new StringBuilder(256); var possibleTitles = new string[] { "Start", "Démarrer" }; if (WindowInterop.GetWindowText(Hwnd, buffer, buffer.Capacity) > 0) { if (possibleTitles.Contains(buffer.ToString())) { vistaStartMenuWnd = Hwnd; return(false); } } return(true); }
private bool isTaskBarWindow(IntPtr hwnd) { //long style = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_STYLE); // Get style. if (/*HasFlag(style, TARGETWINDOW) &&*/ WindowInterop.IsWindowVisible(hwnd) /*&& * WindowInterop.GetParent(hwnd) == IntPtr.Zero*/) { var window = new Win32Window(hwnd); bool noOwner = WindowInterop.GetWindow(hwnd, WindowInterop.GW_OWNER) == IntPtr.Zero; long exStyle = WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_EXSTYLE); // Get extended style. bool isWin10App = window.ClassName == "ApplicationFrameWindow"; return(noOwner && (exStyle & WS_EX_TOOLWINDOW) == 0 && !isWin10App); } return(false); }
private static IntPtr GetVistaStartMenuHwnd(IntPtr taskBarHwnd) { int procId; WindowInterop.GetWindowThreadProcessId(taskBarHwnd, out procId); Process p = Process.GetProcessById(procId); if (p != null) { foreach (ProcessThread t in p.Threads) { WindowInterop.EnumThreadWindows(t.Id, EnumThreadWindowsCallback, IntPtr.Zero); } } return(vistaStartMenuWnd); }
public Window(IntPtr _hwnd) { Hwnd = _hwnd; Title = GetTitle(); titleThread = new Thread(() => { string title = GetTitle(); if (Title != title) { if (TitleChanged != null) { TitleChanged(this, new EventArgs()); } Title = title; } }); titleThread.Start(); WindowInterop.GetWindowThreadProcessId(Hwnd, out ProcId); FileName = ProcessManager.GetExecutablePath(ProcId); }
public async Task <TokenInfo> GetTokenAsync(IKeyValueSettings settings, object platformParameters) { if (null == settings) { throw new ArgumentNullException(nameof(settings)); } var token = await GetToken(); if (null != token) { return(token); } var authority = settings.Values.ContainsKey(TokenKeys.AuthorityKey) ? settings.Values[TokenKeys.AuthorityKey] : throw new ArgumentNullException(TokenKeys.AuthorityKey); var redirectUrl = settings.Values.ContainsKey(TokenKeys.RedirectUrl) ? settings.Values[TokenKeys.RedirectUrl] : throw new ArgumentNullException(TokenKeys.RedirectUrl); await WindowInterop.OpenWindowAsync(_jsRuntime, _localStorage, UriHelper.Encode(new Uri($"{authority}?redirectUrl={redirectUrl}"))); return(await GetToken() ?? throw new Exception("No token found!")); }
public void Close() { WindowInterop.SendMessage(Hwnd, WindowInterop.WM_CLOSE, 0, 0); }
private long getHwndStyleFlags(IntPtr hwnd) { return(WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_STYLE)); }
public static void SetWindowExTransparent(IntPtr hwnd) { var extendedStyle = (int)WindowInterop.GetWindowLongPtr(hwnd, WindowInterop.GWL_EXSTYLE); WindowInterop.SetWindowLongPtr(hwnd, WindowInterop.GWL_EXSTYLE, extendedStyle | WindowInterop.WS_EX_TRANSPARENT); }
public bool IsMinimized() { return(WindowInterop.IsIconic(Hwnd)); }
public IntPtr GetOwnerHwnd() { return(WindowInterop.GetWindow(Hwnd, WindowInterop.GW_OWNER)); }
public void Minimize() { WindowInterop.ShowWindow(Hwnd, WindowInterop.ShowStyle.Minimize); }
public IntPtr GetParentHwnd() { return(WindowInterop.GetParent(Hwnd)); }
public void Start() { Stop(); checkWorkingAreaThread = new Thread(() => { SystemInterop.RECT rect = WorkAreaManager.GetWorkingArea(); while (true) { var newRect = WorkAreaManager.GetWorkingArea(); if (rect.Bottom != newRect.Bottom || rect.Top != newRect.Top || rect.Left != newRect.Left || rect.Right != newRect.Right) { if (WorkingAreaChanged != null) { WorkingAreaChanged(this, new EventArgs()); } rect = newRect; } Thread.Sleep(100); // ~10ips } }); checkWorkingAreaThread.Start(); checkWindowsThread = new Thread(() => { while (true) { // Check windows list int windowCount = 0; WindowInterop.EnumWindows((h, p) => { if (isTaskBarWindow(h)) { windowCount++; } return(true); }, 0); if (windowCount != Windows.Count && WindowListChanged != null) { WindowListChanged(this, new EventArgs()); } // Check active window IntPtr activeHwnd = WindowInterop.GetForegroundWindow(); var activeWindow = new Win32Window(activeHwnd); var isDock = activeWindow.FileName == Process.GetCurrentProcess().MainModule.FileName; if (ActiveWindow != activeHwnd && ActiveWindowChanged != null && !isDock) { ActiveWindowChanged(activeHwnd, new EventArgs()); } // Check active window location if (activeHwnd != IntPtr.Zero && !isDock) { WindowInterop.Rect windowRect = new WindowInterop.Rect(); WindowInterop.GetWindowRect(activeHwnd, ref windowRect); if (windowRect != ActiveWindowRect && ActiveWindowRectChanged != null) { ActiveWindowRectChanged(this, new WindowRectEventArgs(ActiveWindowRect = windowRect)); } } Thread.Sleep(50); // ~20ips } }); checkWindowsThread.Start(); }