您的位置:首页 > 编程语言 > VB

VB.NET实现的QQ消息群炸机(全源码)

2007-08-26 07:51 573 查看
全部代码在Windows Server 2003 + Visual Studio.net 2003中运行并通过,作者开始时写的题目为《QQ消息轰炸机》,但编译后发现并不是轰炸,却可以“群炸”,后来通读一遍代码后发现确实是“群炸”机,至于开头中的注释,应该是作者的本意或者是笔误吧,不管怎么说,这些实实在在的代码可以帮助程序设计爱好者更多更好的学习。

'***************************************
'QQ消息轰炸机源代码(VB.NET)
'wgscd 2005-1-1

'***************************************
Public Class Form1
 Inherits System.Windows.Forms.Form
 Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
 Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String, ByVal cch As Int32) As Int32
 Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
 Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
 Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
 'Private Const WM_PASTE As Int32 = &H302
 Private Const WM_SETTEXT As Int32 = &HC
 Private Const WM_KEYDOWN As Int32 = &H100
 Private Const WM_KEYUP As Int32 = &H101
 Private Const WM_LBUTTONDOWN As Int32 = &H201
 Private Const WM_LBUTTONUP As Int32 = &H202

 'Private Const WM_SHOWWINDOW As Int32 = &H18
 Private Const SW_NORMAL As Int32 = 1
 Private Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Int32, ByVal nCmdShow As Int32) As Int32
 'Private Declare Function GetLastError Lib "kernel32.dll" () As Int32
 Private Const SW_SHOWNOACTIVATE As Int32 = 4
 Private Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Int32, ByVal lpString As String) As Int32
 Private Const SW_HIDE As Int32 = 0
 Private Const SW_SHOW As Int32 = 5

 Dim sMess As String
 Dim hwnd, hwnd2, hwnd3, i, iDelay As Int32
 Dim hWndTalk(20), hWndEdit(20), hWndSend(20) As Int32
 Dim MyThread As Threading.Thread
