/** * <summary> * WindowInfowWithHandleをカレントウィンドウにする * </summary> */ public void SetCurrentWindowIndexByWindowInfo(WindowInfoWithHandle windowInfoWithHandle) { var index = this.windowInfos.FindIndex( (WindowInfoWithHandle needleWindowInfo) => { return(windowInfoWithHandle.Equals(needleWindowInfo)); }); this.SetCurrentWindowIndex(index); }
public static int PushNewWindowInfo(WindowTilingType windowTilingType, List <WindowInfoWithHandle> windowInfos, WindowInfoWithHandle windowInfoWithHandle) { var windowTiler = WindowTiler.CreateWindowTilerInstance(windowTilingType); return(windowTiler.PushNewWindowInfo(windowInfos, windowInfoWithHandle)); }
/** * <summary> * 新規ウィンドウを WindowTilingType に基づいて先頭に追加する * </summary> */ public void PushNew(WindowInfoWithHandle windowInfo) { lock (this.windowInfosLock) { int pushedIndex = WindowTiler.PushNewWindowInfo(this.windowTilingType, this.windowInfos, windowInfo); this.currentWindowInfoIndex = pushedIndex; } }
/** * <summary> * 対象のウィンドウが本アプリケーションの管理下に置かれるべきウィンドウかどうか判定する * </summary> */ protected bool IsValidWindow(WindowInfoWithHandle windowInfoWithHandle, UInt32 windowLong) { var isVisible = (windowLong & WS_VISIBLE) == WS_VISIBLE; var isOverlappedwindow = (windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW; var isTypeVscode = (windowLong & WS_TYPE_VSCODE) == WS_TYPE_VSCODE; var isUwp = (windowLong & WS_UWP) == WS_UWP; //var isMinimized = (windowLong & WS_MINIMIZE) == WS_MINIMIZE; //var isClipchildren = (windowLong & WS_POPUP & WS_CLIPCHILDREN) == (WS_POPUP & WS_CLIPCHILDREN); //DwmGetWindowAttribute(hwnd, DWMWINDOWATTRIBUTE.Cloaked, out var isCloaked, Marshal.SizeOf(typeof(bool))); /* * * Biscute.exe * TraceWindows.EnumerateWindows : (1) 受信箱 | **** | ProtonMail : 14030000 * * * Microsoft Code * README.md - Visual Studio Code : 14c70000 * * * Chrome * ***** - Chromium : 16cf0000 * * * Edge * **** - Microsoft? Edge : 17cf0000 * * * AS/R * w10wm - Asr : 14cf4000 * * * CMD * cmd.exe : 14ef0000 * * * KeePass * KeePass.kdbx [ロック中] - KeePass : 26cf0000 * KeePass.kdbx [ロック中] - KeePass : 16cf0000 * データベースを開く - KeePass.kdbx : 16c80000 */ var moduleFileName = windowInfoWithHandle.ComputeWindowModuleFileName(); var isChildWindow = windowInfoWithHandle.ComputeIsChildWindow(); var hWnd = windowInfoWithHandle.windowHandle; var windowTitle = windowInfoWithHandle.windowTitle; var windowLongString = windowLong.ToString("x8"); var isValid = (isVisible && (isOverlappedwindow || isTypeVscode) && !isUwp && !isChildWindow && windowTitle != null && !this.IsDenyModuleFileName(moduleFileName) && !this.IsDenyWindowTitle(windowTitle) ); var isValidString = isValid.ToString(); Logger.WriteLine($"TraceWindows.IsValidWindow = {isValidString} : ({hWnd}){windowTitle}(path={moduleFileName}) : {windowLongString}, IsChild={isChildWindow}"); return(isValid); }
/** * <summary> * ウィンドウリストの先頭に追加する * </summary> */ public void Push(WindowInfoWithHandle windowInfo) { lock (this.windowInfosLock) { this.windowInfos.Insert(0, windowInfo); // 追加したらこれをカレントウィンドウにする this.currentWindowInfoIndex = 0; } }
public void RemoveWindowInfo(WindowInfoWithHandle windowInfoWithHandle) { if (this.windowInfos.Contains(windowInfoWithHandle)) { lock (this.windowInfosLock) { this.windowInfos.Remove(windowInfoWithHandle); } } }
/** * <summary> * ウィンドウリストに追加する * </summary> */ public void Add(WindowInfoWithHandle windowInfo) { lock (this.windowInfosLock) { this.windowInfos.Add(windowInfo); // 追加したらこれをカレントウィンドウにする this.currentWindowInfoIndex = this.windowInfos.Count - 1; } }
/** * <summary> * src と dest のウィンドウの位置を入れ替える * </summary> */ public void ChangeWindowPosition(WindowInfoWithHandle srcWindowInfoWithHandle, WindowInfoWithHandle destWindowInfoWithHandle) { if (this.windowTilingType == WindowTilingType.None) { return; } WindowRect srcWindowRect = srcWindowInfoWithHandle.GetCurrentWindowRect(); WindowRect destWindowRect = destWindowInfoWithHandle.GetCurrentWindowRect(); this.MoveWindow(srcWindowInfoWithHandle, destWindowRect); this.MoveWindow(destWindowInfoWithHandle, srcWindowRect); }
// ウィンドウリストから削除する public void Remove(WindowInfoWithHandle windowInfo) { if (this.windowInfos.Contains(windowInfo)) { lock (this.windowInfosLock) { this.windowInfos.Remove(windowInfo); // 削除したら一つ上をカレントウィンドウにする // 0 なら 0 のまま if (this.currentWindowInfoIndex > 0) { this.currentWindowInfoIndex -= 1; } } } }
private bool EnumerateWindows(IntPtr hWnd, IntPtr lParam) { var windowInfo = new WindowInfoWithHandle(hWnd); var windowLong = GetWindowLong(hWnd, GWL_STYLE); var windowTitle = windowInfo.windowTitle; if (!this.windowInfos.Contains(windowInfo)) { if (this.IsValidWindow(windowInfo, windowLong)) { Logger.WriteLine("TraceWindows.EnumerateWindows ADD: (hWnd) {windowTitle} : {windowLongString}"); this.windowInfos.Add(windowInfo); OnAddEvent(windowInfo); } } return(true); }
/** * <summary> * 指定されたWindowInfoWithHandleをWindowRectの位置に移動する * ただしWindowInfoWithHandle.positionXXAdjustmentで位置を補正して隙間ができないようにする * </summary> */ public void MoveWindow(WindowInfoWithHandle windowInfoWithHandle, WindowRect windowRect) { var hWnd = windowInfoWithHandle.windowHandle; var windowRectString = windowRect.ToString(); Logger.WriteLine($"WindowManager.MoveWindow : hWnd={hWnd} To {windowRectString}"); // 最大化、最小化Windowの場合は元のウィンドウにする // if ( IsZoomed(hWnd) || IsIconic(hWnd)) if (IsZoomed(hWnd)) { ShowWindow(hWnd, /* SW_RESTORE = */ 9); } MoveWindow(hWnd, windowRect.GetX() + windowInfoWithHandle.positionLeftAdjustment, windowRect.GetY() + windowInfoWithHandle.positionTopAdjustment, windowRect.GetWidth() + windowInfoWithHandle.positionWidthAdjustment, windowRect.GetHeight() + windowInfoWithHandle.positionHeightAdjustment, /* bRepaint = */ 1); }
public override int PushNewWindowInfo(List <WindowInfoWithHandle> windowInfos, WindowInfoWithHandle windowInfoWithHandle) { // 集中モードの場合は、新規ウィンドウは先頭ではない(先頭は集中対象のウィンドウだから) // なのでその次の位置に新規ウィンドウを挿入する int targetIndex = 0; if (windowInfos.Count > 0) { targetIndex = 1; } windowInfos.Insert(targetIndex, windowInfoWithHandle); return(targetIndex); }
public virtual int PushNewWindowInfo(List <WindowInfoWithHandle> windowInfos, WindowInfoWithHandle windowInfoWithHandle) { windowInfos.Insert(0, windowInfoWithHandle); return(0); }
public override void HookProcedure(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) { var eventName = EventMapConverter.CodeToName((int)eventType); if ((uint)idObject != OBJID_WINDOW) { return; } if (eventName == EventName.UNKNOWN) { return; } var needleWindowInfo = new WindowInfoWithHandle(hWnd); var windowLong = GetWindowLong(hWnd, GWL_STYLE); var windowLongString = windowLong.ToString("x8"); var windowTitle = needleWindowInfo.windowTitle; if (windowLong == 0 || ((windowLong & WS_POPUP) == WS_POPUP) || ((windowLong & WS_CHILD) == WS_CHILD)) { return; } var contains = this.windowInfos.Contains(needleWindowInfo); var processId = needleWindowInfo.ComputeProcessId(); Logger.DebugWindowInfo($"{eventName} : ProcessId={processId}, Contains={contains}", needleWindowInfo); if (!this.windowInfos.Contains(needleWindowInfo)) { if (this.IsValidWindow(needleWindowInfo, windowLong) && (eventName == EventName.EVENT_OBJECT_SHOW)) //eventName == EventName.EVENT_OBJECT_SHOW || //eventName == EventName.EVENT_OBJECT_NAMECHANGE)) { Logger.WriteLine($"TraceWindows.HookProcedure OnAdd : ({hWnd}){windowTitle} : {windowLongString}"); this.windowInfos.Add(needleWindowInfo); OnAddEvent(needleWindowInfo); OnShowEvent(needleWindowInfo); } } else { var windowInfo = this.windowInfos.Find( (WindowInfoWithHandle wi) => { return(wi.windowHandle == needleWindowInfo.windowHandle); }); if (windowInfo == null) { return; } if (eventName == EventName.EVENT_OBJECT_DESTROY) { // Window がなくなった Logger.WriteLine($"TraceWindows.HookProcedure OnDestroy : ({hWnd}){windowTitle} : {windowLongString}"); this.windowInfos.Remove(windowInfo); OnRemoveEvent(windowInfo); OnDestroyEvent(windowInfo); } else if (eventName == EventName.EVENT_OBJECT_HIDE) { // Window が HIDDEN Logger.WriteLine($"TraceWindows.HookProcedure OnHide : ({hWnd}){windowTitle} : {windowLongString}"); this.windowInfos.Remove(windowInfo); OnRemoveEvent(windowInfo); OnHideEvent(windowInfo); } else if (eventName == EventName.EVENT_SYSTEM_MOVESIZESTART) { // Window がマウスでドラッグ開始 Logger.WriteLine($"TraceWindows.HookProcedure OnMouseDragStart : ({hWnd}){windowTitle} : {windowLongString}"); this.mouseDraggingWindowHandle = windowInfo; OnMouseDragStartEvent(windowInfo); } else if (eventName == EventName.EVENT_SYSTEM_MOVESIZEEND) { // Window がマウスでドラッグ終了 if (this.mouseDraggingWindowHandle.Equals(windowInfo)) { Logger.WriteLine($"TraceWindows.HookProcedure OnMouseDragEnd : ({hWnd}){windowTitle} : {windowLongString}"); this.mouseDraggingWindowHandle = null; OnMouseDragEndEvent(windowInfo); OnLocationChangeEvent(windowInfo); } } else if (eventName == EventName.EVENT_OBJECT_LOCATIONCHANGE) { // ショートカットキーだけで場所移動 if (this.mouseDraggingWindowHandle == null) { Logger.WriteLine($"TraceWindows.HookProcedure OnLocationChange : ({hWnd}){windowTitle} : {windowLongString}"); OnLocationChangeEvent(windowInfo); } } else if (eventName == EventName.EVENT_SYSTEM_FOREGROUND) { // Window がアクティヴになった Logger.WriteLine($"TraceWindows.HookProcedure OnActivate : ({hWnd}){windowTitle} : {windowLongString}"); OnActivateEvent(windowInfo); } } }
protected void OnDestroyEvent(WindowInfoWithHandle windowInfo) { DestroyEvent?.Invoke(this, new OriginalWinEventArg(windowInfo)); }
public OriginalWinEventArg(WindowInfoWithHandle windowInfo) { this.WindowInfo = windowInfo; }
protected void OnActivateEvent(WindowInfoWithHandle windowInfo) { ActivateEvent?.Invoke(this, new OriginalWinEventArg(windowInfo)); }
protected void OnMouseDragEndEvent(WindowInfoWithHandle windowInfo) { MouseDragEndEvent?.Invoke(this, new OriginalWinEventArg(windowInfo)); }
protected void OnLocationChangeEvent(WindowInfoWithHandle windowInfo) { LocationChangeEvent?.Invoke(this, new OriginalWinEventArg(windowInfo)); }