Visual C#弹出窗口杀手(2)

上面的方法在性能上是不错的,因为他过滤了其他非IE的窗口.但是我们可以用一个更简单的方法来实现,就是调用API FindWindowEx(HWND hWndParent, HWND hWndNext, /*in*/LPCTSTR szClassName, /*in*/LPCTSTR szWindowTitle)方法.比较有用的是这句,我们可以使用registered window class name来找到IE窗口(IEFrame是所有打开的IE的标识).

  数据挖掘实验室

protected void FindPopupToKill()

{

IntPtr hParent = IntPtr.Zero;

IntPtr hNext = IntPtr.Zero;

String sClassNameFilter = "IEFrame"; // 所有IE窗口的类

do

{ hNext = NativeWIN32.FindWindowEx(hParent,hNext,sClassNameFilter,IntPtr.Zero);

// we′ve got a hwnd to play with

if ( !hNext.Equals(IntPtr.Zero) )

{

// get window caption

NativeWIN32.STRINGBUFFER sLimitedLengthWindowTitle;

NativeWIN32.GetWindowText(hNext, out sLimitedLengthWindowTitle, 256);

String sWindowTitle = sLimitedLengthWindowTitle.szText;

if (sWindowTitle.Length>0)

{

// find this caption in the list of banned captions

foreach (ListViewItem item in listView1.Items)

{

if ( sWindowTitle.StartsWith(item.Text) )

NativeWIN32.SendMessage(hNext, NativeWIN32.WM_SYSCOMMAND, 数据挖掘实验室

NativeWIN32.SC_CLOSE,

IntPtr.Zero); // try soft kill

} }

} }

while (!hNext.Equals(IntPtr.Zero));

}

public class NativeWIN32

{ [DllImport("user32.dll", CharSet=CharSet.Auto)]

public static extern IntPtr FindWindowEx(IntPtr parent /*HWND*/,

IntPtr next /*HWND*/,

string sClassName,

IntPtr sWindowTitle);

}

注册系统热键

系统热键用在像弹出窗口杀手这种应用程序非常有用, Ctrl+Shift+J是缺省热键。

说道实现,我们继续用RegisterHotkey(HWND hWnd, int id, UINT fsModifiers, UINT vkey)。完成,代码如下: 数据挖掘实验室

public void SetHotKey(Keys c, bool bCtrl, bool bShift, bool bAlt, bool bWindows)

{

m_hotkey = c;

m_ctrlhotkey = bCtrl;

m_shifthotkey = bShift;

m_althotkey = bAlt;

m_winhotkey = bWindows;

// update hotkey

NativeWIN32.KeyModifiers modifiers = NativeWIN32.KeyModifiers.None;

if (m_ctrlhotkey)

modifiers |= NativeWIN32.KeyModifiers.Control;

if (m_shifthotkey)

modifiers |= NativeWIN32.KeyModifiers.Shift;

if (m_althotkey)

modifiers |= NativeWIN32.KeyModifiers.Alt;

if (m_winhotkey)

modifiers |= NativeWIN32.KeyModifiers.Windows;

NativeWIN32.RegisterHotKey(Handle, 100, modifiers, m_hotkey); //Keys.J);

}

一般的,注册热键要一下几步

/* ------- using HOTKEYs in a C# application -------

-- code snippet by James J Thompson --

在Form的load 中 : Ctrl+Shift+J

bool success = RegisterHotKey(Handle,

100,

KeyModifiers.Control | KeyModifiers.Shift,

Keys.J);

在 form的closing中 : UnregisterHotKey(Handle, 100); 

如何处理热键 : 数据挖掘工具

protected override void WndProc( ref Message m )

{ const int WM_HOTKEY = 0x0312;

switch(m.Msg)

{ case WM_HOTKEY:

MessageBox.Show("Hotkey pressed");

ProcessHotkey();

break;

} base.WndProc(ref m );

}

public class NativeWIN32

{

[DllImport("user32.dll", SetLastError=true)]

public static extern bool RegisterHotKey( IntPtr hWnd, // handle to window

int id, // hot key identifier

KeyModifiers fsModifiers, // key-modifier options

Keys vk // virtual-key code

);

[DllImport("user32.dll", SetLastError=true)]

public static extern bool UnregisterHotKey( IntPtr hWnd, // handle to window

int id // hot key identifier

);

[Flags()]

public enum KeyModifiers

{

数据挖掘论坛


None = 0,

Alt = 1,

Control = 2,

Shift = 4,

Windows = 8

}

}

------- using HOTKEYs in a C# application ------- */