#Region " Windows 窗体设计器生成的代码 "

 Public Sub New()
 MyBase.New()

 '该调用是 Windows 窗体设计器所必需的。
 InitializeComponent()

 '在 InitializeComponent() 调用之后添加任何初始化

 End Sub

 '窗体重写 dispose 以清理组件列表。
 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
 If disposing Then
 If Not (components Is Nothing) Then
 components.Dispose()
 End If
 End If
 MyBase.Dispose(disposing)
 End Sub

 'Windows 窗体设计器所必需的
 Private components As System.ComponentModel.IContainer

 '注意: 以下过程是 Windows 窗体设计器所必需的
 '可以使用 Windows 窗体设计器修改此过程。
 '不要使用代码编辑器修改它。

 Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
 Friend WithEvents Label1 As System.Windows.Forms.Label
 Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
 Friend WithEvents Label3 As System.Windows.Forms.Label
 Friend WithEvents ButtonRefresh As System.Windows.Forms.Button
 Friend WithEvents ButtonStart As System.Windows.Forms.Button
 Friend WithEvents ButtonStop As System.Windows.Forms.Button
 Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
 Friend WithEvents RadioButton2 As System.Windows.Forms.RadioButton
 Friend WithEvents ListView1 As System.Windows.Forms.ListView
 <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 Me.ButtonRefresh = New System.Windows.Forms.Button
 Me.ButtonStart = New System.Windows.Forms.Button
 Me.TextBox1 = New System.Windows.Forms.TextBox
 Me.Label1 = New System.Windows.Forms.Label
 Me.GroupBox1 = New System.Windows.Forms.GroupBox
 Me.ListView1 = New System.Windows.Forms.ListView
 Me.RadioButton2 = New System.Windows.Forms.RadioButton
 Me.RadioButton1 = New System.Windows.Forms.RadioButton
 Me.ButtonStop = New System.Windows.Forms.Button
 Me.Label3 = New System.Windows.Forms.Label
 Me.GroupBox1.SuspendLayout()
 Me.SuspendLayout()
 '
 'ButtonRefresh
 '
 Me.ButtonRefresh.Location = New System.Drawing.Point(16, 80)
 Me.ButtonRefresh.Name = "ButtonRefresh"
 Me.ButtonRefresh.Size = New System.Drawing.Size(56, 24)
 Me.ButtonRefresh.TabIndex = 0
 Me.ButtonRefresh.Text = "刷新"
 '
 'ButtonStart
 '
 Me.ButtonStart.Location = New System.Drawing.Point(16, 116)
 Me.ButtonStart.Name = "ButtonStart"
 Me.ButtonStart.Size = New System.Drawing.Size(56, 24)
 Me.ButtonStart.TabIndex = 1
 Me.ButtonStart.Text = "开始"
 '
 'TextBox1
 '
 Me.TextBox1.AutoSize = False
 Me.TextBox1.Location = New System.Drawing.Point(16, 216)
 Me.TextBox1.Multiline = True
 Me.TextBox1.Name = "TextBox1"
 Me.TextBox1.Size = New System.Drawing.Size(256, 88)
 Me.TextBox1.TabIndex = 3
 Me.TextBox1.Text = "/cy 轰炸美国,从你开始. "
 '
 'Label1
 '
 Me.Label1.AutoSize = True
 Me.Label1.Location = New System.Drawing.Point(24, 200)
 Me.Label1.Name = "Label1"
 Me.Label1.Size = New System.Drawing.Size(91, 17)
 Me.Label1.TabIndex = 4
 Me.Label1.Text = "请输入发送内容"
 '
 'GroupBox1
 '
 Me.GroupBox1.Controls.Add(Me.ListView1)
 Me.GroupBox1.Controls.Add(Me.RadioButton2)
 Me.GroupBox1.Controls.Add(Me.RadioButton1)
 Me.GroupBox1.Controls.Add(Me.ButtonStop)
 Me.GroupBox1.Controls.Add(Me.ButtonStart)
 Me.GroupBox1.Controls.Add(Me.ButtonRefresh)
 Me.GroupBox1.Location = New System.Drawing.Point(16, 8)
 Me.GroupBox1.Name = "GroupBox1"
 Me.GroupBox1.Size = New System.Drawing.Size(248, 184)
 Me.GroupBox1.TabIndex = 9
 Me.GroupBox1.TabStop = False
 '
 'ListView1
 '
 Me.ListView1.CheckBoxes = True
 Me.ListView1.Location = New System.Drawing.Point(96, 24)
 Me.ListView1.Name = "ListView1"
 Me.ListView1.Size = New System.Drawing.Size(144, 152)
 Me.ListView1.TabIndex = 12
 Me.ListView1.View = System.Windows.Forms.View.List
 '
 'RadioButton2
 '
 Me.RadioButton2.Location = New System.Drawing.Point(12, 40)
 Me.RadioButton2.Name = "RadioButton2"
 Me.RadioButton2.Size = New System.Drawing.Size(88, 24)
 Me.RadioButton2.TabIndex = 1
 Me.RadioButton2.Text = "直到我叫停"
 '
 'RadioButton1
 '
 Me.RadioButton1.Checked = True
 Me.RadioButton1.Location = New System.Drawing.Point(12, 17)
 Me.RadioButton1.Name = "RadioButton1"
 Me.RadioButton1.Size = New System.Drawing.Size(88, 24)
 Me.RadioButton1.TabIndex = 0
 Me.RadioButton1.TabStop = True
 Me.RadioButton1.Text = "只发一次"
 '
 'ButtonStop
 '
 Me.ButtonStop.Location = New System.Drawing.Point(16, 152)
 Me.ButtonStop.Name = "ButtonStop"
 Me.ButtonStop.Size = New System.Drawing.Size(56, 24)
 Me.ButtonStop.TabIndex = 11
 Me.ButtonStop.Text = "停止"
 '
 'Label3
 '
 Me.Label3.Location = New System.Drawing.Point(96, 312)
 Me.Label3.Name = "Label3"
 Me.Label3.Size = New System.Drawing.Size(184, 24)
 Me.Label3.TabIndex = 10
 Me.Label3.Text = "---自由奔腾 wgscd----"
 '
 'Form1
 '
 Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
 Me.BackColor = System.Drawing.Color.SkyBlue
 Me.ClientSize = New System.Drawing.Size(280, 325)
 Me.Controls.Add(Me.Label3)
 Me.Controls.Add(Me.Label1)
 Me.Controls.Add(Me.TextBox1)
 Me.Controls.Add(Me.GroupBox1)
 Me.MaximizeBox = False
 Me.MinimizeBox = False
 Me.Name = "Form1"
 Me.Text = "QQ消息群炸机"
 Me.GroupBox1.ResumeLayout(False)
 Me.ResumeLayout(False)

 End Sub

