コード例 #1
0
 private void SetTool(IWin32Window win, string text, TipInfo.Type type, Point position)
 {
     Control key = win as Control;
     if ((key != null) && this.tools.ContainsKey(key))
     {
         bool flag = false;
         System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP lParam = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP();
         try
         {
             lParam.cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP));
             lParam.hwnd = key.Handle;
             lParam.uId = key.Handle;
             if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETTOOLINFO, 0, lParam)) != 0)
             {
                 lParam.uFlags |= 0x20;
                 if ((type == TipInfo.Type.Absolute) || (type == TipInfo.Type.SemiAbsolute))
                 {
                     lParam.uFlags |= 0x80;
                 }
                 lParam.lpszText = Marshal.StringToHGlobalAuto(text);
                 flag = true;
             }
             TipInfo info = (TipInfo) this.tools[key];
             if (info == null)
             {
                 info = new TipInfo(text, type);
             }
             else
             {
                 info.TipType |= type;
                 info.Caption = text;
             }
             info.Position = position;
             this.tools[key] = info;
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_SETTOOLINFO, 0, lParam);
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x411, 1, lParam);
         }
         finally
         {
             if (flag && (IntPtr.Zero != lParam.lpszText))
             {
                 Marshal.FreeHGlobal(lParam.lpszText);
             }
         }
     }
     else
     {
         this.Hide(win);
         TipInfo info2 = (TipInfo) this.tools[key];
         if (info2 == null)
         {
             info2 = new TipInfo(text, type);
         }
         else
         {
             info2.TipType |= type;
             info2.Caption = text;
         }
         info2.Position = position;
         this.tools[key] = info2;
         IntPtr safeHandle = Control.GetSafeHandle(win);
         this.owners[safeHandle] = win;
         System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP winTOOLINFO = this.GetWinTOOLINFO(safeHandle);
         winTOOLINFO.uFlags |= 0x20;
         if ((type == TipInfo.Type.Absolute) || (type == TipInfo.Type.SemiAbsolute))
         {
             winTOOLINFO.uFlags |= 0x80;
         }
         try
         {
             winTOOLINFO.lpszText = Marshal.StringToHGlobalAuto(text);
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_ADDTOOL, 0, winTOOLINFO);
             System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x411, 1, winTOOLINFO);
         }
         finally
         {
             if (IntPtr.Zero != winTOOLINFO.lpszText)
             {
                 Marshal.FreeHGlobal(winTOOLINFO.lpszText);
             }
         }
     }
     if (key != null)
     {
         Form form = key.FindFormInternal();
         if (form != null)
         {
             form.Deactivate += new EventHandler(this.BaseFormDeactivate);
         }
     }
 }
