捕捉消息框中的文字
来源:互联网 发布:mapreduce python 编辑:程序博客网 时间:2024/06/05 09:28
把桌面上弹出的消息框中的文字取出来
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Xml;
using System.Runtime.InteropServices;
namespace WindowsApplication26
...{
public partial class Form1 : Form
...{
public class HookMsg
...{
Win32 API functions#region Win32 API functions
private const int WH_CBT = 0x5;
private const int IDC_OK = 0x1;
private const int IDC_Text = 0xFFFF;
[DllImport("user32.dll")]
protected static extern IntPtr SetWindowsHookEx(int code, HookProc func, IntPtr hInstance, int threadID);
[DllImport("user32.dll")]
protected static extern int UnhookWindowsHookEx(IntPtr hhook);
[DllImport("user32.dll")]
protected static extern int CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
protected static extern int GetWindowText(IntPtr hwnd, [Out]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
protected static extern int GetClassName(IntPtr hwnd, [Out]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
protected static extern int SetWindowText(IntPtr hWnd, string lpString);
[DllImport("user32.dll")]
protected static extern IntPtr GetDlgItem(IntPtr hwnd, int id);
[DllImport("User32")]
protected static extern int SetDlgItemText(IntPtr hDlg, int nIDDlgItem, string lpString);
[DllImport("user32.dll")]
protected static extern int GetDlgItemText(IntPtr hDlg, int nIDDlgItem, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "MessageBox")]
protected static extern int _MessageBox(IntPtr hwnd, string text, string caption,
int options);
[DllImport("user32.dll")]
protected static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
protected static extern void DestroyWindow(IntPtr hwnd);
#endregion
private static System.IntPtr m_hhook;
public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
protected static HookProc m_filterFunc;
static HookMsg()
...{
if (m_filterFunc == null)
m_filterFunc = new HookProc(CoreHookProc);
}
public static void Install()
...{
m_hhook = SetWindowsHookEx(WH_CBT, m_filterFunc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
}
public static void Uninstall()
...{
UnhookWindowsHookEx(m_hhook);
}
//CallBack
protected static int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
...{
if (code == 5)
...{
StringBuilder sb = new StringBuilder();
sb.Capacity = 255;
//Title
GetWindowText(wParam, sb, 255);
string strTitle = "jinjazz看到了:" + sb.ToString();
//Text
GetDlgItemText(wParam, IDC_Text, sb, 255);
string strText = "jinjazz看到了:" + sb.ToString();
//获取按钮
int style = 0;
for (int i = 0; i <= 5; i++)
...{
if (GetDlgItem(wParam, i) != IntPtr.Zero)
style += i;
}
SetDlgItemText(wParam, IDC_Text, strText);
SetWindowText(wParam, strTitle);
SetWindowText(GetDlgItem(wParam, (int)DialogResult.No), "jinjazzOK");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Cancel), "jinjazzCancel");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Abort), "jinjazzAbort");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Ignore), "jinjazzIgnore");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.None), "jinjazzNone");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.OK), "jinjazzOK");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Retry), "jinjazzRetry");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Yes), "jinjazzYes");
}
// return CallNextHookEx(this.m_hhook, code, wParam, lParam);
return 0;
}
}
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
}
private void button1_Click(object sender, EventArgs e)
...{
MessageBox.Show(this,"确定按钮 ","标题");
}
private void button2_Click(object sender, EventArgs e)
...{
MessageBox.Show(this, "确定按钮 ", "标题", MessageBoxButtons.YesNoCancel);
}
private void button3_Click(object sender, EventArgs e)
...{
MessageBox.Show(this, "确定按钮 ", "标题", MessageBoxButtons.AbortRetryIgnore);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
...{
if (this.checkBox1.Checked)
...{
HookMsg.Install();
}
else
...{
HookMsg.Uninstall();
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using System.Xml;
using System.Runtime.InteropServices;
namespace WindowsApplication26
...{
public partial class Form1 : Form
...{
public class HookMsg
...{
Win32 API functions#region Win32 API functions
private const int WH_CBT = 0x5;
private const int IDC_OK = 0x1;
private const int IDC_Text = 0xFFFF;
[DllImport("user32.dll")]
protected static extern IntPtr SetWindowsHookEx(int code, HookProc func, IntPtr hInstance, int threadID);
[DllImport("user32.dll")]
protected static extern int UnhookWindowsHookEx(IntPtr hhook);
[DllImport("user32.dll")]
protected static extern int CallNextHookEx(IntPtr hhook, int code, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll")]
protected static extern int GetWindowText(IntPtr hwnd, [Out]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
protected static extern int GetClassName(IntPtr hwnd, [Out]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
protected static extern int SetWindowText(IntPtr hWnd, string lpString);
[DllImport("user32.dll")]
protected static extern IntPtr GetDlgItem(IntPtr hwnd, int id);
[DllImport("User32")]
protected static extern int SetDlgItemText(IntPtr hDlg, int nIDDlgItem, string lpString);
[DllImport("user32.dll")]
protected static extern int GetDlgItemText(IntPtr hDlg, int nIDDlgItem, [Out] StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "MessageBox")]
protected static extern int _MessageBox(IntPtr hwnd, string text, string caption,
int options);
[DllImport("user32.dll")]
protected static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
protected static extern void DestroyWindow(IntPtr hwnd);
#endregion
private static System.IntPtr m_hhook;
public delegate int HookProc(int code, IntPtr wParam, IntPtr lParam);
protected static HookProc m_filterFunc;
static HookMsg()
...{
if (m_filterFunc == null)
m_filterFunc = new HookProc(CoreHookProc);
}
public static void Install()
...{
m_hhook = SetWindowsHookEx(WH_CBT, m_filterFunc, IntPtr.Zero, AppDomain.GetCurrentThreadId());
}
public static void Uninstall()
...{
UnhookWindowsHookEx(m_hhook);
}
//CallBack
protected static int CoreHookProc(int code, IntPtr wParam, IntPtr lParam)
...{
if (code == 5)
...{
StringBuilder sb = new StringBuilder();
sb.Capacity = 255;
//Title
GetWindowText(wParam, sb, 255);
string strTitle = "jinjazz看到了:" + sb.ToString();
//Text
GetDlgItemText(wParam, IDC_Text, sb, 255);
string strText = "jinjazz看到了:" + sb.ToString();
//获取按钮
int style = 0;
for (int i = 0; i <= 5; i++)
...{
if (GetDlgItem(wParam, i) != IntPtr.Zero)
style += i;
}
SetDlgItemText(wParam, IDC_Text, strText);
SetWindowText(wParam, strTitle);
SetWindowText(GetDlgItem(wParam, (int)DialogResult.No), "jinjazzOK");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Cancel), "jinjazzCancel");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Abort), "jinjazzAbort");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Ignore), "jinjazzIgnore");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.None), "jinjazzNone");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.OK), "jinjazzOK");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Retry), "jinjazzRetry");
SetWindowText(GetDlgItem(wParam, (int)DialogResult.Yes), "jinjazzYes");
}
// return CallNextHookEx(this.m_hhook, code, wParam, lParam);
return 0;
}
}
public Form1()
...{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
...{
}
private void button1_Click(object sender, EventArgs e)
...{
MessageBox.Show(this,"确定按钮 ","标题");
}
private void button2_Click(object sender, EventArgs e)
...{
MessageBox.Show(this, "确定按钮 ", "标题", MessageBoxButtons.YesNoCancel);
}
private void button3_Click(object sender, EventArgs e)
...{
MessageBox.Show(this, "确定按钮 ", "标题", MessageBoxButtons.AbortRetryIgnore);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
...{
if (this.checkBox1.Checked)
...{
HookMsg.Install();
}
else
...{
HookMsg.Uninstall();
}
}
}
}
- 捕捉消息框中的文字
- ITextHost::TxNotify 中的 EN_LINK、EN_CHANGE 消息捕捉
- 用SnapIt 7.12 捕捉屏幕窗口中的文字
- spy++捕捉进程消息
- 捕捉键盘中断消息
- C# 捕捉消息提示框点击的是否
- 鼠标滚轮消息的捕捉
- 鼠标滚轮消息的捕捉
- 鼠标滚轮消息的捕捉
- 鼠标滚轮消息的捕捉
- 如何捕捉窗口按钮消息
- WINCE中的钩子函数能捕捉到关机键按下的消息吗?(zhuan)
- Directshow中的视频捕捉
- Directshow中的视频捕捉
- Directshow中的视频捕捉
- Directshow中的视频捕捉
- Directshow中的视频捕捉
- Directshow中的视频捕捉
- 主板前置USB插线接法大全
- 计算机系统结构[课后题答案] http://bbs.xiakee.com/Topic.aspx?BoardID=84&TopicID=22
- 上交所欲吸引跨国公司来沪上市
- GetMessage()与peekMessage()的区别
- 什么是IOC
- 捕捉消息框中的文字
- 计划文章列表
- 解读协作:建导技巧
- 加密算法
- C语言 for问题
- JSP实现文件下载同时解决中文乱码问题
- ffff
- 中国报表漫谈
- JBossTools开发Seam2.0应用抢先体验