可參考以下:
成都網(wǎng)站設(shè)計、成都做網(wǎng)站、外貿(mào)網(wǎng)站建設(shè),成都做網(wǎng)站公司-成都創(chuàng)新互聯(lián)公司已向超過千家企業(yè)提供了,網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)絡(luò)營銷等服務(wù)!設(shè)計與技術(shù)結(jié)合,多年網(wǎng)站推廣經(jīng)驗,合理的價格為您打造企業(yè)品質(zhì)網(wǎng)站。
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const WM_GETTEXT = HD
Private Const EM_REPLACESEL = HC2
Private Const BM_CLICK = HF5
Private Function GetWinText(ByVal WinHwnd As Long) As String
Dim lLen As Long
GetWinText = String(255, Chr(0))
lLen = SendMessage(WinHwnd, WM_GETTEXT, Len(GetWinText), ByVal GetWinText)
GetWinText = Left(GetWinText, lLen)
End Function
Private Sub Command1_Click()
On Error GoTo ErrorHandler
Dim HFindWnd As Long
Dim QQHwnd As Long, AHwnd As Long, THwnd As Long, RHwnd As Long
List1.Clear
Me.Caption = "正在獲取發(fā)送列表,請稍候..."
HFindWnd = FindWindowEx(0, 0, "#32770", vbNullString)
Do While HFindWnd 0
If InStr(GetWinText(HFindWnd), "聊天中") 0 Or InStr(GetWinText(HFindWnd), " - ") 0 Or InStr(GetWinText(HFindWnd), "群") 0 Or InStr(GetWinText(HFindWnd), "交談中") 0 Or InStr(GetWinText(HFindWnd), "正在輸入") 0 Or InStr(GetWinText(HFindWnd), " - ") 0 Then
List1.AddItem GetWinText(HFindWnd)
End If
HFindWnd = FindWindowEx(0, HFindWnd, "#32770", vbNullString)
DoEvents
Loop
If List1.ListCount = 0 Then
Me.Caption = "無法獲取QQ消息窗口列表"
Exit Sub
End If
Me.Caption = "獲取發(fā)送列表完成"
Sleep (500)
Me.Caption = "正在發(fā)送QQ消息,請稍候..."
For i = 0 To List1.ListCount - 1
List1.Selected(i) = True
QQHwnd = FindWindow("#32770", List1.Text)
Do
If QQHwnd = 0 Then
QQHwnd = FindWindow("#32770", List1.Text)
End If
AHwnd = FindWindowEx(QQHwnd, AHwnd, "AfxWnd42", vbNullString)
If AHwnd = 0 Then
QQHwnd = FindWindowEx(QQHwnd, 0, "#32770", vbNullString)
End If
THwnd = FindWindowEx(AHwnd, 0, "RichEdit20A", vbNullString)
DoEvents
Loop While THwnd = 0
Me.Caption = "正在發(fā)送第" i + 1 "個QQ消息窗口"
SendMessage THwnd, EM_REPLACESEL, 0, ByVal Text1.Text
RHwnd = FindWindowEx(QQHwnd, 0, "Button", "發(fā)送(S)")
SendMessage RHwnd, BM_CLICK, 0, 0
DoEvents
Sleep (500)
Next i
Me.Caption = "一共發(fā)送了" i "個QQ消息窗口"
List1.Clear
List1.AddItem ("已完成所有消息發(fā)送")
ErrorHandler:
End Sub
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.Diagnostics;
namespace QQLogin
{
public partial class QQLoginForm : Form
{
public QQLoginForm()
{
InitializeComponent();
}
UserInfo ui;
private void button1_Click(object sender, EventArgs e)
{
//單用戶登陸
if (ui == null)
{
ui = new UserInfo();//如果沒有提取出來對象,就創(chuàng)建一個
}
if (ui != null)
{
ui.Username = this.txtUser.Text.Trim();
ui.Password = this.txtPwd.Text;
ui.Type = this.cboType.Text == "正常" ? "41" : "40";
if (this.ValidateInput())
{//驗證是否輸入完全
if (string.IsNullOrEmpty(ui.Path))
{//判斷是否有QQ路徑,如果沒有就打開對話框來選擇一下
DialogResult dr = this.opfQQ.ShowDialog();
if (dr == DialogResult.OK)
{
ui.Path = opfQQ.FileName;//將選擇的路徑賦值給對象
this.LoginQQ(ui.Username, ui.Password, ui.Type, ui.Path);//登陸QQ
}
}
else
{
this.LoginQQ(ui.Username, ui.Password, ui.Type, ui.Path);
}
}
SerializeHelper.SerializeUserInfo(ui);//每次登陸都序列化保存一次
}
}
private bool ValidateInput()
{//驗證是否輸入完整
if (this.txtUser.Text == "")
{
this.txtUser.Focus();
return false;
}
else if(this.txtPwd.Text=="")
{
this.txtPwd.Focus();
return false;
}
return true;
}
private void LoginQQ(string user,string pwd,string type,string path)
{//登陸QQ的命令,通過CMD命令來執(zhí)行
Process MyProcess = new Process();
//設(shè)定程序名
MyProcess.StartInfo.FileName = "cmd.exe";
//關(guān)閉Shell的使用
MyProcess.StartInfo.UseShellExecute = false;
//重定向標(biāo)準(zhǔn)輸入
MyProcess.StartInfo.RedirectStandardInput = true;
//重定向標(biāo)準(zhǔn)輸出
MyProcess.StartInfo.RedirectStandardOutput = true;
//重定向錯誤輸出
MyProcess.StartInfo.RedirectStandardError = true;
//設(shè)置不顯示窗口
MyProcess.StartInfo.CreateNoWindow = true;
//執(zhí)行強(qiáng)制結(jié)束命令
MyProcess.Start();
MyProcess.StandardInput.WriteLine(path+" /start QQUIN:"+user+" PWDHASH:" + EncodeHash.pwdHash(pwd) + " /stat:"+type);//直接結(jié)束進(jìn)程ID
MyProcess.StandardInput.WriteLine("Exit");
}
private void btnExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void txtUser_KeyPress(object sender, KeyPressEventArgs e)
{
if ((e.KeyChar '0' || e.KeyChar '9')e.KeyChar!=8)
{//只能輸入數(shù)字和退格鍵
e.Handled = true;
}
}
private void QQLoginForm_Load(object sender, EventArgs e)
{
LoadInfo();//單用戶獲取
}
private void LoadInfo()
{//單用戶獲取
ui = SerializeHelper.DeserializeUserInfo();//返回獲取后對象
if (ui != null)
{
this.txtUser.Text = ui.Username;//填充文本框
this.txtPwd.Text = ui.Password;//填充密碼框
this.cboType.SelectedIndex = ui.Type == "41" ? 0 : 1;//選擇登陸方式
}
else
{
this.cboType.SelectedIndex = 0;
}
}
private void btnConfig_Click(object sender, EventArgs e)
{
ConfigForm cf = new ConfigForm();
cf.ShowDialog();
LoadInfo();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace QQLogin
{
public partial class ConfigForm : Form
{
UserInfo ui;
public ConfigForm()
{
InitializeComponent();
}
private void txtPath_Click(object sender, EventArgs e)
{//點(diǎn)擊一次文本框,彈出一次對話框來選擇QQ路徑
DialogResult dr = this.opfQQ.ShowDialog();
if (dr == DialogResult.OK)
{
this.txtPath.Text = opfQQ.FileName;
}
}
private bool ValidateInput()
{//驗證是否輸入完整
if (this.txtUser.Text == "")
{
this.txtUser.Focus();
return false;
}
else if (this.txtPwd.Text == "")
{
this.txtPwd.Focus();
return false;
}
else if (this.txtPath.Text == "")
{
return false;
}
return true;
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}
private void ConfigForm_Load(object sender, EventArgs e)
{
LoadInfo();
}
private void btnSave_Click(object sender, EventArgs e)
{
ui = new UserInfo();
ui.Username = this.txtUser.Text.Trim();
ui.Password = this.txtPwd.Text;
ui.Type = this.cboType.Text == "正常" ? "41" : "40";
ui.Path = this.txtPath.Text;
if (this.ValidateInput())
{
SerializeHelper.SerializeUserInfo(ui);
this.Close();
}
}
private void LoadInfo()
{
ui = SerializeHelper.DeserializeUserInfo();
if (ui != null)
{
this.txtUser.Text = ui.Username;
this.txtPwd.Text = ui.Password;
this.cboType.SelectedIndex = ui.Type == "41" ? 0 : 1;
this.txtPath.Text = ui.Path;
}
else
{
this.cboType.SelectedIndex = 0;
}
}
}
}
如果你已經(jīng)開啟QQ就可以
這樣寫
Shell Environ("PROGRAMFILES") "\Internet Explorer\iexplore.exe " "Tencent://Message/?Menu=YESExe=Uin=" Text1.Text, vbNormalFocus
Text1.Text就是你輸入想要聊天的對象的QQ號
不需要加對方為好友就可以聊天
如果沒有就回談出無效網(wǎng)頁