コード例 #2
0
        private void WndProc(ref Message msg)
        {
            int num2 = msg.Msg;
            if (num2 <= 0x21)
            {
                switch (num2)
                {
                    case 3:
                        this.WmMove();
                        return;

                    case 15:
                        goto Label_00FF;

                    case 0x21:
                        this.WmMouseActivate(ref msg);
                        return;
                }
                goto Label_027D;
            }
            if (num2 <= 0x318)
            {
                switch (num2)
                {
                    case 70:
                        this.WmWindowPosChanging(ref msg);
                        return;

                    case 0x47:
                        if (!this.WmWindowPosChanged())
                        {
                            this.window.DefWndProc(ref msg);
                        }
                        return;

                    case 0x318:
                        goto Label_00FF;
                }
                goto Label_027D;
            }
            if (num2 == 0x410)
            {
                this.WmWindowFromPoint(ref msg);
                return;
            }
            if (num2 != 0x204e)
            {
                goto Label_027D;
            }
            System.Windows.Forms.NativeMethods.NMHDR lParam = (System.Windows.Forms.NativeMethods.NMHDR) msg.GetLParam(typeof(System.Windows.Forms.NativeMethods.NMHDR));
            if ((lParam.code == -521) && !this.trackPosition)
            {
                this.WmShow();
                return;
            }
            if (lParam.code == -522)
            {
                this.WmPop();
                this.window.DefWndProc(ref msg);
            }
            return;
        Label_00FF:
            if ((this.ownerDraw && !this.isBalloon) && !this.trackPosition)
            {
                System.Windows.Forms.NativeMethods.PAINTSTRUCT lpPaint = new System.Windows.Forms.NativeMethods.PAINTSTRUCT();
                Graphics graphics = Graphics.FromHdcInternal(System.Windows.Forms.UnsafeNativeMethods.BeginPaint(new HandleRef(this, this.Handle), ref lpPaint));
                Rectangle bounds = new Rectangle(lpPaint.rcPaint_left, lpPaint.rcPaint_top, lpPaint.rcPaint_right - lpPaint.rcPaint_left, lpPaint.rcPaint_bottom - lpPaint.rcPaint_top);
                if (bounds == Rectangle.Empty)
                {
                    return;
                }
                System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP toolinfo_tooltip = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
                    cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
                };
                if (((int) ((long) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, toolinfo_tooltip))) != 0)
                {
                    Font defaultFont;
                    IWin32Window associatedWindow = (IWin32Window) this.owners[toolinfo_tooltip.hwnd];
                    Control associatedControl = Control.FromHandleInternal(toolinfo_tooltip.hwnd);
                    if (associatedWindow == null)
                    {
                        associatedWindow = associatedControl;
                    }
                    System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
                    try
                    {
                        defaultFont = Font.FromHfont(System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x31, 0, 0));
                    }
                    catch (ArgumentException)
                    {
                        defaultFont = Control.DefaultFont;
                    }
                    finally
                    {
                        CodeAccessPermission.RevertAssert();
                    }
                    try
                    {
                        this.OnDraw(new DrawToolTipEventArgs(graphics, associatedWindow, associatedControl, bounds, this.GetToolTip(associatedControl), this.BackColor, this.ForeColor, defaultFont));
                        return;
                    }
                    finally
                    {
                        graphics.Dispose();
                        System.Windows.Forms.UnsafeNativeMethods.EndPaint(new HandleRef(this, this.Handle), ref lpPaint);
                    }
                }
            }
        Label_027D:
            this.window.DefWndProc(ref msg);
        }
コード例 #3
0
 private System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP GetWinTOOLINFO(IntPtr hWnd)
 {
     System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP toolinfo_tooltip;
     toolinfo_tooltip = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
         cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP)),
         hwnd = hWnd,
         uFlags = toolinfo_tooltip.uFlags | 0x111
     };
     Control topLevelControl = this.TopLevelControl;
     if (((topLevelControl != null) && (topLevelControl.RightToLeft == RightToLeft.Yes)) && ((((int) ((long) System.Windows.Forms.UnsafeNativeMethods.GetWindowLong(new HandleRef(this, hWnd), -16))) & 0x400000) != 0x400000))
     {
         toolinfo_tooltip.uFlags |= 4;
     }
     toolinfo_tooltip.uId = toolinfo_tooltip.hwnd;
     return toolinfo_tooltip;
 }
