예제 #1
0
            /// <summary>
            /// Initialize a tool with its associated tool tip control, caption, and id
            /// </summary>
            /// <param name="toolTipCtl">associated tool tip control</param>
            /// <param name="toolCaption">tool caption</param>
            /// <param name="id">tool id</param>
            public Tool(IntPtr toolTipCtl, string toolCaption, UIntPtr id)
            {
                // save reference to owning tooltip control
                toolTipControl = toolTipCtl;

                // fill out the toolinfo struct
                toolInfo             = new TOOLINFO();
                toolInfo.cbSize      = (uint)Marshal.SizeOf(toolInfo);
                toolInfo.uFlags      = (BidiHelper.IsRightToLeft ? TTF.TRACK | TTF.ABSOLUTE | TTF_RTLREADING : TTF.TRACK | TTF.ABSOLUTE);
                toolInfo.hwnd        = IntPtr.Zero;
                toolInfo.hinst       = IntPtr.Zero;
                toolInfo.uId         = id;
                toolInfo.lpszText    = toolCaption;
                toolInfo.rect.left   = 0;
                toolInfo.rect.top    = 0;
                toolInfo.rect.right  = 0;
                toolInfo.rect.bottom = 0;
                toolInfo.lParam      = IntPtr.Zero;

                // get an unmanaged pointer to the structure (will be freed on Dispose)
                pToolInfo = Marshal.AllocHGlobal(Marshal.SizeOf(toolInfo));
                Marshal.StructureToPtr(toolInfo, pToolInfo, false);

                // add the tool to the window
                User32.SendMessage(toolTipControl, TTM.ADDTOOL, UIntPtr.Zero, pToolInfo);
            }
예제 #2
0
        /// <summary>
        /// Registers a tool with a ToolTip control
        /// </summary>
        /// <param name="_wndTooltip">HWND of the tooltip</param>
        /// <param name="_ti">TOOLINFO structure containing information that the ToolTip control needs to display text for the tool.</param>
        /// <returns>Returns true if successful.</returns>
        internal static bool AddTool(IntPtr _wndTooltip, TOOLINFO _ti)
        {
            const int TTM_ADDTOOL = WM_USER + 50;
            int       res         = SendToolInfoMessage(_wndTooltip, TTM_ADDTOOL, 0, _ti);

            return(Convert.ToBoolean(res));
        }
예제 #3
0
 void Show(string title, string text, Control control, ICON icon = 0, double timeOut = 0, bool allowMulti = false, bool focus = false, short x = 0, short y = 0)
 {
     if (!allowMulti)
         CloseAll();
     if (x == 0 && y == 0)
     {
         x = (short)(control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
         y = (short)(control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
     }
     TOOLINFO toolInfo = new TOOLINFO();
     toolInfo.cbSize = (uint)Marshal.SizeOf(toolInfo);
     toolInfo.uFlags = 0x20; // TTF_TRACK
     toolInfo.lpszText = text;
     IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));
     Marshal.StructureToPtr(toolInfo, pToolInfo, false);
     byte[] buffer = Encoding.UTF8.GetBytes(title);
     buffer = buffer.Concat(new byte[] { 0 }).ToArray();
     IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);
     Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
     hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
     User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo); // TTM_ADDTOOL
     User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)((ushort)x | ((ushort)y << 16))); // TTM_TRACKPOSITION
     //User32.SendMessage(hWnd, 1043, (IntPtr)0, (IntPtr)0); // TTM_SETTIPBKCOLOR
     //User32.SendMessage(hWnd, 1044, (IntPtr)0xffff, (IntPtr)0); // TTM_SETTIPTEXTCOLOR
     User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle); // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
     User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500); // TTM_SETMAXTIPWIDTH
     User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo); // TTM_UPDATETIPTEXT; 0x439 for Unicode
     User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo); // TTM_TRACKACTIVATE
     Marshal.FreeCoTaskMem(pszTitle);
     Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
     Marshal.FreeCoTaskMem(pToolInfo);
     if (focus)
         control.Focus();
     control.Enter += control_Event;
     control.Leave += control_Event;
     control.TextChanged += control_Event;
     control.KeyPress += control_Event;
     control.Click += control_Event;
     control.LocationChanged += control_Event;
     control.SizeChanged += control_Event;
     control.VisibleChanged += control_Event;
     if (control is DataGridView)
         ((DataGridView)control).CellBeginEdit += control_Event;
     Control parent = control.Parent;
     while(parent != null)
     {
         parent.VisibleChanged += control_Event;
         parent = parent.Parent;
     }
     control.TopLevelControl.LocationChanged += control_Event;
     ((Form)control.TopLevelControl).Deactivate += control_Event;
     timer.AutoReset = false;
     timer.Elapsed += timer_Elapsed;
     if (timeOut > 0)
     {
         timer.Interval = timeOut;
         timer.Start();
     }
 }
예제 #4
0
        void Show(string title, string text, Control control, ICON icon = 0, double timeOut = 0, bool focus = false)
        {
            ushort   x        = (ushort)(control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
            ushort   y        = (ushort)(control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
            TOOLINFO toolInfo = new TOOLINFO();

            toolInfo.cbSize   = (uint)Marshal.SizeOf(toolInfo);
            toolInfo.uFlags   = 0x20;   // TTF_TRACK
            toolInfo.lpszText = text;
            IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));

            Marshal.StructureToPtr(toolInfo, pToolInfo, false);
            byte[] buffer = Encoding.UTF8.GetBytes(title);
            buffer = buffer.Concat(new byte[] { 0 }).ToArray();
            IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);

            Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
            hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
            User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo);               // TTM_ADDTOOL
            User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo);               // TTM_TRACKACTIVATE
            User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)(x | (y << 16))); // TTM_TRACKPOSITION
            //User32.SendMessage(hWnd, 1043, (IntPtr)0, (IntPtr)0); // TTM_SETTIPBKCOLOR
            //User32.SendMessage(hWnd, 1044, (IntPtr)0xffff, (IntPtr)0); // TTM_SETTIPTEXTCOLOR
            User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle);    // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
            User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500);    // TTM_SETMAXTIPWIDTH
            User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo);     // TTM_UPDATETIPTEXT; 0x439 for Unicode
            Marshal.FreeCoTaskMem(pszTitle);
            Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
            Marshal.FreeCoTaskMem(pToolInfo);
            if (focus)
            {
                control.Focus();
            }
            // uncomment bellow to make balloon close when user changes focus,
            // starts typing, resizes/moves parent window, minimizes parent window, etc
            // adjust which control events to subscribe to depending on the control over which the balloon tip is shown

            /*control.Click += control_Event;
             * control.Leave += control_Event;
             * control.TextChanged += control_Event;
             * control.LocationChanged += control_Event;
             * control.SizeChanged += control_Event;
             * control.VisibleChanged += control_Event;
             * Control parent = control.Parent;
             * while(parent != null)
             * {
             *  parent.VisibleChanged += control_Event;
             *  parent = parent.Parent;
             * }
             * control.TopLevelControl.LocationChanged += control_Event;
             * ((Form)control.TopLevelControl).Deactivate += control_Event;*/
            timer.AutoReset = false;
            timer.Elapsed  += timer_Elapsed;
            if (timeOut > 0)
            {
                timer.Interval = timeOut;
                timer.Start();
            }
        }
예제 #5
0
        public void SetToolTip(Control parent, Rectangle rect, string tipText)
        {
            System.Diagnostics.Debug.Assert(parent != null, "parent is null", "parent cant be null");
            m_text = tipText;

            CreateParams cp = new CreateParams();

            cp.ClassName = TOOLTIPS_CLASS;
            cp.Style     = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP;

            cp.Parent = parent.Handle;

            // create the tool
            m_tool.CreateHandle(cp);

            // adjust the rectangle
            Rectangle r = rect;
            IntPtr    p = Marshal.AllocHGlobal(Marshal.SizeOf(r));

            Marshal.StructureToPtr(r, p, true);
            SendMessage(m_tool.Handle, TTM_ADJUSTRECT, -1, p);
            r = (Rectangle)Marshal.PtrToStructure(p, typeof(Rectangle));
            Marshal.FreeHGlobal(p);

            // make sure we make it the top level window
            SetWindowPos(
                m_tool.Handle, HWND_TOPMOST, r.Left, r.Top, 0, 0,
                SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

            // create and fill in the tool tip info
            TOOLINFO ti = new TOOLINFO();

            ti.cbSize = Marshal.SizeOf(ti);
            ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS;

            ti.hwnd     = parent.Handle;
            ti.lpszText = m_text;
            ti.rect     = parent.ClientRectangle;

            // add the tool tip
            IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));

            Marshal.StructureToPtr(ti, ptrStruct, true);

            SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct);

            Marshal.FreeHGlobal(ptrStruct);

            SendMessage(m_tool.Handle, TTM_SETMAXTIPWIDTH,
                        0, new IntPtr(m_maxWidth));

            //			IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);
            //
            //			WinDeclns.SendMessage(
            //				m_tool.Handle, TTDeclns.TTM_SETTITLE,
            //				(int)m_titleIcon, ptrTitle);
            //
            //			Marshal.FreeHGlobal(ptrTitle);
        }
예제 #6
0
        private void TooltipAction(Control ctrl, string text, TToolAction action)
        {
            if (ctrl.Parent != null)
            {
                AttachToParent(ctrl.Parent.Handle);

                Rectangle clientRect = new Rectangle(ctrl.Location, ctrl.Size);

                TOOLINFO info = new TOOLINFO();
                info.cbSize   = (uint)Marshal.SizeOf(typeof(TOOLINFO));
                info.uFlags   = (uint)ToolTipFlags.TTF_IDISHWND | (uint)ToolTipFlags.TTF_SUBCLASS;
                info.hwnd     = ctrl.Parent.Handle;
                info.uId      = ctrl.Handle;
                info.lpszText = text; //( text != null ) ? Marshal.StringToHGlobalAuto( text ) : IntPtr.Zero;
                info.rect     = (RECT)clientRect;

                int msg = 0;

                switch (action)
                {
                case TToolAction.INSERT:
                    msg = (int)ToolTipMsg.TTM_ADDTOOLW;
                    Trace.WriteLine("Add", "TOOL ACTION");
                    break;

                case TToolAction.UPDATE:
                    msg = (int)ToolTipMsg.TTM_UPDATETIPTEXTW;
                    Trace.WriteLine("Update Text", "TOOL ACTION");
                    break;

                case TToolAction.REMOVE:
                    msg = (int)ToolTipMsg.TTM_DELTOOLW;
                    Trace.WriteLine("Add", "TOOL ACTION");
                    break;
                }

                int result = WindowsAPI.SendMessage(m_tooltip.Handle, msg, 0, ref info);

                if (result == 0)
                {
                    Trace.WriteLine("Tool Action status FAIL!!!", "Notification");
                }
            }
        }
예제 #7
0
            private void CreateTool()
            {
                System.Diagnostics.Debug.Assert(
                    mToolP.Handle != IntPtr.Zero,
                    "parent hwnd is null", "SetToolTip");

                CreateParams cp = new CreateParams();
                cp.ClassName = TOOLTIPS_CLASS;
                cp.Style =
                    WS_POPUP |
                    TTS_BALLOON |
                    TTS_NOPREFIX |
                    TTS_ALWAYSTIP |
                    TTS_CLOSE;

                mTool.CreateHandle(cp);

                ti = new TOOLINFO();
                ti.cbSize = Marshal.SizeOf(ti);

                ti.uFlags = TTF_TRACK |
                    TTF_IDISHWND |
                    TTF_TRANSPARENT |
                    TTF_SUBCLASS |
                    TTF_PARSELINKS;

                if (tipmPos)
                    ti.uFlags |= TTF_ABSOLUTE;

                if (tipmCen)
                    ti.uFlags |= TTF_CENTERTIP;

                ti.uId = mTool.Handle;
                ti.lpszText = tipmText;
                ti.hwnd = mToolP.Handle;

                GetClientRect(mToolP.Handle, ref ti.rect);
                ClientToScreen(mToolP.Handle, ref ti.rect);

                SetWindowPos(
                    mTool.Handle,
                    HWND_TOPMOST,
                    0, 0, 0, 0,
                    SWP_NOACTIVATE |
                    SWP_NOMOVE |
                    SWP_NOSIZE);

                IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));
                Marshal.StructureToPtr(ti, ptrStruct, true);

                SendMessage(
                    mTool.Handle, TTM_ADDTOOL, 0, ptrStruct);

                ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct,
                    typeof(TOOLINFO));

                SendMessage(
                    mTool.Handle, TTM_SETMAXTIPWIDTH,
                    0, new IntPtr(mtoolMax));

                IntPtr ptrTitle = Marshal.StringToHGlobalAuto(tipmTitle);

                SendMessage(
                    mTool.Handle, TTM_SETTITLE,
                    (int)tipmTI, ptrTitle);

                SetPos(ti.rect);

                Marshal.FreeHGlobal(ptrStruct);
                Marshal.FreeHGlobal(ptrTitle);
            }
 /// <summary>
 /// Remove all ToolTips.
 /// </summary>
 public void RemoveAll()
 {
     SendMessage(_hTipWnd, TTM_SETTITLE, IntPtr.Zero, "");
     foreach (IntPtr h in _aHandles)
     {
         TOOLINFO tI = new TOOLINFO(0);
         tI.hwnd = h;
         tI.uId = h;
         SendMessage(_hTipWnd, TTM_DELTOOL, 0, ref tI);
     }
     _dCaption.Clear();
     _aHandles.Clear();
     _dSize.Clear();
     _oIcons.Images.Clear();
 }