#End Region

 Private Sub ButtonRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRefresh.Click
 ListView1.Items.Clear()'清除元素
 ''''''''''''''''''''''''''''''''''''''''''''''''
 hwnd = 0
 i = 0
 Dim str As String
 While 1
 hwnd = FindWindowEx(0, hwnd, "#32770", vbNullString)
 If hwnd = 0 Then
 Exit While
 Else
 Str = New String(Chr(0), 50)
 GetWindowText(hwnd, Str, 50)
 Str = Str.TrimEnd(Chr(0))
 If Str.StartsWith("与 ") And Str.EndsWith(" 聊天中") Then
 '聊天主窗口hwnd--子窗口hwnd2(发送BUTTON 和 hwnd3 的父窗口)--hwnd3(文本编辑框的父窗口)--文本编辑窗口句柄
 hWndTalk(i) = hwnd'聊天主窗口句柄
 hwnd2 = FindWindowEx(hwnd, 0, "#32770", vbNullString) '发送按钮 和 文本编辑框 的父窗口
 '''''''''''''''''''''''''''''''''''''''''''
 hWndSend(i) = FindWindowEx(hwnd2, 0, vbNullString, "发送(&s)") '发送BUTTON 句柄
 '''''''''''''''''''''''''''''''''''''''''''
 hwnd3 = FindWindowEx(hwnd2, 0, "AfxWnd42", vbNullString) '文本编辑框的父窗口
 hWndEdit(i) = FindWindowEx(hwnd3, 0, "RICHEDIT", vbNullString) '文本编辑框的句柄
 '''''''''''''''''''''''''''''''''''
 i += 1
 Str = Str.Substring(2)
 Str = Str.Replace(" 聊天中", "")
 Dim item As Windows.Forms.ListViewItem
 item = ListView1.Items.Add(Str)
 item.Checked = True
 '''''''''''''''''''''''''''''''''''
 End If
 End If
 End While

 End Sub

 Private Sub ButtonStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonStop.Click
 If (Not MyThread Is Nothing) Then
 MyThread.Abort()
 End If
 ButtonStart.Enabled = True
 End Sub

 Private Sub ButtonStart_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonStart.Click
 sMess = Me.TextBox1.Text.ToString
 If sMess = "" Then
 MsgBox("请输入发送内容!")
 Exit Sub
 End If
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 '以下求延迟毫秒数
 iDelay = 0
 For i = 0 To ListView1.Items.Count - 1
 If ListView1.Items(i).Checked = True Then
 iDelay += 1 '共有多少个窗口,要发送信息
 End If
 Next
 If iDelay = 0 Then
 MsgBox("请选择至少一个聊天对象,必须打开聊天窗口,再按刷新即可。")
 Exit Sub
 End If
 iDelay = 3100 - iDelay * 1000 '延迟多少秒,发送的窗口越少,延迟秒数越大
 If iDelay < 0 Then
 iDelay = 0
 End If
 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 If RadioButton1.Checked Then'只发一次
 SendMess()
 Else'不停地发,直到用户中止
 MyThread = New Threading.Thread(AddressOf SendMessUntil)
 MyThread.Start()
 ButtonStart.Enabled = False
 End If
 End Sub
 Private Sub SendMess()
 For i = 0 To ListView1.Items.Count - 1
 If ListView1.Items(i).Checked = True Then
 SendMessage(hWndEdit(i), WM_SETTEXT, 0, sMess & "hhhhhhhh")
 System.Threading.Thread.Sleep(iDelay)
 SendMessage(hWndSend(i), WM_LBUTTONDOWN, 0, 0)
 SendMessage(hWndSend(i), WM_LBUTTONUP, 0, 0)
 End If
 Next
 End Sub
 Private Sub SendMessUntil()
 While 1
 SendMess()
 End While
 End Sub

 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
 ButtonRefresh_Click(Nothing, Nothing)
 End Sub

 Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
 If (Not MyThread Is Nothing) Then
 MyThread.Abort()
 End If
 End Sub

End Class
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: