在《QQ群发软件开发一》中我们建立了QQ帐号与QQ主程序对应关系。现在我们要实现自动发送功能必须解决以下几个问题:
1、通过这个主程序句柄调出对话框 。
2 、取得QQ对话框句柄,对其进行操作。
先说第一部份取话框, 取对话框分为取QQ好友对话框与QQ群对话框以及群里的陌生人的对话框这三种情况 。
取QQ好友的对话框
// trytimes尝试次数,lastfirend上次取到的好友呢称,friendName这次取到的呢称。
public bool GetNextFriend(int trytimes, string lastfirend, out string friendName)
{
friendName = "";
try
{
if (this.IsActive())
{
for (int timeindex = 0; timeindex < trytimes; timeindex++)
{
WinAPI.ShowWindow(this._QQHandleID.handle, WinConst.SW_SHOW);
Thread.Sleep(new System.Random().Next(8) + 100);
WinAPI.BringWindowToTop(this._QQHandleID.handle);
//Thread.Sleep(new System.Random().Next(8) + 300);
Rect winrect = new Rect();
WinAPI.GetWindowRect(this._QQHandleID.handle, out winrect);
ushort xpos = ushort.Parse(((winrect.Right - winrect.Left) - 10).ToString());
ushort ypos = ushort.Parse(((winrect.Bottom - winrect.Top) - 80).ToString());
//点击滚动条,使用程序取到焦点
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_LBUTTONDOWN, 0, this.MAKELONG(xpos, ypos));
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_LBUTTONUP, 0, this.MAKELONG(xpos, ypos))
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_KEYDOWN, 40, 0);
Thread.Sleep(new System.Random().Next(10) + 20);
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_KEYUP, 40, 0);
Thread.Sleep(new System.Random().Next(10) + 20);
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_KEYDOWN, 13, 0);
Thread.Sleep(new System.Random().Next(10) + 20);
WinAPI.SendMessage(this._QQHandleID.handle, WinConst.WM_KEYUP, 13, 0);
//取到对话框列表
List<winHandle> chatboxlist = this.GetChatInputBoxs();
if (chatboxlist.Count == 0)
{
Thread.Sleep(500 + new System.Random().Next(500));
chatboxlist = this.GetChatInputBoxs();
if (chatboxlist.Count == 0)
{
if (timeindex == 4)
BaseLib.Encry.Writelog(System.DateTime.Now.ToString("yyyyMMddhhmmss") + " ERROE HAVE NOT GET CHATBOX");
continue;
}
}