예제 #9
0
        private static void Add(IntPtr handle)
        {
            _tooltipWindow = CreateWindowEx(WindowStylesEx.WS_EX_TOPMOST | WindowStylesEx.WS_EX_TRANSPARENT, "tooltips_class32", null,
                (uint)WindowStyles.WS_POPUP | (uint)ToolTipStyles.TTS_NOPREFIX | (uint)ToolTipStyles.TTS_ALWAYSTIP,
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            SetWindowPos(_tooltipWindow, HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);

            _ti = new TOOLINFO();
            _ti.cbSize = Marshal.SizeOf(_ti);
            _ti.uFlags = (int)ToolTipFlags.TTF_SUBCLASS;
            _ti.hwnd = handle;
            // we need to set the rect field, otherwise TTM_POPUP doesn't do anything
            _ti.rect = new RECT() { top = 0, left = 0, bottom = int.MaxValue, right = int.MaxValue };

            // copy the TOOLINFO struct into unmanaged memory (remember to free the memory when exiting the application)
            _pti = Marshal.AllocHGlobal(Marshal.SizeOf(_ti));

            Marshal.StructureToPtr(_ti, _pti, false);

            SendToolTipMessage(ToolTipMessages.TTM_ADDTOOLW, IntPtr.Zero, _pti);

            // effectively disable the maximum width bound - line breaking can behave oddly otherwise
            SendToolTipMessage(ToolTipMessages.TTM_SETMAXTIPWIDTH, IntPtr.Zero, new IntPtr(short.MaxValue));

            added = true;
        }
예제 #10
0
        internal static void UpdateTipText(IntPtr _wndTooltip, TOOLINFO _ti)
        {
            const int TTM_UPDATETIPTEXT = WM_USER + 57;

            SendToolInfoMessage(_wndTooltip, TTM_UPDATETIPTEXT, 0, _ti);
        }
예제 #11
0
        private void tipChangeStyle(IntPtr handle, int Style, int StyleNot)
        {
            string sC = String.Empty;

            if (!_aHandles.Contains(handle))
            {
                TOOLINFO tI = new TOOLINFO(0);
                tI.hwnd = Handle;
                tI.uId = Handle;
                // get the tip data
                SendMessage(_hTipWnd, TTM_GETTOOLINFO, 0, ref tI);
                sC = (string)_dCaption[handle];
                // remove old
                RemoveTip(handle);
                // change the flags
                tI.uFlags = ((tI.uFlags & ~StyleNot) | Style);
                IntPtr pS = Marshal.StringToHGlobalAuto(sC);
                tI.lpszText = pS;
                // add the tip
                SendMessage(_hTipWnd, TTM_ADDTOOL, 0, ref tI);
                SendMessage(_hTipWnd, TTM_ACTIVATE, 1, 0);
                Marshal.FreeHGlobal(pS);
            }
        }
예제 #12
0
 private extern static int SendMessage(IntPtr hWnd, int msg, int wParam, ref TOOLINFO lParam);
예제 #13
0
 public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TOOLINFO lParam);
예제 #14
0
 /// <summary>
 /// Update the ToolTip text.
 /// </summary>
 /// <param name="Handle">IntPtr control handle</param>
 /// <param name="Caption">string caption</param>
 public void ToolUpdateText(IntPtr Handle, string Caption)
 {
     if (!_aHandles.Contains(Handle))
     {
         TOOLINFO tI = new TOOLINFO(0);
         tI.uId = Handle;
         tI.hinst = _hInstance;
         tI.hwnd = Handle;
         IntPtr pS = Marshal.StringToHGlobalAuto(Caption);
         SendMessage(_hTipWnd, TTM_UPDATETIPTEXT, 0, ref tI);
         Marshal.FreeHGlobal(pS);
     }
 }
예제 #15
0
 public static extern IntPtr SendMessage(HWND hWnd, EditMessage Msg, int wParam, ref TOOLINFO toolInfo);
예제 #16
0
 public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, TOOLINFO lParam);
예제 #17
0
 public static extern IntPtr SendMessageTOOLINFO(IntPtr hWnd, int Msg, int wParam, TOOLINFO lParam);
예제 #18
0
        public void SetToolTip(Control parent, string tipText)
        {
            try
            {
                //System.Diagnostics.Debug.Assert(parent.Handle!=IntPtr.Zero, "parent hwnd is null", "SetToolTip");
                m_displayText = tipText;
                CreateParams cp = new CreateParams();
                cp.ClassName = TOOLTIPS_CLASS;
                cp.Style     = WS_POPUP | TTS_BALLOON | TTS_NOPREFIX | TTS_ALWAYSTIP;

                cp.Parent = parent.Handle;

                // create the tool
                try
                {
                    m_tool.CreateHandle(cp);
                }
                catch (Exception ee)
                {
                    //Console.WriteLine(ee.ToString());
                }

                // make sure we make it the top level window
                SetWindowPos(
                    m_tool.Handle,
                    HWND_TOPMOST,
                    0, 0, 0, 0,
                    SWP_NOACTIVATE |
                    SWP_NOMOVE |
                    SWP_NOSIZE);

                // create and fill in the tool tip info
                TOOLINFO ti = new TOOLINFO();
                ti.cbSize   = Marshal.SizeOf(ti);
                ti.uFlags   = TTF_TRANSPARENT | TTF_SUBCLASS;
                ti.hwnd     = parent.Handle;
                ti.lpszText = m_displayText;

                // get the display co-ordinates
                GetClientRect(parent.Handle, ref ti.rect);

                // add the tool tip
                IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));
                Marshal.StructureToPtr(ti, ptrStruct, true);


                SendMessage(
                    m_tool.Handle,
                    TTM_ADDTOOL,
                    0,
                    ptrStruct);

                ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct, typeof(TOOLINFO));

                Marshal.FreeHGlobal(ptrStruct);

                SendMessage(
                    m_tool.Handle,
                    TTM_SETMAXTIPWIDTH,
                    0,
                    new IntPtr(m_maxWidth));


                if (m_title != null || m_title != string.Empty)
                {
                    IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);

                    SendMessage(
                        m_tool.Handle, TTM_SETTITLE,
                        (int)m_titleIcon, ptrTitle);

                    Marshal.FreeHGlobal(ptrTitle);
                }
            }
            catch (Exception ee)
            {
                //Console.WriteLine(ee.ToString());
            }
        }
예제 #19
0
 internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TOOLINFO ti);
