public void TestEnsureVisible() { NativeTree tree = new NativeTree(testDlg.IdentifyFromDialogId(1041)); tree.EmulateExpand(tree.Nodes[1], true); IntPtr node = tree.FindNode(1, 99); RECT native = new RECT(); NativeMethods.GetWindowRect(tree.Handle, out native); Rectangle rect = new Rectangle(0, 0, native.Right - native.Left + 1, native.Bottom - native.Top + 1); Assert.IsFalse(rect.Contains(tree.GetItemRect(node, false))); Assert.IsTrue(tree.EnsureVisible(node)); Assert.IsTrue(rect.Contains(tree.GetItemRect(node, false))); }
internal static extern bool GetWindowRect(IntPtr hwnd, out RECT lpRect);
/// <summary> /// Obtains an item's bounds. /// </summary> /// <param name="hItem">Item handle.</param> /// <param name="isTextOnly">True to obtain bounds of only the text portion.</param> /// <returns>Item boundary rectangle.</returns> #else /// <summary> /// アイテム矩形を取得します。 /// </summary> /// <param name="hItem">アイテムハンドル。</param> /// <param name="isTextOnly">テキスト部分のみの取得であるか。</param> /// <returns>アイテム矩形。</returns> #endif public Rectangle GetItemRect(IntPtr hItem, bool isTextOnly) { RECT rc = new RECT(); if (IntPtr.Size == 4) { rc.Left = hItem.ToInt32(); } else { uint ui = (uint)(hItem.ToInt64() & 0xffffffff); rc.Left = (int)ui; ulong ul = (((ulong)hItem.ToInt64() & 0xffffffff00000000) >> 32); ui = (uint)ul; rc.Top = (int)ui; } AppVar inTarget = App.Dim(rc); App[typeof(NativeMethods), "SendMessage"](Handle, TVM_GETITEMRECT, NativeDataUtility.ToIntPtr(isTextOnly), inTarget); return NativeDataUtility.ToRectangle((RECT)inTarget.Core); }