• Api代码收集


    收集自网络,方便自己,方便他人 

     1     #region 隐藏系统滚动条
     2     protected override void WndProc(ref System.Windows.Forms.Message m)
     3     {
     4       ShowScrollBar(this.Handle, 3, false);//0:horizontal,1:vertical,3:both
     5       base.WndProc(ref m);
     6     }
     7 
     8     [DllImport("user32.dll")]
     9     [return: MarshalAs(UnmanagedType.Bool)]
    10     private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow);
    11     #endregion
     1     #region 得到光标在屏幕上的位置
     2    [DllImport("user32")]
     3     public static extern bool GetCaretPos(out Point lpPoint);
     4     [DllImport("user32.dll")]
     5     private static extern IntPtr GetForegroundWindow();
     6     [DllImport("user32.dll")]
     7     private static extern IntPtr GetFocus();
     8     [DllImport("user32.dll")]
     9     private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach);
    10     [DllImport("user32.dll")]
    11     private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
    12     [DllImport("kernel32.dll")]
    13     private static extern IntPtr GetCurrentThreadId();
    14     [DllImport("user32.dll")]
    15     private static extern void ClientToScreen(IntPtr hWnd, ref Point p);
    16 
    17     private Point CaretPos()
    18     {
    19         IntPtr ptr = GetForegroundWindow();
    20         Point p = new Point();
    21 
    22         //得到Caret在屏幕上的位置   
    23       if (ptr.ToInt32() != 0)
    24         {
    25             IntPtr targetThreadID = GetWindowThreadProcessId(ptr, IntPtr.Zero);
    26             IntPtr localThreadID = GetCurrentThreadId();
    27 
    28             if (localThreadID != targetThreadID)
    29             {
    30                 AttachThreadInput(localThreadID, targetThreadID, 1);
    31                 ptr = GetFocus();
    32                 if (ptr.ToInt32() != 0)
    33                 {
    34                     GetCaretPos(out   p);
    35                     ClientToScreen(ptr, ref   p);
    36                 }
    37                 AttachThreadInput(localThreadID, targetThreadID, 0);
    38             }
    39         }
    40         return p;
    41     }
    42     #endregion
     1 //如何在全屏时notifyIcon依然能够弹出ShowBalloonTip
     2 [DllImport("user32.dll",EntryPoint = "GetForegroundWindow", CharSet = CharSet.Auto, ExactSpelling = true)]
     3 public static extern IntPtr GetForegroundWindow(); //获得本窗体的句柄
     4 [DllImport("user32.dll", EntryPoint = "SetForegroundWindow")]
     5 public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体
     6 
     7 if (this.Handle != GetForegroundWindow())
     8 {
     9     SetForegroundWindow(this.Handle);
    10     notifyIcon1.ShowBalloonTip(1500,"注意注意","XXXXXXX!",ToolTipIcon.Warning);
    11 }
  • 相关阅读:
    HttpClient使用
    十九、springboot使用@ControllerAdvice(二)之深入理解
    如何同步删除svn管理的package包目录
    在使用FastJson开发遇到的的坑
    解决tomcat端口被占用:Port 8005 required by Tomcat v7.0 Server at localhost is already in use
    SpringBoot使用Mybatis-Generator
    SpringCloud Gateway入门
    使用Nginx部署静态网站
    SpringBoot使用Jsp
    SpringBoot应用War包形式部署到外部Tomcat
  • 原文地址:https://www.cnblogs.com/knightyj/p/3738227.html
Copyright © 2020-2023  润新知