Api代码收集
2014-05-20 09:50
246 查看
收集自网络,方便自己,方便他人
#region 隐藏系统滚动条 protected override void WndProc(ref System.Windows.Forms.Message m) { ShowScrollBar(this.Handle, 3, false);//0:horizontal,1:vertical,3:both base.WndProc(ref m); } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow); #endregion
#region 得到光标在屏幕上的位置 [DllImport("user32")] public static extern bool GetCaretPos(out Point lpPoint); [DllImport("user32.dll")] private static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] private static extern IntPtr GetFocus(); [DllImport("user32.dll")] private static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, int fAttach); [DllImport("user32.dll")] private static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId); [DllImport("kernel32.dll")] private static extern IntPtr GetCurrentThreadId(); [DllImport("user32.dll")] private static extern void ClientToScreen(IntPtr hWnd, ref Point p); private Point CaretPos() { IntPtr ptr = GetForegroundWindow(); Point p = new Point(); //得到Caret在屏幕上的位置 if (ptr.ToInt32() != 0) { IntPtr targetThreadID = GetWindowThreadProcessId(ptr, IntPtr.Zero); IntPtr localThreadID = GetCurrentThreadId(); if (localThreadID != targetThreadID) { AttachThreadInput(localThreadID, targetThreadID, 1); ptr = GetFocus(); if (ptr.ToInt32() != 0) { GetCaretPos(out p); ClientToScreen(ptr, ref p); } AttachThreadInput(localThreadID, targetThreadID, 0); } } return p; } #endregion
//如何在全屏时notifyIcon依然能够弹出ShowBalloonTip [DllImport("user32.dll",EntryPoint = "GetForegroundWindow", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetForegroundWindow(); //获得本窗体的句柄 [DllImport("user32.dll", EntryPoint = "SetForegroundWindow")] public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 if (this.Handle != GetForegroundWindow()) { SetForegroundWindow(this.Handle); notifyIcon1.ShowBalloonTip(1500,"注意注意","XXXXXXX!",ToolTipIcon.Warning); }
相关文章推荐
- 一个Win32 API实例类(代码收集)
- 网上收集标准API展开BOM代码
- JAVASCRIPT代码收集
- VC学习资料收集(25):获取硬盘ID信息及网卡MAC地址的代码
- 收集来的JavaScript代码
- 代码收集工具升级了~
- csdn代码收集
- JavaScript 收集的两个小代码!
- ASP.NET程序中常用的三十三种代码(收集)
- 一些Web开发代码收集
- 收集整理:网页特效代码共享
- C# 收集机器硬件信息的相关代码片断(cpu频率、磁盘可用空间、内存容量……)
- ASP.NET程序中常用的三十三种代码(收集)
- 自我代码收集
- 以前初学时收集的一些代码(JSP)
- Win32 API资源分配释放速查,防止代码资源泄露
- 适合做公告板的代码收集
- 让 VB 执行自定义字符串代码的 API 函数。
- JavaScript代码收集
- VC代码收集