예제 #20
0
 /// <summary>
 /// Binds the ToolTip window with the specified control.
 /// </summary>
 /// <param name="control">IntPtr Handle</param>
 /// <param name="Caption">string Caption</param>
 public void SetToolTip(IntPtr Handle, string Caption)
 {
     if (!_aHandles.Contains(Handle))
     {
         _aHandles.Add(Handle);
         _dCaption.Add(Handle, Caption);
         // create the tip default params
         TOOLINFO tI = new TOOLINFO(TTF_IDISHWND | TTF_SUBCLASS | TTF_PARSELINKS | TTF_TRANSPARENT |
             (_bRightToLeft ? TTF_RTLREADING : 0) |
             (_bCenterTip ? TTF_CENTERTIP : 0));
         tI.hwnd = Handle;
         tI.uId = Handle;
         tI.hinst = _hInstance;
         IntPtr pS = Marshal.StringToHGlobalAuto(Caption);
         tI.lpszText = pS;
         GetClientRect(Handle, ref tI.rect);
         SendMessage(_hTipWnd, TTM_ADDTOOL, 0, ref tI);
         SendMessage(_hTipWnd, TTM_ACTIVATE, 1, 0);
         Marshal.FreeHGlobal(pS);
     }
 }
예제 #21
0
            private void CreateTool()
            {
                System.Diagnostics.Debug.Assert(
                    mToolP.Handle != IntPtr.Zero,
                    "parent hwnd is null", "SetToolTip");

                CreateParams cp = new CreateParams();

                cp.ClassName = TOOLTIPS_CLASS;
                cp.Style     =
                    WS_POPUP |
                    TTS_BALLOON |
                    TTS_NOPREFIX |
                    TTS_ALWAYSTIP |
                    TTS_CLOSE;

                mTool.CreateHandle(cp);

                ti        = new TOOLINFO();
                ti.cbSize = Marshal.SizeOf(ti);

                ti.uFlags = TTF_TRACK |
                            TTF_IDISHWND |
                            TTF_TRANSPARENT |
                            TTF_SUBCLASS |
                            TTF_PARSELINKS;

                if (tipmPos)
                {
                    ti.uFlags |= TTF_ABSOLUTE;
                }


                if (tipmCen)
                {
                    ti.uFlags |= TTF_CENTERTIP;
                }


                ti.uId      = mTool.Handle;
                ti.lpszText = tipmText;
                ti.hwnd     = mToolP.Handle;

                GetClientRect(mToolP.Handle, ref ti.rect);
                ClientToScreen(mToolP.Handle, ref ti.rect);

                SetWindowPos(
                    mTool.Handle,
                    HWND_TOPMOST,
                    0, 0, 0, 0,
                    SWP_NOACTIVATE |
                    SWP_NOMOVE |
                    SWP_NOSIZE);

                IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));

                Marshal.StructureToPtr(ti, ptrStruct, true);

                SendMessage(
                    mTool.Handle, TTM_ADDTOOL, 0, ptrStruct);

                ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct,
                                                      typeof(TOOLINFO));

                SendMessage(
                    mTool.Handle, TTM_SETMAXTIPWIDTH,
                    0, new IntPtr(mtoolMax));

                IntPtr ptrTitle = Marshal.StringToHGlobalAuto(tipmTitle);

                SendMessage(
                    mTool.Handle, TTM_SETTITLE,
                    (int)tipmTI, ptrTitle);

                SetPos(ti.rect);

                Marshal.FreeHGlobal(ptrStruct);
                Marshal.FreeHGlobal(ptrTitle);
            }
예제 #22
0
 /// <summary>
 /// Global: Binds the ToolTip window with the specified control. Tooltip is only activated
 /// within the specified rectangle.
 /// </summary>
 /// <param name="control">Control control</param>
 /// <param name="Caption">string caption</param>
 /// <param name="Bounds">Rectangle bounds</param>
 public void SetToolTipByRect(IntPtr Handle, string Caption, Rectangle Bounds)
 {
     if (!_aHandles.Contains(Handle))
     {
         _aHandles.Add(Handle);
         _dCaption.Add(Handle, Caption);
     }
     if (_eCustomStyle == TipStyle.Default)
     {
         // create the tip default params
         TOOLINFO tI = new TOOLINFO(TTF_SUBCLASS | TTF_PARSELINKS | TTF_ABSOLUTE |
             (_bRightToLeft ? TTF_RTLREADING : 0) |
             (_bCenterTip ? TTF_CENTERTIP : 0));
         tI.hwnd = Handle;
         tI.uId = Handle;
         tI.hinst = _hInstance;
         IntPtr pS = Marshal.StringToHGlobalAuto(Caption);
         tI.lpszText = pS;
         tI.rect = new RECT(Bounds.X, Bounds.Y, Bounds.Right, Bounds.Bottom);
         SendMessage(_hTipWnd, TTM_ADDTOOL, 0, ref tI);
         SendMessage(_hTipWnd, TTM_ACTIVATE, 1, 0);
         Marshal.FreeHGlobal(pS);
     }
     else
     {
         throw new Exception("This method option is only avaliable in the Default style mode.");
     }
 }
예제 #23
0
파일: BalloonTip.cs 프로젝트: uvbs/Holodeck
        public void SetToolTip(Control parent, string tipText)
        {
            System.Diagnostics.Debug.Assert(parent.Handle!=IntPtr.Zero, "parent hwnd is null", "SetToolTip");

            m_displayText = tipText;

            CreateParams cp = new CreateParams();
            cp.ClassName = TOOLTIPS_CLASS;
            cp.Style = WS_POPUP | TTS_BALLOON | TTS_NOPREFIX |	TTS_ALWAYSTIP;

            cp.Parent = parent.Handle;

            // create the tool
            m_tool.CreateHandle(cp);

            // make sure we make it the top level window
            SetWindowPos(
                m_tool.Handle,
                HWND_TOPMOST,
                0, 0, 0, 0,
                SWP_NOACTIVATE |
                SWP_NOMOVE |
                SWP_NOSIZE);

            // create and fill in the tool tip info
            TOOLINFO ti = new TOOLINFO();
            ti.cbSize = Marshal.SizeOf(ti);
            ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS;
            ti.hwnd = parent.Handle;
            ti.lpszText = m_displayText;

            // get the display co-ordinates
            GetClientRect(parent.Handle, ref ti.rect);

            // add the tool tip
            IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));
            Marshal.StructureToPtr(ti, ptrStruct, true);

            SendMessage(
                m_tool.Handle,
                TTM_ADDTOOL,
                0,
                ptrStruct);

            ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct, typeof(TOOLINFO));

            Marshal.FreeHGlobal(ptrStruct);

            SendMessage(
                m_tool.Handle,
                TTM_SETMAXTIPWIDTH,
                0,
                new IntPtr(m_maxWidth));

            if(m_title != null || m_title!=string.Empty)
            {
                IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);

                SendMessage(
                    m_tool.Handle, TTM_SETTITLE,
                    (int)m_titleIcon, ptrTitle);

                Marshal.FreeHGlobal(ptrTitle);
            }
        }
