Beispiel #1
0
        /// <summary>
        /// Desktopウィンドウのハンドルを返す。
        /// </summary>
        /// <returns>Desktopウィンドウのハンドル。見つからない場合はIntPtr.Zeroを返す。</returns>
        static private IntPtr FindDesktopWindow()
        {
            IntPtrObj hWndDesktop  = new IntPtrObj();
            GCHandle  hhWndDesktop = GCHandle.Alloc(hWndDesktop);

            // hWndDesktop.ValueにDesktopウィンドウのハンドルが返る
            EnumWindows(new EnumWindowsProc(EnumWindowsCallback), (IntPtr)hhWndDesktop);

            hhWndDesktop.Free();

            return(hWndDesktop.Value);
        }
Beispiel #2
0
        /// <summary>
        /// EnumWindowsのハンドラ。
        /// hWndがDesktopウィンドウならlParamで渡されたIntPtrObjのValueにDesktopウィンドウのハンドルを代入する。
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="lParam"></param>
        /// <returns></returns>
        private static bool EnumWindowsCallback(IntPtr hWnd, IntPtr lParam)
        {
            if (!IsDesktopWindow(hWnd))
            {
                return(true);
            }

            GCHandle  hhWndDesktop = GCHandle.FromIntPtr(lParam);
            IntPtrObj hWndDesktop  = (IntPtrObj)hhWndDesktop.Target;

            hWndDesktop.Value = hWnd;

            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Desktopウィンドウのハンドルを返す。
        /// </summary>
        /// <returns>Desktopウィンドウのハンドル。見つからない場合はIntPtr.Zeroを返す。</returns>
        private static IntPtr FindDesktopWindow()
        {
            IntPtrObj hWndDesktop = new IntPtrObj();
            GCHandle hhWndDesktop = GCHandle.Alloc(hWndDesktop);

            // hWndDesktop.ValueにDesktopウィンドウのハンドルが返る
            EnumWindows(new EnumWindowsProc(EnumWindowsCallback), (IntPtr)hhWndDesktop);

            hhWndDesktop.Free();

            return hWndDesktop.Value;
        }