mirror of
https://github.com/mirror/processhacker
synced 2026-06-08 16:03:24 +00:00
refactoring in WindowHandle
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1577 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
@@ -2251,7 +2251,7 @@ namespace ProcessHacker.Native.Api
|
||||
);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern int EnumWindows(
|
||||
public static extern bool EnumWindows(
|
||||
[In] [MarshalAs(UnmanagedType.FunctionPtr)] EnumWindowsProc Callback,
|
||||
[In] int param
|
||||
);
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ProcessHacker.Native.Api;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace ProcessHacker.Native.Objects
|
||||
{
|
||||
public struct WindowHandle
|
||||
public delegate bool EnumerateWindowsDelegate(WindowHandle windowHandle);
|
||||
|
||||
public struct WindowHandle : IEquatable<WindowHandle>, IEquatable<IntPtr>
|
||||
{
|
||||
private static WindowHandle _zero = new WindowHandle(IntPtr.Zero);
|
||||
|
||||
@@ -15,6 +17,16 @@ namespace ProcessHacker.Native.Objects
|
||||
get { return _zero; }
|
||||
}
|
||||
|
||||
public static bool Enumerate(EnumerateWindowsDelegate callback)
|
||||
{
|
||||
return Win32.EnumWindows((hWnd, param) => callback(new WindowHandle(hWnd)), 0);
|
||||
}
|
||||
|
||||
public static bool EnumerateByThreadId(int tid, EnumerateWindowsDelegate callback)
|
||||
{
|
||||
return Win32.EnumThreadWindows(tid, (hWnd, param) => callback(new WindowHandle(hWnd)), 0);
|
||||
}
|
||||
|
||||
public static WindowHandle Find(string className, string windowName)
|
||||
{
|
||||
IntPtr handle = Win32.FindWindow(className, windowName);
|
||||
@@ -54,6 +66,11 @@ namespace ProcessHacker.Native.Objects
|
||||
get { return _handle; }
|
||||
}
|
||||
|
||||
public bool IsInvalid
|
||||
{
|
||||
get { return _handle == IntPtr.Zero; }
|
||||
}
|
||||
|
||||
public bool BringToTop()
|
||||
{
|
||||
return Win32.BringWindowToTop(this);
|
||||
@@ -69,6 +86,21 @@ namespace ProcessHacker.Native.Objects
|
||||
return Win32.DestroyWindow(this);
|
||||
}
|
||||
|
||||
public bool EnumerateChildren(EnumerateWindowsDelegate callback)
|
||||
{
|
||||
return Win32.EnumChildWindows(this, (hWnd, param) => callback(new WindowHandle(hWnd)), 0);
|
||||
}
|
||||
|
||||
public bool Equals(WindowHandle other)
|
||||
{
|
||||
return this.Handle.Equals(other.Handle);
|
||||
}
|
||||
|
||||
public bool Equals(IntPtr other)
|
||||
{
|
||||
return this.Handle.Equals(other);
|
||||
}
|
||||
|
||||
public ClientId GetClientId()
|
||||
{
|
||||
int tid, pid;
|
||||
@@ -83,11 +115,13 @@ namespace ProcessHacker.Native.Objects
|
||||
return new WindowHandle(Win32.GetParent(this));
|
||||
}
|
||||
|
||||
public WindowPlacement GetWindowPlacement()
|
||||
public WindowPlacement GetPlacement()
|
||||
{
|
||||
WindowPlacement placement = new WindowPlacement();
|
||||
|
||||
placement.Length = Marshal.SizeOf(placement);
|
||||
Win32.GetWindowPlacement(this, ref placement);
|
||||
|
||||
return placement;
|
||||
}
|
||||
|
||||
@@ -130,5 +164,25 @@ namespace ProcessHacker.Native.Objects
|
||||
{
|
||||
return Win32.IsWindowVisible(this);
|
||||
}
|
||||
|
||||
public bool PostMessage(WindowMessage message, int wParam, int lParam)
|
||||
{
|
||||
return Win32.PostMessage(this, message, wParam, lParam);
|
||||
}
|
||||
|
||||
public IntPtr SendMessage(WindowMessage message, int wParam, int lParam)
|
||||
{
|
||||
return Win32.SendMessage(this, message, wParam, lParam);
|
||||
}
|
||||
|
||||
public bool SetForeground()
|
||||
{
|
||||
return Win32.SetForegroundWindow(this);
|
||||
}
|
||||
|
||||
public bool Show(ShowWindowType flags)
|
||||
{
|
||||
return Win32.ShowWindow(this, flags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user