예제 #24
0
        private DrawEventArgs getEventParams()
        {
            DrawEventArgs dR = new DrawEventArgs();
            TOOLINFO tI = new TOOLINFO(0);
            RECT tR = new RECT();
            string sT = String.Empty;
            string sC = String.Empty;

            GetWindowRect(_hTipWnd, ref tR);
            dR.Bounds = new Rectangle(0, 0, tR.Right - tR.Left, tR.Bottom - tR.Top);
            dR.Position = new Point(tR.Left, tR.Top);

            tI.uId = _hTipWnd;
            SendMessage(_hTipWnd, TTM_GETCURRENTTOOL, 0, ref tI);
            dR.ParentWnd = _hParentWnd;
            if (tI.hwnd != IntPtr.Zero)
            {
                if (_dTitle.ContainsKey(tI.hwnd))
                {
                    sT = (string)_dTitle[tI.hwnd];
                }
                if (_dCaption.ContainsKey(tI.hwnd))
                {
                    sC = (string)_dCaption[tI.hwnd];
                }
            }
            dR.Caption = sC;
            dR.Title = sT;
            dR.Hdc = IntPtr.Zero;
            return dR;
        }
예제 #25
0
        private void CreateTool()
        {
            System.Diagnostics.Debug.Assert(
                m_parent.Handle != IntPtr.Zero,
                "parent hwnd is null", "SetToolTip");

            CreateParams cp = new CreateParams();
            cp.ClassName = TOOLTIPS_CLASS;
            cp.Style =
                WS_POPUP |
                TTS_BALLOON |
                TTS_NOPREFIX |
                TTS_ALWAYSTIP |
                TTS_CLOSE;

            // create the tool
            m_tool.CreateHandle(cp);

            // create and fill in the tool tip info
            m_ti = new TOOLINFO();
            m_ti.cbSize = Marshal.SizeOf(m_ti);

            m_ti.uFlags = TTF_TRACK |
                TTF_IDISHWND |
                TTF_TRANSPARENT |
                TTF_SUBCLASS |
                TTF_PARSELINKS;

            // absolute is used tooltip maynot be shown
            // if coords exceed the corners of the screen
            if (m_absPosn)
            {
                m_ti.uFlags |= TTF_ABSOLUTE;
            }

            if (m_centerStem)
            {
                m_ti.uFlags |= TTF_CENTERTIP;
            }

            m_ti.uId = m_tool.Handle;
            m_ti.lpszText = m_text;
            m_ti.hwnd = m_parent.Handle;

            GetClientRect(m_parent.Handle, ref m_ti.rect);
            ClientToScreen(m_parent.Handle, ref m_ti.rect);

            // make sure we make it the top level window
            SetWindowPos(
                m_tool.Handle,
                HWND_TOPMOST,
                0, 0, 0, 0,
                SWP_NOACTIVATE |
                SWP_NOMOVE |
                SWP_NOSIZE);

            // add the tool tip
            IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(m_ti));  //  + 100
            Marshal.StructureToPtr(m_ti, ptrStruct, false);

            SendMessage(
                m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct);

            m_ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct,
                typeof(TOOLINFO));

            SendMessage(
                m_tool.Handle, TTM_SETMAXTIPWIDTH,
                0, new IntPtr(m_maxWidth));

            IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);

            SendMessage(
                m_tool.Handle, TTM_SETTITLE,
                (int)m_titleIcon, ptrTitle);

            SetBalloonPosition(m_ti.rect);

            Marshal.FreeHGlobal(ptrStruct);
            Marshal.FreeHGlobal(ptrTitle);
        }
