zoukankan      html  css  js  c++  java
  • 编写DLLBalloon

    using System;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;

    namespace Balloon
    {
     //Defines a set of standardized icons that can be associated with a ToolTip
     public enum TooltipIcon : int
     {
      None,     //Not a standard icon.
      Info,    //An information icon.
      Warning,   //A warning icon.
      Error    //An error icon
     }
     
     public class XPBalloon
     {
      private Control _parent;

      private string _text = "Balloon Tooltip Control Display Message";
      private string _title = "Balloon Tooltip Message";
      private TooltipIcon _titleIcon = TooltipIcon.None;

      private const int ECM_FIRST = 0x1500;
      private const int EM_SHOWBALLOONTIP = ECM_FIRST + 3;

      [DllImport("User32",SetLastError=true)]
     
      /*SendMessage:它把一条消息发送给指定窗口的窗口过程,
      而且等待该窗口过程完成消息的处理之后才会返回。
      当需要知道某个消息的处理结果时,
      使用该函数发送消息,然后根据其返回值进行处理。
      */
      private static extern int SendMessage(IntPtr hWnd,int Msg,int wParam,IntPtr lParam);
     
      //StructLayoutAttribute 类使用户可以控制类或结构的数据字段的物理布局
      [StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
       private struct BALLOONTIP
       {
        public int cbStruct;
        public string pszTitle;
        public string pszText;
        public int ttiIcon;
       }

      public XPBalloon()
      {
      }

      public XPBalloon(Control parent)
      {
       _parent = parent;
      }

      ///


      /// Show a balloon tooltip for edit control.
      ///

      public void balloonShow()
      {
       BALLOONTIP balloonTip = new BALLOONTIP();
      
       /*
        *Marshal:提供了一个方法集,这些方法用于分配非托管内存、复制非托管内存块、
        *将托管类型转换为非托管类型,此外还提供了在与非托管代码交互时使用的其他杂项方法。
        */
       balloonTip.cbStruct = Marshal.SizeOf(balloonTip);
       balloonTip.pszText = _text;
       balloonTip.pszTitle = _title;
       balloonTip.ttiIcon = (int)_titleIcon;
      
       //IntPtr : 用于表示指针或句柄的平台特定类型。
       //AllocHGlobal : 使用 GlobalAlloc 从进程的非托管内存中分配内存。
       IntPtr ptrStruct = Marshal.AllocHGlobal(Marshal.SizeOf(balloonTip));
      
       //StructureToPtr:将数据从托管对象封送到非托管内存块。
       Marshal.StructureToPtr(balloonTip, ptrStruct, true);

       System.Diagnostics.Debug.Assert(_parent!=null, "Parent control is null", "Set parent before calling Show");

       int ret = SendMessage(_parent.Handle,EM_SHOWBALLOONTIP,0, ptrStruct);
      
       //FreeHGlobal : 释放以前使用 AllocHGlobal 从进程的非托管内存中分配的内存。
       Marshal.FreeHGlobal(ptrStruct);
      }

      ///


      /// Sets or gets the Title.
      ///

      public string balloonTitle
      {
       get
       {
        return _title;
       }
       set
       {
        _title = value;
       }
      }

      ///


      /// Sets or gets the display icon.
      ///

      public TooltipIcon balloonTitleIcon
      {
       get
       {
        return _titleIcon;
       }
       set
       {
        _titleIcon = value;
       }
      }

      ///


      /// Sets or gets the display text.
      ///

      public string balloonText
      {
       get
       {
        return _text;
       }
       set
       {
        _text = value;
       }
      }

      ///


      /// Sets or gets the parent.
      ///

      public Control balloonParent
      {
       get
       {
        return _parent;
       }
       set
       {
        _parent = value;
       }
      }

     }
    }


    2005年10月31日20:17:41

  • 相关阅读:
    糍粑大叔的独游之旅-战斗!之弹道实现
    攻击判定流程研究: 瀑布算法、圆桌算法、混合算法解析
    GitHub排名TOP30的机器学习开源项目/贪心学院
    学习ES7+ES8
    k8s Ipvs 内部网络自动分配和内部网络一致ip地址,导致ip冲突
    Linux操作系统load average过高,kworker占用较多cpu
    chrome断点调试&&其他技巧
    Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
    记一次线上Java程序导致服务器CPU占用率过高的问题排除过程
    解决并发问题,数据库常用的两把锁(转)
  • 原文地址:https://www.cnblogs.com/RuiLei/p/265770.html
Copyright © 2011-2022 走看看