コード例 #4
0
 private unsafe void WmWindowPosChanging(ref Message m)
 {
     if (!this.cancelled)
     {
         System.Windows.Forms.NativeMethods.WINDOWPOS* lParam = (System.Windows.Forms.NativeMethods.WINDOWPOS*) m.LParam;
         Cursor currentInternal = Cursor.CurrentInternal;
         Point position = Cursor.Position;
         System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP toolinfo_tooltip = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
             cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
         };
         if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, toolinfo_tooltip)) != 0)
         {
             IWin32Window window = (IWin32Window) this.owners[toolinfo_tooltip.hwnd];
             if (window == null)
             {
                 window = Control.FromHandleInternal(toolinfo_tooltip.hwnd);
             }
             if ((window == null) || !this.IsWindowActive(window))
             {
                 return;
             }
             TipInfo info = null;
             if (window != null)
             {
                 info = (TipInfo) this.tools[window];
                 if (info == null)
                 {
                     return;
                 }
                 TreeView view = window as TreeView;
                 if ((view != null) && view.ShowNodeToolTips)
                 {
                     return;
                 }
             }
             if (this.IsBalloon)
             {
                 lParam->cx += 20;
                 return;
             }
             if ((info.TipType & TipInfo.Type.Auto) != TipInfo.Type.None)
             {
                 this.window.DefWndProc(ref m);
                 return;
             }
             if (((info.TipType & TipInfo.Type.SemiAbsolute) != TipInfo.Type.None) && (info.Position == Point.Empty))
             {
                 Screen screen = Screen.FromPoint(position);
                 if (currentInternal != null)
                 {
                     lParam->x = position.X;
                     try
                     {
                         System.Windows.Forms.IntSecurity.ObjectFromWin32Handle.Assert();
                         lParam->y = position.Y;
                         if ((((lParam->y + lParam->cy) + currentInternal.Size.Height) - currentInternal.HotSpot.Y) > screen.WorkingArea.Bottom)
                         {
                             lParam->y = position.Y - lParam->cy;
                         }
                         else
                         {
                             lParam->y = (position.Y + currentInternal.Size.Height) - currentInternal.HotSpot.Y;
                         }
                     }
                     finally
                     {
                         CodeAccessPermission.RevertAssert();
                     }
                 }
                 if ((lParam->x + lParam->cx) > screen.WorkingArea.Right)
                 {
                     lParam->x = screen.WorkingArea.Right - lParam->cx;
                 }
             }
             else if (((info.TipType & TipInfo.Type.SemiAbsolute) != TipInfo.Type.None) && (info.Position != Point.Empty))
             {
                 Screen screen2 = Screen.FromPoint(info.Position);
                 lParam->x = info.Position.X;
                 if ((lParam->x + lParam->cx) > screen2.WorkingArea.Right)
                 {
                     lParam->x = screen2.WorkingArea.Right - lParam->cx;
                 }
                 lParam->y = info.Position.Y;
                 if ((lParam->y + lParam->cy) > screen2.WorkingArea.Bottom)
                 {
                     lParam->y = screen2.WorkingArea.Bottom - lParam->cy;
                 }
             }
         }
         m.Result = IntPtr.Zero;
     }
 }
コード例 #5
0
 private void WmShow()
 {
     System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT();
     System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(this, this.Handle), ref rect);
     System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP lParam = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
         cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
     };
     if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, lParam)) != 0)
     {
         IWin32Window associatedWindow = (IWin32Window) this.owners[lParam.hwnd];
         if (associatedWindow == null)
         {
             associatedWindow = Control.FromHandleInternal(lParam.hwnd);
         }
         if (associatedWindow != null)
         {
             Control associatedControl = associatedWindow as Control;
             Size size = rect.Size;
             PopupEventArgs e = new PopupEventArgs(associatedWindow, associatedControl, this.IsBalloon, size);
             this.OnPopup(e);
             DataGridView view = associatedControl as DataGridView;
             if ((view != null) && view.CancelToolTipPopup(this))
             {
                 e.Cancel = true;
             }
             System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(this, this.Handle), ref rect);
             size = (e.ToolTipSize == size) ? rect.Size : e.ToolTipSize;
             if (this.IsBalloon)
             {
                 System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x41f, 1, ref rect);
                 if (rect.Size.Height > size.Height)
                 {
                     size.Height = rect.Size.Height;
                 }
             }
             if (size != rect.Size)
             {
                 Screen screen = Screen.FromPoint(Cursor.Position);
                 int num2 = this.IsBalloon ? Math.Min(size.Width - 20, screen.WorkingArea.Width) : Math.Min(size.Width, screen.WorkingArea.Width);
                 System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x418, 0, num2);
             }
             if (e.Cancel)
             {
                 this.cancelled = true;
                 System.Windows.Forms.SafeNativeMethods.SetWindowPos(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.HWND_TOPMOST, 0, 0, 0, 0, 0x210);
             }
             else
             {
                 this.cancelled = false;
                 System.Windows.Forms.SafeNativeMethods.SetWindowPos(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.HWND_TOPMOST, rect.left, rect.top, size.Width, size.Height, 0x210);
             }
         }
     }
 }