예제 #26
0
        /// <summary>
        /// message pump
        /// </summary>
        /// <param name="m">message struct</param>
        protected override void WndProc(ref Message m)
        {
            TOOLINFO tI = new TOOLINFO(0);
            RECT tR = new RECT();
            Size sZ = new Size();
            Point pT = new Point();
            DrawEventArgs dR;

            switch (m.Msg)
            {
                // window painting
                case WM_PAINT:
                    PAINTSTRUCT tPaint = new PAINTSTRUCT();
                    string sT = String.Empty;
                    string sC = String.Empty;
                    if (_eCustomStyle != TipStyle.Default)
                    {
                        if (!_bPainting)
                        {
                            _bPainting = true;
                            // start painting engine
                            BeginPaint(m.HWnd, ref tPaint);
                            dR = getEventParams();
                            if (Draw != null)
                            {
                                dR.Hdc = tPaint.hdc;
                                Draw(this, dR);
                            }
                            else
                            {
                                drawTip(dR.Bounds, dR.Caption, dR.Title, tPaint.hdc, dR.ParentWnd);
                            }
                            // done
                            EndPaint(m.HWnd, ref tPaint);
                            _bPainting = false;
                        }
                        else
                        {
                            base.DefWndProc(ref m);
                        }
                    }
                    else
                    {
                        // call the old proc
                        base.WndProc(ref m);
                    }
                    break;

                case (WM_NOTIFY | WM_REFLECT):
                    NMHDR nM = new NMHDR(0);
                    RtlMoveMemory(ref nM, m.LParam, Marshal.SizeOf(nM));
                    if (nM.hwndFrom == _hTipWnd)
                    {
                        switch (nM.code)
                        {
                            //case TTN_GETDISPINFOA: <- not working
                            //case TTN_GETDISPINFOW:
                            //    break;
                            case TTN_SHOW:
                                Point tp = new Point();
                                SendMessage(_hTipWnd, TTM_GETCURRENTTOOL, 0, ref tI);
                                _hParentWnd = tI.hwnd;
                                //// SIZE ////
                                // tip size set globally
                                if ((_oSize.Width != 0) || (_oSize.Height != 0))
                                {
                                    tR.Left = 0;
                                    tR.Top = 0;
                                    tR.Bottom = _oSize.Height;
                                    tR.Right = _oSize.Width;
                                    SendMessage(_hTipWnd, TTM_ADJUSTRECT, 1, ref tR);
                                    SetWindowPos(_hTipWnd,
                                                HWND_TOP,
                                                0, 0,
                                                tR.Right, tR.Bottom,
                                                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                    m.Result = RETURN_TRUE;
                                }
                                else
                                {
                                    // tip size set individually
                                    tI.uId = _hTipWnd;
                                    // get tool parent
                                    SendMessage(_hTipWnd, TTM_GETCURRENTTOOL, 0, ref tI);
                                    if (tI.hwnd != IntPtr.Zero)
                                    {
                                        // test the dictionary
                                        if (_dSize.ContainsKey(tI.hwnd))
                                        {
                                            sZ = _dSize[tI.hwnd];
                                            // size tip
                                            if ((sZ.Width != 0) || (sZ.Height != 0))
                                            {
                                                tR.Left = 0;
                                                tR.Top = 0;
                                                tR.Bottom = sZ.Height;
                                                tR.Right = sZ.Width;
                                                SendMessage(_hTipWnd, TTM_ADJUSTRECT, 1, ref tR);
                                                SetWindowPos(_hTipWnd,
                                                            HWND_TOP,
                                                            0, 0,
                                                            tR.Right, tR.Bottom,
                                                            SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                                m.Result = RETURN_TRUE;
                                            }
                                        }
                                        // calculate size
                                        else if (_eCustomStyle != TipStyle.Default)
                                        {
                                            StringFormat sF = new StringFormat();
                                            sF.Alignment = StringAlignment.Near;
                                            sF.LineAlignment = StringAlignment.Near;
                                            Rectangle rDmn = new Rectangle(4, sZ.Height, (tR.Right - tR.Left), (tR.Bottom - tR.Top));
                                            calcTipSize(ref rDmn, tI.hwnd, _oTipFont, _dCaption[tI.hwnd], sF);
                                            sF.Dispose();
                                            SetWindowPos(_hTipWnd,
                                                        HWND_TOP,
                                                        0, 0,
                                                        rDmn.Width + 8, rDmn.Height + sZ.Height + 8,
                                                        SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                            m.Result = RETURN_TRUE;
                                        }
                                    }
                                }
                                //// POSITION ////
                                if (_ePosition != TipPosition.AutoPosition)
                                {
                                    if (tI.hwnd != IntPtr.Zero)
                                    {
                                        GetCursorPos(ref tp);
                                        GetWindowRect(_hTipWnd, ref tR);
                                        // offset for global size
                                        if ((_oSize.Width != 0) || (_oSize.Height != 0))
                                        {
                                            tR.Bottom = tR.Top + _oSize.Height;
                                            tR.Right = tR.Left + _oSize.Width;
                                        }
                                        // offset for tp size mod
                                        else if (_dSize.ContainsKey(tI.hwnd))
                                        {
                                            sZ = _dSize[tI.hwnd];
                                            tR.Bottom = tR.Top + sZ.Height;
                                            tR.Right = tR.Left + sZ.Width;
                                        }
                                        int iX = 0;
                                        int iY = 0;
                                        if ((_bShowAlways) || (_bClickable))
                                        {
                                            iX = 12;
                                            iY = 12;
                                        }
                                        else
                                        {
                                            iX = 20;
                                            iY = 20;
                                        }
                                        switch (_ePosition)
                                        {
                                            case TipPosition.BottomCenter:
                                                tp.Y += iX;
                                                tp.X -= ((tR.Right - tR.Left) / 2);
                                                break;
                                            case TipPosition.BottomLeft:
                                                tp.Y += iX;
                                                tp.X -= ((tR.Right - tR.Left) - 4);
                                                break;
                                            case TipPosition.BottomRight:
                                                tp.Y += iX;
                                                tp.X += 12;
                                                break;
                                            case TipPosition.LeftCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) / 2);
                                                tp.X -= ((tR.Right - tR.Left) + 4);
                                                break;
                                            case TipPosition.RightCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) / 2);
                                                tp.X += 20;
                                                break;
                                            case TipPosition.TopCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                tp.X -= ((tR.Right - tR.Left) / 2);
                                                break;
                                            case TipPosition.TopLeft:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                tp.X -= ((tR.Right - tR.Left) + 4);
                                                break;
                                            case TipPosition.TopRight:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                break;
                                        }
                                        SetWindowPos(_hTipWnd,
                                                    HWND_TOP,
                                                    tp.X, tp.Y,
                                                    0, 0,
                                                    SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                    }
                                    m.Result = RETURN_TRUE;
                                }
                                if (PopUp != null) PopUp();
                                tipCapture();
                                break;

                            case TTN_POP:
                                if (Pop != null) Pop();
                                //base.WndProc(ref m);
                                break;

                            //case NM_CUSTOMDRAW:
                            //NMTTCUSTOMDRAW nC = new NMTTCUSTOMDRAW(); //<- can't get this to work..
                            //RtlMoveMemory(ref nC, m.LParam, Marshal.SizeOf(nC));
                            //    break;
                            default:
                                base.WndProc(ref m);
                                break;
                        }
                    }
                    break;

                // mouse events
                case WM_MOUSEMOVE:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MouseMove != null)
                        {
                            GetCursorPos(ref pT);
                            MouseMove(pT);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                        trackMouse(m.HWnd);
                    }
                    if ((!_bShowAlways) && (!_bClickable))
                        base.WndProc(ref m);
                    break;
                case WM_MOUSELEAVE:
                    if ((_bShowAlways) || (_bClickable))
                    {
                        if (IsVisible())
                        {
                            Hide();
                        }
                    }
                    base.WndProc(ref m);
                    break;
                case WM_LBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_LBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonUp(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bCloseButton)
                        {
                            if (closeButtonHitTest())
                            {
                                Hide();
                            }
                            else
                            {
                                base.WndProc(ref m);
                            }
                        }
                        else if (_bClickable)
                        {
                            m.Result = RETURN_TRUE;
                        }
                        else
                        {
                            base.WndProc(ref m);
                        }
                    }
                    break;
                case WM_LBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonDblClick != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonUp(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonDblClick != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MOUSEWHEEL:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MouseWheel != null)
                        {
                            MouseWheel();
                        }
                    }
                    break;

                case WM_TIMER:
                    switch (m.WParam.ToInt32())
                    {
                        case HOVER_SIGNALED:
                            if (IsVisible())
                            {
                                if ((_bShowAlways) || (_bClickable))
                                {
                                    GetWindowRect(_hTipWnd, ref tR);
                                    GetCursorPos(ref pT);
                                    if (PtInRect(ref tR, pT))
                                        m.Result = RETURN_TRUE;
                                    else
                                        base.WndProc(ref m);
                                }
                                else
                                {
                                    base.WndProc(ref m);
                                }
                            }
                            else
                            {
                                base.WndProc(ref m);
                            }
                            break;
                        case FADER_SIGNALED: //<-vista only
                            if (IsVisible())
                            {
                                if ((_bShowAlways) || (_bClickable))
                                {
                                    GetWindowRect(_hTipWnd, ref tR);
                                    GetCursorPos(ref pT);
                                    if (PtInRect(ref tR, pT))
                                        m.Result = RETURN_TRUE;
                                    else
                                        base.WndProc(ref m);
                                }
                                else if (_eCustomStyle != TipStyle.Default)
                                {
                                    if (!_bTimerActive)
                                    {
                                        startFadeTimer();
                                        m.Result = RETURN_TRUE;
                                    }
                                    else
                                    {
                                        m.Result = RETURN_TRUE;
                                    }
                                }
                                else
                                {
                                    base.WndProc(ref m);
                                }
                            }
                            break;
                        case TIMER_FADE:
                            _iSafeTimer += 1;
                            if (_iSafeTimer > (_iFadeDelay / 50))
                                stopFadeTimer();
                            else
                                tipFade();
                            break;
                        default:
                            base.WndProc(ref m);
                            break;
                    }
                    break;

                case WM_SETFOCUS:
                    if (!_bCanFocus)
                    {
                        if (_hParentWnd != IntPtr.Zero)
                            SetFocus(_hParentWnd);
                        if (_bClickable)
                        {
                            if (closeButtonHitTest())
                                SendMessage(_hTipWnd, WM_LBUTTONUP, 0, 0);
                        }
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_STYLECHANGED:
                    if (_eCustomStyle == TipStyle.Default)
                        SendMessage(_hTipWnd, TTM_SETTIPBKCOLOR, ColorTranslator.ToWin32(Color.LightYellow), 0); //<-added for xp
                    base.WndProc(ref m);
                    break;

                /*case WM_NCPAINT:
                    break;
                case WM_DESTROY:
                    break;
                case WM_ACTIVATEAPP:
                    break;
                 case WM_ACTIVATE:
                    break;
                case WM_KILLFOCUS:
                    break;
                 case WM_IME_NOTIFY:
                    break;
                 case WM_IME_SETCONTEXT:
                    break;
                 case WM_NCACTIVATE:
                    break;
                case WM_STYLECHANGING:
                    break;
                case WM_WINDOWPOSCHANGING:
                    break;
                case WM_WINDOWPOSCHANGED:
                    break;
                case WM_NCCALCSIZE:
                    break;
                // undocumented?
                case 0x410: // effects show/timer
                    break;
                case 0x418: // format
                    break;
                case 0x421: // title
                    break;
                case 0x407: //show/timer
                    break;*/

                default:
                    //Debug.Print(m.Msg.ToString());
                    base.WndProc(ref m);
                    break;
            }
        }
