Можно вызвать NativeWindowControl.CreateFromHandle из handle окна, и для созданного контрола показать тултип:
Код | public class NativeWindowControl : Control { private NativeWindowControl() { }
[DllImport("user32.dll")] static extern IntPtr GetParent(IntPtr handle); [DllImport("user32.dll")] static extern int GetWindowThreadProcessId(IntPtr handle, ref int processId);
public static NativeWindowControl CreateFromHandle(IntPtr handle) { // create control... NativeWindowControl ret = new NativeWindowControl(); FieldInfo fi = typeof(Control).GetField("window", BindingFlags.NonPublic | BindingFlags.Instance); NativeWindow wnd = (NativeWindow)fi.GetValue(ret); wnd.AssignHandle(handle); ret.OnHandleCreated(EventArgs.Empty); ret.UpdateBounds();
// ...and form Form form = new Form(); IntPtr tmpHandle = handle, parentHandle = handle; int unused = 0; int currThreadId = GetWindowThreadProcessId(handle, ref unused); while ((tmpHandle = GetParent(parentHandle)) != IntPtr.Zero) { if (GetWindowThreadProcessId(tmpHandle, ref unused) != currThreadId) break; parentHandle = tmpHandle; } wnd = (NativeWindow)fi.GetValue(form); wnd.AssignHandle(parentHandle); MethodInfo mi = typeof(Form).GetMethod("OnHandleCreated", BindingFlags.NonPublic | BindingFlags.Instance); mi.Invoke(form, new object[] { EventArgs.Empty }); mi = typeof(Form).GetMethod("UpdateBounds", BindingFlags.NonPublic | BindingFlags.Instance, null, Type.EmptyTypes, null); mi.Invoke(form, new object[0]); form.Visible = true;
// bind them together fi = typeof(Control).GetField("parent", BindingFlags.NonPublic | BindingFlags.Instance); fi.SetValue(ret, form);
return ret; }
protected override void CreateHandle() { } }
|
|