我正在使用 Easy Hook 库。如何获取所有者窗口句柄?
[StructLayout(LayoutKind.Sequential)]
public struct Rect
{
public int Left;
public int Top;
public int Right;
public int Bottom;
public override string ToString()
{
return $"[Left: {Left}, Top: {Top}, Right: {Right}, Bottom: {Bottom}]";
}
}
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int DrawText(IntPtr hDc, string lpString, int nCount, ref Rect lpRect, uint uFormat);
[UnmanagedFunctionPointer(CallingConvention.StdCall, CharSet = CharSet.Unicode, SetLastError = true)]
public delegate int DDrawText(IntPtr hDc, string lpString, int nCount, ref Rect lpRect, uint uFormat);
private int DrawText_Hooked(IntPtr hDc, string lpString, int nCount, ref Rect lpRect, uint uFormat)
{
var This = (Main) HookRuntimeInfo.Callback;
lock (This._queue)
{
var parent = GetAncestor(hDc, GetAncestorFlags.GetParent); // always return 0! why????????????????
This._queue.Push($"parent [{parent}]");
}
return DrawText(hDc, lpString, nCount, ref lpRect, uFormat);
}
GetWindowDC、GetDC、GetParent 等都不行,如何获取父窗口?