예제 #27
0
 /// <summary>
 /// Sends the specified message to a window or windows. The SendMessage function calls the window procedure for the specified window and does not return until the window procedure has processed the message.
 /// </summary>
 /// <param name="hWnd">A handle to the window whose window procedure will receive the message. If this parameter is HWND_BROADCAST ((HWND)0xffff), the message is sent to all top-level windows in the system, including disabled or invisible unowned windows, overlapped windows, and pop-up windows; but the message is not sent to child windows.</param>
 /// <param name="Msg">The message to be sent.</param>
 /// <param name="wParam">Additional message-specific information.</param>
 /// <param name="toolInfo">Additional message-specific information.</param>
 /// <returns>The return value specifies the result of the message processing; it depends on the message sent.</returns>
 public static IntPtr SendMessage(HandleRef hWnd, EditMessage Msg, int wParam, ref TOOLINFO toolInfo) => User32_Gdi.SendMessage(hWnd, Msg, wParam, ref toolInfo);
예제 #28
0
        private void CreateTool()
        {
            System.Diagnostics.Debug.Assert(
                m_parent.Handle != IntPtr.Zero,
                "parent hwnd is null", "SetToolTip");

            CreateParams cp = new CreateParams();

            cp.ClassName = TOOLTIPS_CLASS;
            cp.Style     =
                WS_POPUP |
                TTS_BALLOON |
                TTS_NOPREFIX |
                TTS_ALWAYSTIP |
                TTS_CLOSE;

            // create the tool
            m_tool.CreateHandle(cp);

            // create and fill in the tool tip info
            m_ti        = new TOOLINFO();
            m_ti.cbSize = Marshal.SizeOf(m_ti);

            m_ti.uFlags = TTF_TRACK |
                          TTF_IDISHWND |
                          TTF_TRANSPARENT |
                          TTF_SUBCLASS |
                          TTF_PARSELINKS;

            // absolute is used tooltip maynot be shown
            // if coords exceed the corners of the screen
            if (m_absPosn)
            {
                m_ti.uFlags |= TTF_ABSOLUTE;
            }

            if (m_centerStem)
            {
                m_ti.uFlags |= TTF_CENTERTIP;
            }

            m_ti.uId      = m_tool.Handle;
            m_ti.lpszText = m_text;
            m_ti.hwnd     = m_parent.Handle;

            GetClientRect(m_parent.Handle, ref m_ti.rect);
            ClientToScreen(m_parent.Handle, ref m_ti.rect);

            // make sure we make it the top level window
            SetWindowPos(
                m_tool.Handle,
                HWND_TOPMOST,
                0, 0, 0, 0,
                SWP_NOACTIVATE |
                SWP_NOMOVE |
                SWP_NOSIZE);

            // add the tool tip
            IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(m_ti));  //  + 100

            Marshal.StructureToPtr(m_ti, ptrStruct, false);

            SendMessage(
                m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct);

            m_ti = (TOOLINFO)Marshal.PtrToStructure(ptrStruct,
                                                    typeof(TOOLINFO));

            SendMessage(
                m_tool.Handle, TTM_SETMAXTIPWIDTH,
                0, new IntPtr(m_maxWidth));

            IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);

            SendMessage(
                m_tool.Handle, TTM_SETTITLE,
                (int)m_titleIcon, ptrTitle);

            SetBalloonPosition(m_ti.rect);

            Marshal.FreeHGlobal(ptrStruct);
            Marshal.FreeHGlobal(ptrTitle);
        }
예제 #29
0
 internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref TOOLINFO info);
예제 #30
0
 public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, TOOLINFO lParam);
예제 #31
0
 internal static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, ref TOOLINFO info);
예제 #32
0
 public extern static int SendMessage(
     IntPtr hWnd, int msg, int wParam, ref TOOLINFO lParam);