コード例 #6
0
 private void WmPop()
 {
     System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP lParam = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
         cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
     };
     if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, lParam)) != 0)
     {
         IWin32Window window = (IWin32Window) this.owners[lParam.hwnd];
         if (window == null)
         {
             window = Control.FromHandleInternal(lParam.hwnd);
         }
         if (window != null)
         {
             Control key = window as Control;
             TipInfo info = (TipInfo) this.tools[window];
             if (info != null)
             {
                 if (((info.TipType & TipInfo.Type.Auto) != TipInfo.Type.None) || ((info.TipType & TipInfo.Type.SemiAbsolute) != TipInfo.Type.None))
                 {
                     Screen screen = Screen.FromPoint(Cursor.Position);
                     System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), 0x418, 0, screen.WorkingArea.Width);
                 }
                 if ((info.TipType & TipInfo.Type.Auto) == TipInfo.Type.None)
                 {
                     this.tools.Remove(key);
                     this.owners.Remove(window.Handle);
                     key.HandleCreated -= new EventHandler(this.HandleCreated);
                     key.HandleDestroyed -= new EventHandler(this.HandleDestroyed);
                     this.created.Remove(key);
                     if (this.originalPopupDelay != 0)
                     {
                         this.AutoPopDelay = this.originalPopupDelay;
                         this.originalPopupDelay = 0;
                     }
                 }
                 else
                 {
                     info.TipType = TipInfo.Type.Auto;
                     info.Position = Point.Empty;
                     this.tools[key] = info;
                 }
             }
         }
     }
 }
コード例 #7
0
 private void WmMove()
 {
     System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT();
     System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(this, this.Handle), ref rect);
     System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP lParam = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
         cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
     };
     if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, lParam)) != 0)
     {
         IWin32Window window = (IWin32Window) this.owners[lParam.hwnd];
         if (window == null)
         {
             window = Control.FromHandleInternal(lParam.hwnd);
         }
         if (window != null)
         {
             TipInfo info = (TipInfo) this.tools[window];
             if ((window != null) && (info != null))
             {
                 TreeView view = window as TreeView;
                 if (((view == null) || !view.ShowNodeToolTips) && (info.Position != Point.Empty))
                 {
                     this.Reposition(info.Position, rect.Size);
                 }
             }
         }
     }
 }
コード例 #8
0
 private void WmMouseActivate(ref Message msg)
 {
     System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP lParam = new System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP {
         cbSize = Marshal.SizeOf(typeof(System.Windows.Forms.NativeMethods.TOOLINFO_TOOLTIP))
     };
     if (((int) System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, this.Handle), System.Windows.Forms.NativeMethods.TTM_GETCURRENTTOOL, 0, lParam)) != 0)
     {
         IWin32Window wrapper = (IWin32Window) this.owners[lParam.hwnd];
         if (wrapper == null)
         {
             wrapper = Control.FromHandleInternal(lParam.hwnd);
         }
         if (wrapper != null)
         {
             System.Windows.Forms.NativeMethods.RECT rect = new System.Windows.Forms.NativeMethods.RECT();
             System.Windows.Forms.UnsafeNativeMethods.GetWindowRect(new HandleRef(wrapper, Control.GetSafeHandle(wrapper)), ref rect);
             Point position = Cursor.Position;
             if (((position.X >= rect.left) && (position.X <= rect.right)) && ((position.Y >= rect.top) && (position.Y <= rect.bottom)))
             {
                 msg.Result = (IntPtr) 3;
             }
         }
     }
 }