当我们按下热键以后,流程是这样:首先用HWND GetForegroundWindow()来得到窗体,然后要抓出窗体的标题, GetWindowText(HWND hwnd, /*out*/LPTSTR lpString, int nMaxCount). 具体如下: 数据挖掘论坛

protected void ProcessHotkey()

{ IntPtr hwnd = NativeWIN32.GetForegroundWindow();

if (!hwnd.Equals(IntPtr.Zero))

{ NativeWIN32.STRINGBUFFER sWindowTitle;

NativeWIN32.GetWindowText(hwnd, out sWindowTitle, 256);

if (sWindowTitle.szText.Length>0)

AddWindowTitle( sWindowTitle.szText ); // add to the ListView (Form)

} }
[数据挖掘专家] [数据挖掘研究院] [数据挖掘论坛] [数据挖掘实验室]
上一篇:Visual C#弹出窗口杀手(1)
下一篇:Windows 窗体之创建动态上下文菜单
最新评论共有 0 位网友发表了评论 , 查看所有评论
发表评论( 不能超过250字,需审核,请自觉遵守互联网相关政策法规。 )
匿名?
数据挖掘网站导航 数据挖掘论坛导航
  • 数据挖掘工具
  • 数据挖掘论坛
  • DataCruncher - Cognos
  • MineSet - MathSoft
  • Intelligent Miner - GainSmarts
  • Sqlserver - SAS - Clementine
  • CART - Weka - WizSoft
  • NeuroShell - ModelQuest
  • data mining tools - Darwin
  • 数据挖掘交友
  • 数据挖掘博客
  • 数据挖掘工具
  • 数据挖掘资源
  • 数据挖掘技术算法
  • 数据挖掘相关期刊、会议
  • 研究院联盟合作专区
  • 数据挖掘基础与相关技术
  • 数据挖掘厂商与就业
  • 数据挖掘研究者乐园
  • 知名厂商数据挖掘工具资料
  • 国内数据挖掘实验室
  • Foreign Data Mining Lab
  • 热点关注
  • 挑战C#学习的最快速度
  • C#模仿QQ截图功能
  • C# 关于开机自动运行程序方式之一
  • 第一章 C#简介
  • 利用C#实现分布式数据库查询
  • Visual Studio 2005 Hands-On Tutorial - P
  • C#入门代码
  • .NET架构与模式探索
  • 用C#代码编写的SN快速输入工具
  • C# 关于开机自动运行程序方式之一
  • 论坛最新话题
  • Foundations of Statistical Natural Langu
  • Game Theory meet Data Mining: A Recent P
  • System Building: How does it help or hin
  • 数据挖掘与Clementine培训
  • 新手报到
  • 求 SASEM 客户流失预测分析
  • 数据挖掘工程师/搜索研究院—北京——无线
  • 数据挖掘入门介绍(如何着手数据挖掘)
  • Information Overload Survey Results
  • The INEX 2005 Workshop on Element Retrie
  • 相关资讯
  • 彻底剖析C# 2.0泛型类的创建和使用
  • 对C# 2.0中匿名方法的怀疑分析
  • EasySP管理解决方案基于Microsoft .NET架构
  • .NET架构与模式探索
  • .NET架构的核心开发技术
  • 用C#代码编写的SN快速输入工具
  • C#链接数据库技巧
  • C#设计模式编程之抽象工厂模式新解
  • 第一章 C#简介
  • 第七章 异常处理
  • 数据挖掘实验室资料
  • 数据挖掘博客地址
  • 数据挖掘实验室网站地址
  • Prepare for Medicare audits by using dat
  • 注册成为SAS用户与爱好者俱乐部会员
  • 水南梅
  • 明日烟
  • 新人报道
  • 下载
  • 厦门服务器托管,450元/月—0592-5177319 高
  • 买空间送域名--0592-5177319 高静