예제 #33
0
        public void Show(string title, string text, Control control, ToolTipIcon icon, double showTime, int x = 0, int y = 0)
        {
            balloons.Add(this);
            if (x == 0 && y == 0)
            {
                x = (control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
                y = (control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
            }

            TOOLINFO toolInfo = new TOOLINFO();

            toolInfo.cbSize   = (uint)Marshal.SizeOf(toolInfo);
            toolInfo.uFlags   = 0x20; // TTF_TRACK
            toolInfo.lpszText = text;
            IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));

            Marshal.StructureToPtr(toolInfo, pToolInfo, false);
            byte[] buffer = Encoding.Default.GetBytes(title);
            buffer = buffer.Concat(new byte[] { 0 }).ToArray();
            IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);

            Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
            hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
            User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo);               // TTM_ADDTOOL
            User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)(x | (y << 16))); // TTM_TRACKPOSITION
            User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle);             // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
            User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500);             // TTM_SETMAXTIPWIDTH
            User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo);              // TTM_UPDATETIPTEXT; 0x439 for Unicode
            User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo);               // TTM_TRACKACTIVATE
            Marshal.FreeCoTaskMem(pszTitle);
            Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
            Marshal.FreeCoTaskMem(pToolInfo);


            control.Enter           += control_Event;
            control.Leave           += control_Event;
            control.TextChanged     += control_Event;
            control.KeyPress        += control_Event;
            control.Click           += control_Event;
            control.LocationChanged += control_Event;
            control.SizeChanged     += control_Event;
            control.VisibleChanged  += control_Event;
            if (control is DataGridView)
            {
                ((DataGridView)control).CellBeginEdit += control_Event;
            }
            Control parent = control.Parent;

            while (parent != null)
            {
                parent.VisibleChanged += control_Event;
                parent = parent.Parent;
            }
            control.TopLevelControl.LocationChanged    += control_Event;
            ((Form)control.TopLevelControl).Deactivate += control_Event;
            timer.AutoReset = false;
            timer.Elapsed  += timer_Elapsed;
            if (showTime > 0)
            {
                timer.Interval = showTime;
                timer.Start();
            }
        }
예제 #34
0
        /// <summary>
        /// Send a message that wants LPTOOLINFO as the lParam
        /// </summary>
        /// <param name="_wndTooltip">HWND of the tooltip.</param>
        /// <param name="_msg">window message to send</param>
        /// <param name="_wParam">wParam value</param>
        /// <param name="_ti">TOOLINFO structure that goes to the lParam field. The cbSize field must be set.</param>
        internal static int SendToolInfoMessage(IntPtr _wndTooltip, int _msg, int _wParam, TOOLINFO _ti)
        {
            var tempptr = IntPtr.Zero;

            try
            {
                tempptr = Marshal.AllocHGlobal(_ti.cbSize);
                Marshal.StructureToPtr(_ti, tempptr, false);

                return(SendMessage(_wndTooltip, _msg, _wParam, tempptr));
            }
            finally
            {
                if (IntPtr.Zero != tempptr)
                {
                    Marshal.FreeHGlobal(tempptr);
                    tempptr = IntPtr.Zero;
                }
            }
        }
예제 #35
0
 internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TOOLINFO ti);
예제 #36
0
        /// <summary>
        /// Registers a tool with a ToolTip control
        /// </summary>
        /// <param name="_wndTooltip">HWND of the tooltip</param>
        /// <param name="_ti">TOOLINFO structure containing information that the ToolTip control needs to display text for the tool.</param>
        internal static void DelTool(IntPtr _wndTooltip, TOOLINFO _ti)
        {
            const int TTM_DELTOOL = WM_USER + 51;

            SendToolInfoMessage(_wndTooltip, TTM_DELTOOL, 0, _ti);
        }
예제 #37
0
 /// <summary>
 /// Remove the ToolTip associated with the specified control window handle.
 /// </summary>
 public void RemoveTip(IntPtr Handle)
 {
     TOOLINFO tI = new TOOLINFO(0);
     if (_aHandles.Contains(Handle))
     {
         tI.hwnd = Handle;
         tI.uId = Handle;
         SendMessage(_hTipWnd, TTM_SETTITLE, IntPtr.Zero, "");
         SendMessage(_hTipWnd, TTM_DELTOOL, 0, ref tI);
         if (_dCaption.ContainsKey(Handle))
             _dCaption.Remove(Handle);
         if (_dSize.ContainsKey(Handle))
             _dSize.Remove(Handle);
         if (_oIcons.Images.ContainsKey(Handle.ToString()))
             _oIcons.Images.RemoveByKey(Handle.ToString());
         _aHandles.RemoveAt(_aHandles.IndexOf(Handle));
     }
 }
예제 #38
0
        /// <summary>
        /// Activates or deactivates a tracking ToolTip
        /// </summary>
        /// <param name="_wndTooltip">HWND of the tooltip</param>
        /// <param name="bActivate">Value specifying whether tracking is being activated or deactivated</param>
        /// <param name="_ti">Pointer to a TOOLINFO structure that identifies the tool to which this message applies</param>
        internal static void TrackActivate(IntPtr _wndTooltip, bool bActivate, TOOLINFO _ti)
        {
            const int TTM_TRACKACTIVATE = WM_USER + 17;

            SendToolInfoMessage(_wndTooltip, TTM_TRACKACTIVATE, Convert.ToInt32(bActivate), _ti);
        }
예제 #39
0
        public void SetToolTip(Control parent, Rectangle rect, string tipText)
        {
            System.Diagnostics.Debug.Assert(parent!=null, "parent is null", "parent cant be null");
            m_text = tipText;

            CreateParams cp = new CreateParams();
            cp.ClassName = TOOLTIPS_CLASS;
            cp.Style = WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP;

            cp.Parent = parent.Handle;

            // create the tool
            m_tool.CreateHandle(cp);

            // adjust the rectangle
            Rectangle r = rect;
            IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(r));
            Marshal.StructureToPtr(r, p, true);
            SendMessage(m_tool.Handle, TTM_ADJUSTRECT, -1, p);
            r = (Rectangle)Marshal.PtrToStructure(p, typeof(Rectangle));
            Marshal.FreeHGlobal(p);

            // make sure we make it the top level window
            SetWindowPos(
                m_tool.Handle, HWND_TOPMOST, r.Left, r.Top, 0, 0,
                SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);

            // create and fill in the tool tip info
            TOOLINFO ti = new TOOLINFO();
            ti.cbSize = Marshal.SizeOf(ti);
            ti.uFlags = TTF_TRANSPARENT | TTF_SUBCLASS;

            ti.hwnd = parent.Handle;
            ti.lpszText = m_text;
            ti.rect = parent.ClientRectangle;

            // add the tool tip
            IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(ti));
            Marshal.StructureToPtr(ti, ptrStruct, true);

            SendMessage(m_tool.Handle, TTM_ADDTOOL, 0, ptrStruct);

            Marshal.FreeHGlobal(ptrStruct);

            SendMessage(m_tool.Handle, TTM_SETMAXTIPWIDTH,
                0, new IntPtr(m_maxWidth));

            //			IntPtr ptrTitle = Marshal.StringToHGlobalAuto(m_title);
            //
            //			WinDeclns.SendMessage(
            //				m_tool.Handle, TTDeclns.TTM_SETTITLE,
            //				(int)m_titleIcon, ptrTitle);
            //
            //			Marshal.FreeHGlobal(ptrTitle);
        }