Beispiel #1
0
        private bool EnumerateWindows(IntPtr hwnd, IntPtr lParam)
        {
            var windowInfo         = new WindowInfoWithHandle(hwnd);
            var windowLong         = GetWindowLong(hwnd, GWL_STYLE);
            var windowTitle        = windowInfo.WindowTitle;
            var isVisible          = (windowLong & WS_VISIBLE) == WS_VISIBLE;
            var isOverlappedwindow = (windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW;
            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 は以下の状態なので、WS_OVERLAPPEDWINDOW - WS_SYSMENU なのかも
             * Window add: ********* : 15c70000
             */

            //Debug.WriteLine("Window add: " + windowTitle + " : " + windowLong.ToString("x8"));

            if (!WindowHandles.Contains(windowInfo))
            {
                //if (isVisible && isOverlappedwindow && isClipchildren && !isMinimized && windowTitle != null)
                //if (isVisible && isOverlappedwindow  && !isCloaked && windowTitle != null)
                if (isVisible && isOverlappedwindow && !isUwp && windowTitle != null)
                //if (isVisible && isOverlappedwindow && windowTitle != null)
                {
                    //Debug.WriteLine("Window add: " + windowTitle + " : " + windowLong.ToString("x8"));
                    WindowHandles.Add(windowInfo);
                    OnAddEvent(windowInfo);
                }
            }

            return(true);
        }
Beispiel #2
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 windowInfo         = new WindowInfoWithHandle(hwnd);
            var windowLong         = GetWindowLong(hwnd, GWL_STYLE);
            var windowTitle        = windowInfo.WindowTitle;
            var isVisible          = (windowLong & WS_VISIBLE) == WS_VISIBLE;
            var isOverlappedwindow = (windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW;
            var isUwp = (windowLong & WS_UWP) == WS_UWP;

            if (windowLong == 0)
            {
                return;
            }
            if ((windowLong & WS_CHILD) == WS_CHILD)
            {
                return;
            }


            if (!WindowHandles.Contains(windowInfo))
            {
                if (isVisible && isOverlappedwindow && !isUwp &&
                    (eventName == EventName.EVENT_OBJECT_SHOW ||
                     eventName == EventName.EVENT_OBJECT_NAMECHANGE))
                {
                    //Debug.WriteLine("Window created: " + windowTitle + " : " + windowLong.ToString("x8"));
                    WindowHandles.Add(windowInfo);
                    OnAddEvent(windowInfo);
                    OnShowEvent(windowInfo);

                    /*
                     * Debug.WriteLine("---");
                     * Debug.WriteLine(windowTitle + ":" + is_visible + ":" + eventName + ":" + windowLong);
                     * Debug.WriteLine("WS_VISIBLE = " + ((windowLong & WS_VISIBLE) == WS_VISIBLE));
                     * Debug.WriteLine("WS_OVERLAPPEDWINDOW = " + ((windowLong & WS_OVERLAPPEDWINDOW) == WS_OVERLAPPEDWINDOW));
                     */
                }
            }
            else
            {
                //Debug.WriteLine( " - " + windowTitle + " : " + eventName + ": " + windowLong.ToString("x8"));

                if (eventName == EventName.EVENT_OBJECT_DESTROY)
                {
                    // Window がなくなった
                    //Debug.WriteLine("Window destroyed: " + windowTitle + " : " + windowLong.ToString("x8"));
                    WindowHandles.Remove(windowInfo);
                    OnRemoveEvent(windowInfo);
                    OnDestroyEvent(windowInfo);
                }
                else if (eventName == EventName.EVENT_OBJECT_HIDE)
                {
                    // Window が HIDDEN
                    //Debug.WriteLine("Window hide: " + windowTitle + " : " + windowLong.ToString("x8"));
                    WindowHandles.Remove(windowInfo);
                    OnRemoveEvent(windowInfo);
                    OnHideEvent(windowInfo);
                }
                else if (eventName == EventName.EVENT_SYSTEM_MOVESIZESTART)
                {
                    // Window がマウスでドラッグ開始
                    //Debug.WriteLine("Window mouse drag start: " + windowTitle + " : " + windowLong.ToString("x8"));
                    MouseDraggingWindowHandle = windowInfo;
                    OnMouseDragStartEvent(windowInfo);
                }
                else if (eventName == EventName.EVENT_SYSTEM_MOVESIZEEND)
                {
                    // Window がマウスでドラッグ終了
                    if (MouseDraggingWindowHandle.Equals(windowInfo))
                    {
                        //Debug.WriteLine("Window mouse drag end: " + windowTitle + " : " + windowLong.ToString("x8"));
                        MouseDraggingWindowHandle = null;
                        OnMouseDragEndEvent(windowInfo);
                    }
                }
                else if (eventName == EventName.EVENT_OBJECT_LOCATIONCHANGE)
                {
                    // ショートカットキーだけで場所移動
                    if (MouseDraggingWindowHandle == null)
                    {
                        //Debug.WriteLine("Window location change: " + windowTitle + " : " + windowLong.ToString("x8"));
                        OnLocationChangeEvent(windowInfo);
                    }
                }
            }

            if (WindowHandles.Contains(windowInfo))
            {
                // Debug.WriteLine(" - " + eventName + " : " + windowTitle);
            }

            /*
             * Debug.WriteLine("----");
             * Debug.WriteLine("hWinEventHook:" + hWinEventHook);
             * Debug.WriteLine("eventType:"+eventName);
             * Debug.WriteLine("hwnd:" + hwnd);
             * Debug.WriteLine("title:" + GetCurrentWindowTitle(hwnd));
             * Debug.WriteLine("idObject:" + idObject);
             * Debug.WriteLine("idChild:" + idChild);
             * Debug.WriteLine("dwEventThread:" + dwEventThread);
             * Debug.WriteLine("dwmsEventTime:" + dwmsEventTime);
             */
        }