Ejemplo n.º 1
0
        public static WindowPlacement GetPlacement(
            IntPtr windowHandle, bool throwOnError)
        {
            var placement = new WindowPlacement();

            if (windowHandle == IntPtr.Zero)
            {
                return(placement);
            }

            placement.Length = Marshal.SizeOf(
                typeof(WindowPlacement));

            if (WindowNative.GetWindowPlacement(
                    windowHandle, ref placement))
            {
                return(placement);
            }

            if (throwOnError)
            {
                throw new Win32Exception(
                          Marshal.GetLastWin32Error());
            }

            return(new WindowPlacement());
        }
Ejemplo n.º 2
0
        public static bool SendString(IntPtr hwnd,
                                      uint msg, int dwData, string value,
                                      bool unicode = true)
        {
            var data = CreateForString(
                dwData, value, unicode);
            var dataSize = Environment
                           .GetSize <CopyData>();
            var dataPtr = Marshal
                          .AllocCoTaskMem(dataSize);

            Marshal.StructureToPtr(
                data, dataPtr, false);

            var messageReceived = WindowNative
                                  .SendMessage(hwnd, msg,
                                               IntPtr.Zero, dataPtr)
                                  .ToInt32() != 0;

            data.Dispose();

            Marshal.FreeCoTaskMem(
                dataPtr);

            return(messageReceived);
        }
Ejemplo n.º 3
0
 public static void ActivateWindow(IntPtr hwnd)
 {
     if (hwnd != IntPtr.Zero)
     {
         WindowNative.SetActiveWindow(hwnd);
     }
 }
Ejemplo n.º 4
0
        public static IntPtr GetModalWindow(IntPtr owner)
        {
            ModalWindow window = new ModalWindow();

            WindowNative.EnumThreadWindows(WindowNative.GetCurrentThreadId(),
                                           window.EnumChildren, owner);

            return(window.MaxOwnershipHandle);
        }
Ejemplo n.º 5
0
        public bool EnumChildren(IntPtr hwnd, IntPtr lParam)
        {
            int level = 1;

            if (WindowNative.IsWindowVisible(hwnd) &&
                ModalWindowUtils.IsOwned(lParam, hwnd, ref level) &&
                level > _maxOwnershipLevel)
            {
                MaxOwnershipHandle = hwnd;
                _maxOwnershipLevel = level;
            }

            return(true);
        }
Ejemplo n.º 6
0
        public static bool IsOwned(IntPtr owner, IntPtr hwnd, ref int level)
        {
            IntPtr ownerWindow = WindowNative.GetWindow(hwnd, ModalWindow.GwOwner);

            if (ownerWindow == IntPtr.Zero)
            {
                return(false);
            }

            if (ownerWindow == owner)
            {
                return(true);
            }

            level++;

            return(IsOwned(owner, ownerWindow, ref level));
        }
Ejemplo n.º 7
0
 public void SetPlacement(IntPtr windowHandle)
 {
     WindowNative.SetWindowPlacement(windowHandle, ref this);
 }