/// <summary>
 /// WinuserEvent が発生した際に処理するイベント ハンドラー。
 /// </summary>
 /// <param name="winuserEvent">発生したイベントの種類。</param>
 /// <param name="windowClassName">クラス名。</param>
 private static void WinuserEventOccuredEventHandler(WinuserEvent winuserEvent, string windowClassName)
 {
     if (winuserEvent == WinuserEvent.SystemForeground)
     {
         // WorkerW はデスクトップ
         if (string.Equals(windowClassName, "WorkerW", StringComparison.Ordinal) /*|| string.Equals(windowClassName, "Progman", StringComparison.Ordinal)*/)
         {
             nativeMethods.Window.Topmost = true;
         }
         else
         {
             nativeMethods.Window.Topmost = false;
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// フックを開始します。
        /// </summary>
        /// <param name="winuserEvent">フック対象のイベント。</param>
        public void AddHook(WinuserEvent winuserEvent)
        {
            if (Window == null)
            {
                throw new InvalidOperationException("Window is not set.");
            }
            if (IsHooked)
            {
                return;
            }

            IsHooked = true;

            _delegate   = new WinEventDelegate(WinEventHook);
            _hookIntPtr = NativeMethods.SetWinEventHook((uint)winuserEvent, (uint)winuserEvent, IntPtr.Zero, _delegate, 0, 0, WINEVENT_OUTOFCONTEXT);
        }