(山寨版QQ)源代码
仿QQ聊天软件MyQQ源代码教学(北大青鸟完整版)

需求分析——功能分析
主要功能:
注册与登录 好友管理 消息管理 个人设置
需求分析——界面分析
需要的界面:
注册界面 登录界面 登录后的主界面 查找/添加好友界面 聊天界面 系统消息界面 个人设置界面
头像列表界面
需求分析——辅助类分析
需要添加的辅助类:
DBHelper类 UserHelper 类
小组分工
4
4 4 4 4
软件开发流程
比尔盖子是一名建筑工人 起初只干一些比较简单的 建筑工作 凭个人技术和经验,不需要特 别设计,可以顺利完成
如同编写早期比较小的程序
软件开发流程
新任务:建造一间非常美 丽而完整的房间 工作变得复杂许多
像不断发展的软件,功能 越来越多,越来越复杂
软件开发流程
软件复杂性
图形用户界面 客户/服务器结构 分布式应用 数据通信 超大型关系型数据库
// 判断 ListView 中是否有选中的项 if (lvFaces.SelectedItems.Count == 0) { // … } // 获得选中的头像的索引 int faceId = lvFaces.SelectedItems[0].ImageIndex;
第四次集中编码:A任务
个人信息修改功能
第一次集中编码:难点分析
好友列表——第三方控件 SideBar
SbGroup 类型 Items 属性 Groups 属性 SbItem 类型
第一次集中编码:难点分析
SideBar
// 命名空间 using Aptech.UI; // 添加组 sbFriends.AddGroup("我的好友"); sbFriends.AddGroup("陌生人"); 显示的文字 // 添加项 SbItem item = new SbItem((string)dataReader["NickName"], (int)dataReader["FaceId"]); sbFriends.Groups[0].Items.Add(item); 显示的图像索引
51Aspx源码必读

║ 5) 商业源码请在源码授权范围内进行使用! ║
║ ║
2.数据库:有很多朋友问数据库怎么弄,实际上截至GG的目前版本,还没有用到数据库,所有的信息都只是在内存中,所以,目前版本的GG做了一些假设:
(1)用户登录帐号随意,但必须为数字组;密码可随意输入。
(2)所有的在线用户都是好友。
3.麦克风、摄像头以及扬声器的选择可在配置文件中指定相应的Index。
GG叽叽(QQ高仿)源码
源码描述:
GG是QQ的高仿版,包括客户端和服务端,可在广域网部署使用
GG的前面几个版本开发了一些比较高级的功能,像视频聊天、远程桌面、文件传送、远程磁盘等,但是,有一些基础且必需的功能一直未实现,比如注册、添加好友、加入群、群聊天等等。经常有朋友留言问这些功能要怎么做,GG3.0终于可以给出一个答案了。
║ ║
║51Aspx声明: ║
║ 1) 本站不保证所提供软件或程序的完整性和安全性。 ║
║ 51Aspx —— .Net源码服务专家 ║
║ 联系方式 : support@ ║
║ ╭──────────────────────╮ ║
╭══════┤ ├══════╮
║ ║ 论坛: ║ ║
║ ╰═══════════════╯ ║
4.语音视频:也有很多朋友问语音视频设备的工作怎么不正常,或者语音视频不流畅,这个可以直接参考OMCS官方文档:摄像头、麦克风、扬声器、设备测试 、带宽要求。
5.GG使用了最新版本的SkinForm,如果有关于SkinForm的问题,可以直接联系我的好友 威廉乔克斯_汀。
6.特别说明一下:GG项目中,只要是我写的代码,全部都放出来了。拜托喜欢每一个dll都有源码的朋友不要再问我要其它的源码了:)
qq源代码

UserHelper..cs类代码using System;using System.Collections.Generic;using System.Text;namespace MyQQ{//记录登录的用户Idclass UserHelper{public static int loginId; //登录的用户Id}}using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace MyQQ{///<summary>///聊天窗体///</summary>public partial class ChatForm : Form{public int friendId; // 当前聊天的好友号码public string nickName; // 当前聊天的好友昵称public int faceId; // 当前聊天的好友头像Idpublic ChatForm(){InitializeComponent();}// 窗体加载时的动作private void ChatForm_Load(object sender, EventArgs e){// 设置窗体标题this.Text = string.Format("与{0}聊天中",nickName);// 设置窗体顶部显示的好友信息picFace.Image = ilFaces.Images[faceId];lblFriend.Text = string.Format("{0}({1})",nickName,friendId);// 读取所有的未读消息,显示在窗体中ShowMessage();}// 关闭窗体private void btnClose_Click(object sender, EventArgs e){this.Close();}// 发送消息private void btnSend_Click(object sender, EventArgs e){if (txtChat.Text.Trim() == "") // 不能发送空消息{MessageBox.Show("不能发送空消息!", "提示", MessageBoxButtons.OK, rmation);return;}else if (txtChat.Text.Trim().Length > 50){MessageBox.Show("消息内容过长,请分为几条发送!", "提示", MessageBoxButtons.OK, rmation);return;}else// 发送消息,写入数据库{// MessageTypeId:1-表示聊天消息,为简化操作没有读取数据表,到S2可以用常量或者枚举实现// MessageState:0-表示消息状态是未读int result = -1; // 表示操作数据库的结果string sql = string.Format("INSERT INTO Messages (FromUserId, ToUserId, Message, MessageTypeId,MessageState) VALUES ({0},{1},'{2}',{3},{4})",UserHelper.loginId, friendId, txtChat.Text.Trim(), 1, 0);try{// 执行命令SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();result = command.ExecuteNonQuery();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}if (result != 1){MessageBox.Show("服务器出现意外错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);}txtChat.Text = ""; // 输入消息清空this.Close();}}///<summary>///读取所有的未读消息,显示在窗体中///</summary>private void ShowMessage(){string messageIdsString = ""; // 消息的Id组成的字符串string message; // 消息内容string messageTime; // 消息发出的时间// 读取消息的SQL语句string sql = string.Format("SELECT Id, Message,MessageTime From Messages WHERE FromUserId={0} AND ToUserId={1} AND MessageTypeId=1 AND MessageState=0",friendId,UserHelper.loginId);try{SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader reader = command.ExecuteReader();// 循环将消息添加到窗体上while (reader.Read()){messageIdsString += Convert.ToString(reader["Id"]) + "_";message = Convert.ToString(reader["Message"]);messageTime = Convert.ToDateTime(reader["MessageTime"]).ToString(); // 转换为日期类型,告诉学员lblMessages.Text += string.Format("\n{0} {1}\n{2}",nickName,messageTime,message);}reader.Close();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 把显示出的消息置为已读if (messageIdsString.Length > 1){messageIdsString.Remove(messageIdsString.Length - 1);SetMessageRead(messageIdsString, '_');}}///<summary>///把显示出的消息置为已读///</summary>private void SetMessageRead(string messageIdsString, char separator){string[] messageIds = messageIdsString.Split(separator); // 分割出每个消息Idstring sql = "Update Messages SET MessageState=1 WHERE Id="; // 更新状态的SQL语句的固定部分string updateSql; // 执行的SQL语句try{SqlCommand command = new SqlCommand(); // 创建Command对象command.Connection = DBHelper.connection; // 指定数据库连接DBHelper.connection.Open(); // 打开数据库连接foreach (string id in messageIds){if (id != ""){updateSql = sql + id; // 补充完整的SQL语句 mandText = updateSql; // 指定要执行的SQL语句int result = command.ExecuteNonQuery(); // 执行命令}}}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}}ChatForm.cs代码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace MyQQ{///<summary>///聊天窗体///</summary>public partial class ChatForm : Form{public int friendId; // 当前聊天的好友号码public string nickName; // 当前聊天的好友昵称public int faceId; // 当前聊天的好友头像Idpublic ChatForm(){InitializeComponent();}// 窗体加载时的动作private void ChatForm_Load(object sender, EventArgs e){// 设置窗体标题this.Text = string.Format("与{0}聊天中",nickName);// 设置窗体顶部显示的好友信息picFace.Image = ilFaces.Images[faceId];lblFriend.Text = string.Format("{0}({1})",nickName,friendId);// 读取所有的未读消息,显示在窗体中ShowMessage();}// 关闭窗体private void btnClose_Click(object sender, EventArgs e){this.Close();}// 发送消息private void btnSend_Click(object sender, EventArgs e){if (txtChat.Text.Trim() == "") // 不能发送空消息{MessageBox.Show("不能发送空消息!", "提示", MessageBoxButtons.OK, rmation);return;}else if (txtChat.Text.Trim().Length > 50){MessageBox.Show("消息内容过长,请分为几条发送!", "提示", MessageBoxButtons.OK, rmation);return;}else// 发送消息,写入数据库{// MessageTypeId:1-表示聊天消息,为简化操作没有读取数据表,到S2可以用常量或者枚举实现// MessageState:0-表示消息状态是未读int result = -1; // 表示操作数据库的结果string sql = string.Format("INSERT INTO Messages (FromUserId, ToUserId, Message, MessageTypeId, MessageState) VALUES ({0},{1},'{2}',{3},{4})",UserHelper.loginId, friendId, txtChat.Text.Trim(), 1, 0);try{// 执行命令SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();result = command.ExecuteNonQuery();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}if (result != 1){MessageBox.Show("服务器出现意外错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);}txtChat.Text = ""; // 输入消息清空this.Close();}}///<summary>///读取所有的未读消息,显示在窗体中///</summary>private void ShowMessage(){string messageIdsString = ""; // 消息的Id组成的字符串string message; // 消息内容string messageTime; // 消息发出的时间// 读取消息的SQL语句string sql = string.Format("SELECT Id, Message,MessageTime From Messages WHERE FromUserId={0} AND ToUserId={1} AND MessageTypeId=1 AND MessageState=0",friendId,UserHelper.loginId);try{SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader reader = command.ExecuteReader();// 循环将消息添加到窗体上while (reader.Read()){messageIdsString += Convert.ToString(reader["Id"]) + "_";message = Convert.ToString(reader["Message"]);messageTime = Convert.ToDateTime(reader["MessageTime"]).ToString(); // 转换为日期类型,告诉学员lblMessages.Text += string.Format("\n{0} {1}\n{2}",nickName,messageTime,message);}reader.Close();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 把显示出的消息置为已读if (messageIdsString.Length > 1){messageIdsString.Remove(messageIdsString.Length - 1);SetMessageRead(messageIdsString, '_');}}///<summary>///把显示出的消息置为已读///</summary>private void SetMessageRead(string messageIdsString, char separator){string[] messageIds = messageIdsString.Split(separator); // 分割出每个消息Idstring sql = "Update Messages SET MessageState=1 WHERE Id="; // 更新状态的SQL语句的固定部分string updateSql; // 执行的SQL语句try{SqlCommand command = new SqlCommand(); // 创建Command对象command.Connection = DBHelper.connection; // 指定数据库连接DBHelper.connection.Open(); // 打开数据库连接foreach (string id in messageIds){if (id != ""){updateSql = sql + id; // 补充完整的SQL语句 mandText = updateSql; // 指定要执行的SQL语句int result = command.ExecuteNonQuery(); // 执行命令}}}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}}private void lblMessages_Click(object sender, EventArgs e){}}}DBHelper.cs类代码using System;using System.Collections.Generic;using System.Text;using System.Data.SqlClient;namespace MyQQ{// 数据库帮助类,维护数据库连接字符串和数据库连接对象class DBHelper{private static string connString = "Data Source=.;database=MyQQ;integrated security=sspi";public static SqlConnection connection = new SqlConnection(connString);}}using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace MyQQ{///<summary>///头像选择窗体///</summary>public partial class FacesForm : Form{public PersonalInfoForm personalInfoForm; // 个人信息窗体public FacesForm(){InitializeComponent();}1.FacesForm.cs代码private void FacesForm_Load(object sender, EventArgs e){for (int i = 0; i < ilFaces.Images.Count; i++){lvFaces.Items.Add(i.ToString());lvFaces.Items[i].ImageIndex = i;}}// 确定选择头像private void btnOK_Click(object sender, EventArgs e){if (lvFaces.SelectedItems.Count == 0){MessageBox.Show("请选择一个头像!", "提示", MessageBoxButtons.OK, rmation);}else{int faceId = lvFaces.SelectedItems[0].ImageIndex; // 获得当前选中的头像的索引personalInfoForm.ShowFace(faceId); // 设置个人信息窗体中显示的头像this.Close();}}// 双击时选择头像private void lvIcons_MouseDoubleClick(object sender, MouseEventArgs e){int faceId = lvFaces.SelectedItems[0].ImageIndex; // 获得当前选中的头像的索引 personalInfoForm.ShowFace(faceId); // 设置个人信息窗体中显示的头像this.Close();}// 关闭窗体private void btnCancel_Click(object sender, EventArgs e){this.Close();}}}LoginForm.csusing System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace MyQQ{///<summary>///登录窗体///</summary>public partial class LoginForm : Form{public LoginForm(){InitializeComponent();}// 取消按钮的事件处理private void btnCancel_Click(object sender, EventArgs e){Application.Exit();}// 打开申请号码界面private void llbl_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {RegisterForm registerForm = new RegisterForm();registerForm.Show();}// 登录按钮事件处理private void btnLogin_Click(object sender, EventArgs e){bool error = false; // 标志在执行数据库操作的过程中是否出错// 如果输入验证成功,就验证身份,并转到相应的窗体if (ValidateInput()){int num = 0; // 数据库操作结果try{// 查询用的sql语句string sql = string.Format("SELECT COUNT(*) FROM Users WHERE Id={0} AND LoginPwd = '{1}'",int.Parse(txtLoginId.Text.Trim()), txtLoginPwd.Text.Trim());// 创建Command 对象SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open(); // 打开数据库连接num = Convert.ToInt32(command.ExecuteScalar());}catch (Exception ex){error = true;Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close(); // 关闭数据库连接}if (!error && (num == 1)) // 验证通过{// 设置登录的用户号码UserHelper.loginId = int.Parse(txtLoginId.Text.Trim());// 创建主窗体MainForm mainForm = new MainForm();mainForm.Show(); // 显示窗体this.Visible = false; // 当前窗体不可见}else{MessageBox.Show("输入的用户名或密码有误!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);}}}// 忘记密码标签private void llblFogetPwd_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) {MessageBox.Show("该功能尚未开通!","提示",MessageBoxButtons.OK,rmation);}// 用户输入验证private bool ValidateInput(){// 验证用户输入if (txtLoginId.Text.Trim() == ""){MessageBox.Show("请输入登录的号码", "登录提示", MessageBoxButtons.OK, rmation);txtLoginId.Focus();return false;}else if (txtLoginPwd.Text.Trim() == ""){MessageBox.Show("请输入密码", "登录提示", MessageBoxButtons.OK, rmation);txtLoginPwd.Focus();return false;}return true;}}}MainForm.csusing System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using Aptech.UI;using System.Data.SqlClient;using System.Media;namespace MyQQ{///<summary>///登录后的主窗体///</summary>public partial class MainForm : Form{int fromUserId; // 消息的发起者int friendFaceId; // 发消息的好友的头像Idint messageImageIndex = 0; // 工具栏中的消息图标的索引public MainForm(){InitializeComponent();}// 窗体加载时发生private void MainForm_Load(object sender, EventArgs e) {// 工具栏的消息图标tsbtnMessageReading.Image = ilMessage.Images[0];// 显示个人的信息ShowSelfInfo();// 添加SideBar 的两个组sbFriends.AddGroup("我的好友");sbFriends.AddGroup("陌生人");// 向我的好友组中添加我的好友列表ShowFriendList();}// 窗体关闭后,退出应用程序private void MainForm_FormClosed(object sender, FormClosedEventArgs e) {Application.Exit();}// 显示个人信息窗体private void tsbtnPersonalInfo_Click(object sender, EventArgs e){PersonalInfoForm personalInfoForm = new PersonalInfoForm();personalInfoForm.mainForm = this; // 将当前窗体本身传给个人信息窗体 personalInfoForm.Show();}// 显示查找好友窗体private void tsbtnSearchFriend_Click(object sender, EventArgs e){SearchFriendForm searchFriendForm = new SearchFriendForm();searchFriendForm.Show();}// 双击一项,弹出聊天窗体private void sbFriends_ItemDoubleClick(SbItemEventArgs e){// 消息timer停止运行if (tmrChatRequest.Enabled == true){tmrChatRequest.Stop();e.Item.ImageIndex = this.friendFaceId;}// 显示聊天窗体ChatForm chatForm = new ChatForm();chatForm.friendId = Convert.ToInt32(e.Item.Tag); // 号码chatForm.nickName = e.Item.Text; // 昵称chatForm.faceId = e.Item.ImageIndex; // 头像chatForm.Show();}// 点击刷新好友列表private void tsbtnUpdateFriendList_Click(object sender, EventArgs e){ShowFriendList();}// 定时扫描数据库,找到未读消息private void tmrMessage_Tick(object sender, EventArgs e){ShowFriendList(); // 刷新好友列表int messageTypeId = 1; // 消息类型int messageState = 1; // 消息状态// 找出未读消息对应的好友Idstring sql = string.Format("SELECT Top 1 FromUserId, MessageTypeId, MessageState FROM Messages WHERE ToUserId={0} AND MessageState=0", UserHelper.loginId);SqlCommand command;// 消息有两种类型:聊天消息、添加好友消息try{command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader dataReader = command.ExecuteReader();// 循环读出一个未读消息if (dataReader.Read()){this.fromUserId = (int)dataReader["FromUserId"];messageTypeId = (int)dataReader["MessageTypeId"];messageState = (int)dataReader["MessageState"];}dataReader.Close();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 判断消息类型,如果是添加好友消息,就启动喇叭timer,让小喇叭闪烁if (messageTypeId == 2 && messageState == 0){SoundPlayer player = new SoundPlayer("system.wav");player.Play();tmrAddFriend.Start();}// 如果是聊天消息,就启动聊天timer,让好友头像闪烁else if (messageTypeId == 1 && messageState == 0){// 获得发消息的人的头像Idsql = "SELECT FaceId FROM Users WHERE Id=" + this.fromUserId;try{command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();this.friendFaceId = Convert.ToInt32(command.ExecuteScalar()); // 设置发消息的好友的头像索引}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 如果发消息的人没有在列表中就添加到陌生人列表中if (!HasShowUser(fromUserId)){UpdateStranger(fromUserId);}SoundPlayer player = new SoundPlayer("msg.wav");player.Play();tmrChatRequest.Start(); // 启动闪烁头像定时器}}// 控制喇叭闪烁private void tmrAddFriend_Tick(object sender, EventArgs e){// 反复修改它的图像messageImageIndex = messageImageIndex == 0 ? 1:0;tsbtnMessageReading.Image = ilMessage.Images[messageImageIndex];}// 单击时显示请求好友消息窗体private void tsbtnMessageReading_Click(object sender, EventArgs e){tmrAddFriend.Stop(); // 消息timer停止运行// 图片恢复正常messageImageIndex = 0;tsbtnMessageReading.Image = ilMessage.Images[messageImageIndex];// 显示系统消息窗体RequestForm requestForm = new RequestForm();requestForm.Show();}// 让相应的好友头像闪烁private void tmrChatRequest_Tick(object sender, EventArgs e){// 循环好友列表两个组中的每个item,找到发消息的好友,让他的头像闪烁for (int i = 0; i < 2; i++){for (int j = 0; j < sbFriends.Groups[i].Items.Count; j++){if(Convert.ToInt32(sbFriends.Groups[i].Items[j].Tag) == this.fromUserId) {if (sbFriends.Groups[i].Items[j].ImageIndex < 100){sbFriends.Groups[i].Items[j].ImageIndex = 100;// 索引为的图片是一个空白图片}else{sbFriends.Groups[i].Items[j].ImageIndex = this.friendFaceId;}sbFriends.Invalidate(); // 重新绘制,只要告诉学生需要这句话才能正常闪烁头像就行}}}}// 显示右键菜单时,控制哪些菜单不可见private void cmsFriendList_Opening(object sender, CancelEventArgs e){// 如果没有选中的项if (sbFriends.SeletedItem == null){tsmiDelete.Visible = false;}else{tsmiDelete.Visible = true;}// 如果选中的是陌生人,显示加为好友菜单if (sbFriends.SeletedItem != null && sbFriends.SeletedItem.Parent == sbFriends.Groups[1]){tsmiAddFriend.Visible = true;}else{tsmiAddFriend.Visible = false;}}// 显示大、小头像视图切换private void tsmiView_Click(object sender, EventArgs e){if (sbFriends.View == rgeIcon){sbFriends.View = SbView.SmallIcon;tsmiView.Text = "显示大头像";}else if (sbFriends.View == SbView.SmallIcon){sbFriends.View = rgeIcon;tsmiView.Text = "显示小头像";}}// 删除好友private void tsmiDelete_Click(object sender, EventArgs e){DialogResult result; // 对话框结果int deleteResult = 0; // 操作结果if (sbFriends.SeletedItem != null){result = MessageBox.Show("确实要删除该好友吗?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);if (result == DialogResult.Yes) // 确认删除{if (sbFriends.VisibleGroup == sbFriends.Groups[0]){string sql = string.Format("DELETE FROM Friends WHERE HostId={0} AND FriendId={1}",UserHelper.loginId, Convert.ToInt32(sbFriends.SeletedItem.Tag));try{SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();deleteResult = command.ExecuteNonQuery();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}if (deleteResult == 1){MessageBox.Show("好友已删除", "提示", MessageBoxButtons.OK, rmation);sbFriends.SeletedItem.Parent.Items.Remove(sbFriends.SeletedItem);}}else{MessageBox.Show("好友已删除", "提示", MessageBoxButtons.OK, rmation);sbFriends.SeletedItem.Parent.Items.Remove(sbFriends.SeletedItem);}}}}// 将选中的人加为好友private void tsmiAddFriend_Click(object sender, EventArgs e){int result = 0; // 操作结果string sql = string.Format("INSERT INTO Friends (HostId, FriendId) VALUES({0},{1})",UserHelper.loginId, Convert.ToInt32(sbFriends.SeletedItem.Tag));try{SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();result = command.ExecuteNonQuery();}catch (Exception ex){Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}if (result == 1){MessageBox.Show("添加成功!", "提示", MessageBoxButtons.OK, rmation);sbFriends.SeletedItem.Parent.Items.Remove(sbFriends.SeletedItem);ShowFriendList(); // 更新好友列表}else{MessageBox.Show("添加失败,请稍候再试!", "提示", MessageBoxButtons.OK, rmation);}}// 退出private void tsbtnExit_Click(object sender, EventArgs e){DialogResult result = MessageBox.Show("确实要退出吗?", "操作确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);if (result == DialogResult.Yes){Application.Exit();}}// 可见组发生变化时,发出声音private void sbFriends_VisibleGroupChanged(SbGroupEventArgs e){SoundPlayer player = new SoundPlayer("folder.wav");player.Play();}///<summary>///登录后显示个人的信息///</summary>public void ShowSelfInfo(){string nickName = ""; // 昵称int faceId = 0; // 头像索引bool error = false; // 标识是否出现错误// 取得当前用户的昵称、头像string sql = string.Format("SELECT NickName, FaceId FROM Users WHERE Id={0}",UserHelper.loginId);try{// 查询SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader dataReader = command.ExecuteReader();if (dataReader.Read()){if (!(dataReader["NickName"] is DBNull)) // 判断数据库类型是否为空 {nickName = Convert.ToString(dataReader["NickName"]);}faceId = Convert.ToInt32(dataReader["FaceId"]);}dataReader.Close();}catch (Exception ex){error = true;Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 根据操作数据库结果进行不同的操作if (error){MessageBox.Show("服务器请求失败!请重新登录!", "意外错误", MessageBoxButtons.OK, MessageBoxIcon.Error);Application.Exit();}else{// 在窗体标题显示登录的昵称、号码this.Text = UserHelper.loginId.ToString();this.picFace.Image = ilFaces.Images[faceId];this.lblLoginId.Text = string.Format("{0}({1})", nickName,UserHelper.loginId.ToString());}}///<summary>///向我的好友组中添加我的好友列表///</summary>private void ShowFriendList(){// 清空原来的列表sbFriends.Groups[0].Items.Clear();bool error = false; // 标识数据库是否出错// 查找有哪些好友string sql = string.Format("SELECT FriendId,NickName,FaceId FROM Users,Friends WHERE Friends.HostId={0} AND Users.Id=Friends.FriendId",UserHelper.loginId);try{// 执行查询SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader dataReader = command.ExecuteReader();// 循环添加好友列表while (dataReader.Read()){// 创建一个SideBar项SbItem item = new SbItem((string)dataReader["NickName"], (int)dataReader["FaceId"]);item.Tag = (int)dataReader["FriendId"]; // 将号码放在Tag属性中// SideBar中的组可以通过数组的方式访问,按照添加的顺序索引从开始// Groups[0]表示SideBar中的第一个组,也就是“我的好友”组sbFriends.Groups[0].Items.Add(item); // 向SideBar的“我的好友”组中添加项 }dataReader.Close();}catch (Exception ex){error = true;Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 出错了if (error){MessageBox.Show("服务器发生意外错误!请尝试重新登录", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);Application.Exit();}}///<summary>///判断发消息的人是否在列表中///</summary>private bool HasShowUser(int loginId){bool find = false; // 表示是否在当前显示出的用户列表中找到了该用户// 循环SideBar 中的个组,寻找发消息的人是否在列表中for (int i = 0; i < 2; i++){for (int j = 0; j < sbFriends.Groups[i].Items.Count; j++){if (Convert.ToInt32(sbFriends.Groups[i].Items[j].Tag) == loginId){find = true;}}}return find;}///<summary>///更新陌生人列表///</summary>private void UpdateStranger(int loginId){// 选出这个人的基本信息string sql = "SELECT NickName, FaceId FROM Users WHERE Id=" + loginId;bool error = false; // 用来标识是否出现错误try{SqlCommand command = new SqlCommand(sql, DBHelper.connection);DBHelper.connection.Open();SqlDataReader dataReader = command.ExecuteReader(); // 查询if (dataReader.Read()){SbItem item = new SbItem((string)dataReader["NickName"],(int)dataReader["FaceId"]);item.Tag = this.fromUserId; // 将Id记录在Tag属性中sbFriends.Groups[1].Items.Add(item); // 向陌生人组中添加项}sbFriends.VisibleGroup = sbFriends.Groups[1]; // 设定陌生人组为可见组 }catch (Exception ex){error = true;Console.WriteLine(ex.Message);}finally{DBHelper.connection.Close();}// 出错了if (error){MessageBox.Show("服务器出现意外错误!", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);}}}}(资料素材和资料部分来自网络,供参考。
qq木马源代码 (2)

/************************************************************************/
/* 其它直接用IoCallDriver把IRP传到下一层驱动中 */
/************************************************************************/
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09, //normal
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69, 0x6F, 0x70, 0x5B, 0x5D, 0x0D, 0x00, 0x61, 0x73,
ULONG s_UpChar=0;
typedef struct _FILTER_DEVICE_EXTEN
{
PDEVICE_OBJECT pFilterDeviceObject;//过滤设备
PDEVICE_OBJECT pTagerDeviceObject;//绑定的设备对象
KSPIN_LOCK Lockspin;//调用时的保护锁
0x32, 0x33, 0x30, 0x2E,
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x09, //shift
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49, 0x4F, 0x50, 0x7B, 0x7D, 0x0D, 0x00, 0x41, 0x53,
高仿QQ截图程序C#源码

高仿QQ截图程序C#源码using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Threading;namespace _SCREEN_CAPTURE{public partial class FrmCapture : Form{public FrmCapture() {InitializeComponent();this.FormBorderStyle = FormBorderStyle.None;this.Location = new Point(0, 0);this.Size = new Size(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);this.TopMost = true;this.ShowInTaskbar = false;m_MHook = new MouseHook();this.FormClosing += (s, e) => { m_MHook.UnLoadHook(); this.DelResource(); };imageProcessBox1.MouseLeave += (s, e) => this.Cursor = Cursors.Default;//后期一些操作历史记录图层m_layer = new List<Bitmap>();}private void DelResource() {if (m_bmpLayerCurrent != null) m_bmpLayerCurrent.Dispose();if (m_bmpLayerShow != null) m_bmpLayerShow.Dispose();m_layer.Clear();imageProcessBox1.DeleResource();GC.Collect();}#region Propertiesprivate bool isCaptureCursor;/// <summary>/// 获取或设置是否捕获鼠标/// </summary>public bool IsCaptureCursor {get { return isCaptureCursor; }set { isCaptureCursor = value; }}/// <summary>/// 获取或设置是否显示图像信息/// </summary>public bool ImgProcessBoxIsShowInfo {get { return imageProcessBox1.IsShowInfo; }set { imageProcessBox1.IsShowInfo = value; }}/// <summary>/// 获取或设置操作框点的颜色/// </summary>public Color ImgProcessBoxDotColor {get { return imageProcessBox1.DotColor; }set { imageProcessBox1.DotColor = value; }}/// <summary>/// 获取或设置操作框边框颜色/// </summary>public Color ImgProcessBoxLineColor {get { return imageProcessBox1.LineColor; }set { imageProcessBox1.LineColor = value; }}/// <summary>/// 获取或设置放大图形的原始尺寸/// </summary>public Size ImgProcessBoxMagnifySize {get { return imageProcessBox1.MagnifySize; }set { imageProcessBox1.MagnifySize = value; }}/// <summary>/// 获取或设置放大图像的倍数/// </summary>public int ImgProcessBoxMagnifyTimes {get { return imageProcessBox1.MagnifyTimes; }set { imageProcessBox1.MagnifyTimes = value; }}#endregion//初始化参数private void InitMember() {panel1.Visible = false;panel2.Visible = false;panel1.BackColor = Color.White;panel2.BackColor = Color.White;panel1.Height = tBtn_Finish.Bottom + 3;panel1.Width = tBtn_Finish.Right + 3;panel2.Height = colorBox1.Height;panel1.Paint += (s, e) => e.Graphics.DrawRectangle(Pens.SteelBlue, 0, 0, panel1.Width - 1, panel1.Height - 1);panel2.Paint += (s, e) => e.Graphics.DrawRectangle(Pens.SteelBlue, 0, 0, panel2.Width - 1, panel2.Height - 1);tBtn_Rect.Click += new EventHandler(selectToolButton_Click);tBtn_Ellipse.Click += new EventHandler(selectToolButton_Click);tBtn_Arrow.Click += new EventHandler(selectToolButton_Click);tBtn_Brush.Click += new EventHandler(selectToolButton_Click);tBtn_Text.Click += new EventHandler(selectToolButton_Click);tBtn_Close.Click += (s, e) => this.Close();textBox1.BorderStyle = BorderStyle.None;textBox1.Visible = false;textBox1.ForeColor = Color.Red;colorBox1.ColorChanged += (s, e) => textBox1.ForeColor = e.Color;}private MouseHook m_MHook;private List<Bitmap> m_layer; //记录历史图层private bool m_isStartDraw;private Point m_ptOriginal;private Point m_ptCurrent;private Bitmap m_bmpLayerCurrent;private Bitmap m_bmpLayerShow;private void FrmCapture_Load(object sender, EventArgs e) {this.InitMember();imageProcessBox1.BaseImage = this.GetScreen();m_MHook.SetHook();m_MHook.MHookEvent += new MouseHook.MHookEventHandler(m_MHook_MHookEvent);imageProcessBox1.IsDrawOperationDot = false;this.BeginInvoke(new MethodInvoker(() => this.Enabled = false));timer1.Interval = 500;timer1.Enabled = true;}private void m_MHook_MHookEvent(object sender, MHookEventArgs e) {//如果窗体禁用调用控件的方法设置信息显示位置if (!this.Enabled) //貌似Hook不能精确坐标(Hook最先执行执执行完后的坐标可能与执行时传入的坐标发生了变化猜测是这样) 所以放置了一个timer检测imageProcessBox1.SetInfoPoint(MousePosition.X, MousePosition.Y);//鼠标点下恢复窗体禁用if (e.MButton == ButtonStatus.LeftDown || e.MButton == ButtonStatus.RightDown) {this.Enabled = true;imageProcessBox1.IsDrawOperationDot = true;}#region 在imageProcessBox_MouseUp中完成了//if (e.MButton == ButtonStatus.LeftUp) {// //if (imageProcessBox1.SelectedRectangle.Width < 5// // || imageProcessBox1.SelectedRectangle.Height < 5) {// // //如果选取区域不符要求向控件模拟鼠标抬起然后禁用窗体// // //(Hook事件先于控件事件禁用控件时模拟一个鼠标抬起)// // Win32.SendMessage(imageProcessBox1.Handle, Win32.WM_LBUTTONUP,// // IntPtr.Zero, (IntPtr)(MousePosition.Y << 16 | MousePosition.X));// // this.Enabled = false;// // imageProcessBox1.IsDrawOperationDot = false;// //} else// // this.SetToolBarLocation(); //重置工具条位置//}#endregion#region 右键抬起if (e.MButton == ButtonStatus.RightUp) {if (!imageProcessBox1.IsDrawed) //没有绘制那么退出(直接this.Close右键将传递到下面)this.BeginInvoke(new MethodInvoker(() => this.Close()));//有绘制的情况情况继续禁用窗体this.Enabled = false;imageProcessBox1.ClearDraw();imageProcessBox1.CanReset = true;imageProcessBox1.IsDrawOperationDot = false;m_layer.Clear(); //清空历史记录m_bmpLayerCurrent = null;m_bmpLayerShow = null;ClearToolBarBtnSelected();panel1.Visible = false;panel2.Visible = false;}#endregion#region 找寻窗体if (!this.Enabled) {this.FoundAndDrawWindowRect();}#endregion}//工具条前五个按钮绑定的公共事件private void selectToolButton_Click(object sender, EventArgs e) {panel2.Visible = ((ToolButton)sender).IsSelected;if (panel2.Visible) imageProcessBox1.CanReset = false;else { imageProcessBox1.CanReset = m_layer.Count == 0; }this.SetToolBarLocation();}#region 截图后的一些后期绘制private void imageProcessBox1_MouseDown(object sender, MouseEventArgs e) { if (imageProcessBox1.Cursor != Cursors.SizeAll &&imageProcessBox1.Cursor != Cursors.Default)panel1.Visible = false; //表示改变选取大小隐藏工具条//若果在选取类点击并且有选择工具if (e.Button == MouseButtons.Left && imageProcessBox1.IsDrawed && HaveSelectedToolButton()) {if (imageProcessBox1.SelectedRectangle.Contains(e.Location)) {if (tBtn_Text.IsSelected) { //如果选择的是绘制文本弹出文本框textBox1.Location = e.Location;textBox1.Visible = true;textBox1.Focus();return;}m_isStartDraw = true;Cursor.Clip = imageProcessBox1.SelectedRectangle;}}m_ptOriginal = e.Location;}private void imageProcessBox1_MouseMove(object sender, MouseEventArgs e) { m_ptCurrent = e.Location;//根据是否选择有工具决定鼠标指针样式if (imageProcessBox1.SelectedRectangle.Contains(e.Location) && HaveSelectedToolButton() && imageProcessBox1.IsDrawed)this.Cursor = Cursors.Cross;else if (!imageProcessBox1.SelectedRectangle.Contains(e.Location))this.Cursor = Cursors.Default;if (imageProcessBox1.IsStartDraw && panel1.Visible) //在重置选取的时候重置工具条位置(成立于移动选取的时候)this.SetToolBarLocation();if (m_isStartDraw && m_bmpLayerShow != null) { //如果在区域内点下那么绘制相应图形using (Graphics g = Graphics.FromImage(m_bmpLayerShow)) {int tempWidth = 1;if (toolButton2.IsSelected) tempWidth = 3;if (toolButton3.IsSelected) tempWidth = 5;Pen p = new Pen(colorBox1.SelectedColor, tempWidth);#region 绘制矩形if (tBtn_Rect.IsSelected) {int tempX = e.X - m_ptOriginal.X > 0 ? m_ptOriginal.X : e.X;int tempY = e.Y - m_ptOriginal.Y > 0 ? m_ptOriginal.Y : e.Y;g.Clear(Color.Transparent);g.DrawRectangle(p, tempX - imageProcessBox1.SelectedRectangle.Left, tempY - imageProcessBox1.SelectedRectangle.Top, Math.Abs(e.X - m_ptOriginal.X), Math.Abs(e.Y - m_ptOriginal.Y));imageProcessBox1.Invalidate();}#endregion#region 绘制圆形if (tBtn_Ellipse.IsSelected) {g.DrawLine(Pens.Red, 0, 0, 200, 200);g.Clear(Color.Transparent);g.DrawEllipse(p, m_ptOriginal.X - imageProcessBox1.SelectedRectangle.Left, m_ptOriginal.Y - imageProcessBox1.SelectedRectangle.Top, e.X - m_ptOriginal.X, e.Y - m_ptOriginal.Y);imageProcessBox1.Invalidate();}#endregion#region 绘制箭头if (tBtn_Arrow.IsSelected) {g.Clear(Color.Transparent);System.Drawing.Drawing2D.AdjustableArrowCap lineArrow =new System.Drawing.Drawing2D.AdjustableArrowCap(4, 4, true);p.CustomEndCap = lineArrow;g.DrawLine(p, (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location), (Point)((Size)m_ptCurrent - (Size)imageProcessBox1.SelectedRectangle.Location));imageProcessBox1.Invalidate();}#endregion#region 绘制线条if (tBtn_Brush.IsSelected) {Point ptTemp = (Point)((Size)m_ptOriginal - (Size)imageProcessBox1.SelectedRectangle.Location);p.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;g.DrawLine(p, ptTemp, (Point)((Size)e.Location - (Size)imageProcessBox1.SelectedRectangle.Location));m_ptOriginal = e.Location;imageProcessBox1.Invalidate();}#endregionp.Dispose();}}}private void imageProcessBox1_MouseUp(object sender, MouseEventArgs e) { if (!imageProcessBox1.IsDrawed) { //如果没有成功绘制选取继续禁用窗体this.Enabled = false;imageProcessBox1.IsDrawOperationDot = false;} else if (!panel1.Visible) { //否则显示工具条this.SetToolBarLocation(); //重置工具条位置panel1.Visible = true;m_bmpLayerCurrent = imageProcessBox1.GetResultBmp(); //获取选取图形m_bmpLayerShow = new Bitmap(m_bmpLayerCurrent.Width, m_bmpLayerCurrent.Height);}//如果移动了选取位置重新获取选取的图形if (imageProcessBox1.Cursor == Cursors.SizeAll && m_ptOriginal != e.Location) m_bmpLayerCurrent = imageProcessBox1.GetResultBmp();if (!m_isStartDraw) return;Cursor.Clip = Rectangle.Empty;m_isStartDraw = false;if (e.Location == m_ptOriginal && !tBtn_Brush.IsSelected) return;this.SetLayer(); //将绘制的图形绘制到历史图层中}//绘制后期操作private void imageProcessBox1_Paint(object sender, PaintEventArgs e) {Graphics g = e.Graphics;if (m_layer.Count > 0) //绘制保存的历史记录的最后一张图g.DrawImage(m_layer[m_layer.Count - 1], imageProcessBox1.SelectedRectangle.Location);if (m_bmpLayerShow != null) //绘制当前正在拖动绘制的图形(即鼠标点下还没有抬起确认的图形)g.DrawImage(m_bmpLayerShow,imageProcessBox1.SelectedRectangle.Location);}#endregion//文本改变时重置文本框大小private void textBox1_TextChanged(object sender, EventArgs e) {Size se = TextRenderer.MeasureText(textBox1.Text, textBox1.Font);textBox1.Size = se.IsEmpty ? new Size(50, textBox1.Font.Height) : se;}//文本框失去焦点时绘制文本private void textBox1_Validating(object sender, CancelEventArgs e) {textBox1.Visible = false;if (string.IsNullOrEmpty(textBox1.Text.Trim())) { textBox1.Text = ""; return; }using (Graphics g = Graphics.FromImage(m_bmpLayerCurrent)) {SolidBrush sb = new SolidBrush(colorBox1.SelectedColor);g.DrawString(textBox1.Text, textBox1.Font, sb,textBox1.Left - imageProcessBox1.SelectedRectangle.Left,textBox1.Top - imageProcessBox1.SelectedRectangle.Top);sb.Dispose();textBox1.Text = "";this.SetLayer(); //将文本绘制到当前图层并存入历史记录imageProcessBox1.Invalidate();}}//窗体大小改变时重置字体从控件中获取字体大小private void textBox1_Resize(object sender, EventArgs e) {//在三个大小选择的按钮点击中设置字体大小太麻烦所以Resize中获取设置int se = 10;if (toolButton2.IsSelected) se = 12;if (toolButton3.IsSelected) se = 14;if (this.textBox1.Font.Height == se) return;textBox1.Font = new Font(this.Font.FontFamily, se);}//撤销private void tBtn_Cancel_Click(object sender, EventArgs e) {using (Graphics g = Graphics.FromImage(m_bmpLayerShow)) {g.Clear(Color.Transparent); //情况当前临时显示的图像}if (m_layer.Count > 0) { //删除最后一层m_layer.RemoveAt(m_layer.Count - 1);if (m_layer.Count > 0)m_bmpLayerCurrent = m_layer[m_layer.Count - 1].Clone(new Rectangle(0, 0, m_bmpLayerCurrent.Width, m_bmpLayerCurrent.Height), m_bmpLayerCurrent.PixelFormat);elsem_bmpLayerCurrent = imageProcessBox1.GetResultBmp();imageProcessBox1.Invalidate();imageProcessBox1.CanReset = m_layer.Count == 0 && !HaveSelectedToolButton();} else { //如果没有历史记录则取消本次截图this.Enabled = false;imageProcessBox1.ClearDraw();imageProcessBox1.IsDrawOperationDot = false;panel1.Visible = false;panel2.Visible = false;}}private void tBtn_Save_Click(object sender, EventArgs e) {SaveFileDialog saveDlg = new SaveFileDialog();saveDlg.Filter = "位图(*.bmp)|*.bmp|JPEG(*.jpg)|*.jpg";saveDlg.FilterIndex = 1;saveDlg.FileName = "CAPTURE_" + GetTimeString();if (saveDlg.ShowDialog() == DialogResult.OK) {switch (saveDlg.FilterIndex) {case 1:m_bmpLayerCurrent.Clone(new Rectangle(0, 0, m_bmpLayerCurrent.Width, m_bmpLayerCurrent.Height),System.Drawing.Imaging.PixelFormat.Format24bppRgb).Save(saveDlg.FileName,System.Drawing.Imaging.ImageFormat.Bmp);this.Close();break;case 2:m_bmpLayerCurrent.Save(saveDlg.FileName,System.Drawing.Imaging.ImageFormat.Jpeg);this.Close();break;}}}//将图像保存到剪贴板private void tBtn_Finish_Click(object sender, EventArgs e) {Clipboard.SetImage(m_bmpLayerCurrent);this.Close();}private void imageProcessBox1_DoubleClick(object sender, EventArgs e) {Clipboard.SetImage(m_bmpLayerCurrent);this.Close();}private void timer1_Tick(object sender, EventArgs e) {if (!this.Enabled)imageProcessBox1.SetInfoPoint(MousePosition.X, MousePosition.Y);}//根据鼠标位置找寻窗体平绘制边框private void FoundAndDrawWindowRect() {Win32.LPPOINT pt = new Win32.LPPOINT();pt.X = MousePosition.X; pt.Y = MousePosition.Y;IntPtr hWnd = Win32.ChildWindowFromPointEx(Win32.GetDesktopWindow(), pt, Win32.CWP_SKIPINVISIBL | Win32.CWP_SKIPDISABLED);if (hWnd != IntPtr.Zero) {IntPtr hTemp = hWnd;while (true) {Win32.ScreenToClient(hTemp, out pt);hTemp = Win32.ChildWindowFromPointEx(hTemp, pt, Win32.CWP_All);if (hTemp == IntPtr.Zero || hTemp == hWnd)break;hWnd = hTemp;pt.X = MousePosition.X; pt.Y = MousePosition.Y; //坐标还原为屏幕坐标}Win32.LPRECT rect = new Win32.LPRECT();Win32.GetWindowRect(hWnd, out rect);imageProcessBox1.SetSelectRect(new Rectangle(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top));}}//获取桌面图像private Bitmap GetScreen() {Bitmap bmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);if (this.isCaptureCursor) { //是否捕获鼠标//如果直接将捕获当的鼠标画在bmp上光标不会反色指针边框也很浓也就是说//尽管bmp上绘制了图像绘制鼠标的时候还是以黑色作为鼠标的背景然后在将混合好的鼠标绘制到图像会很别扭//所以干脆直接在桌面把鼠标绘制出来再截取桌面using (Graphics g = Graphics.FromHwnd(IntPtr.Zero)) { //传入0默认就是桌面Win32.GetDesktopWindow()也可以Win32.PCURSORINFO pci;pci.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(Win32.PCURSORINFO));Win32.GetCursorInfo(out pci);if (pci.hCursor != IntPtr.Zero) {Cursor cur = new Cursor(pci.hCursor);g.CopyFromScreen(0, 0, 0, 0, bmp.Size); //在桌面绘制鼠标前先在桌面绘制一下当前的桌面图像//如果不绘制当前桌面那么cur.Draw的时候会是用历史桌面的快照进行鼠标的混合那么到时候混出现底色(测试中就是这样的)cur.Draw(g, new Rectangle((Point)((Size)MousePosition - (Size)cur.HotSpot), cur.Size));}}}//做完以上操作才开始捕获桌面图像using (Graphics g = Graphics.FromImage(bmp)) {g.CopyFromScreen(0, 0, 0, 0, bmp.Size);}return bmp;}//设置工具条位置private void SetToolBarLocation() {int tempX = imageProcessBox1.SelectedRectangle.Left;int tempY = imageProcessBox1.SelectedRectangle.Bottom + 5;int tempHeight = panel2.Visible ? panel2.Height + 2 : 0;if (tempY + panel1.Height + tempHeight >= this.Height)tempY = imageProcessBox1.SelectedRectangle.Top - panel1.Height - 10 - imageProcessBox1.Font.Height;if (tempY - tempHeight <= 0) {if (imageProcessBox1.SelectedRectangle.Top - 5 - imageProcessBox1.Font.Height >= 0)tempY = imageProcessBox1.SelectedRectangle.Top + 5;elsetempY = imageProcessBox1.SelectedRectangle.Top + 10 + imageProcessBox1.Font.Height;}if (tempX + panel1.Width >= this.Width)tempX = this.Width - panel1.Width - 5;panel1.Left = tempX;panel2.Left = tempX;panel1.Top = tempY;panel2.Top = imageProcessBox1.SelectedRectangle.Top > tempY ? tempY - tempHeight : panel1.Bottom + 2;}//确定是否工具条上面有被选中的按钮private bool HaveSelectedToolButton() {return tBtn_Rect.IsSelected || tBtn_Ellipse.IsSelected|| tBtn_Arrow.IsSelected || tBtn_Brush.IsSelected|| tBtn_Text.IsSelected;}//清空选中的工具条上的工具private void ClearToolBarBtnSelected() {tBtn_Rect.IsSelected = tBtn_Ellipse.IsSelected = tBtn_Arrow.IsSelected =tBtn_Brush.IsSelected = tBtn_Text.IsSelected = false;}//设置历史图层private void SetLayer() {if (this.IsDisposed) return;using (Graphics g = Graphics.FromImage(m_bmpLayerCurrent)) {g.DrawImage(m_bmpLayerShow, 0, 0);}Bitmap bmpTemp = m_bmpLayerCurrent.Clone(new Rectangle(0, 0, m_bmpLayerCurrent.Width, m_bmpLayerCurrent.Height), m_bmpLayerCurrent.PixelFormat);m_layer.Add(bmpTemp);}//保存时获取当前时间字符串作文默认文件名private string GetTimeString() {DateTime time = DateTime.Now;return time.Date.ToShortDateString().Replace("/", "") + "_" +time.ToLongTimeString().Replace(":", "");}}}。
模仿QQ MFC 源码

登陆框.h#pragma once#include"afxcmn.h"#include"afxwin.h"// CLoginDlg 对话框class CLoginDlg : public CDialog{DECLARE_DYNAMIC(CLoginDlg)public:CLoginDlg(CWnd* pParent = NULL); // 标准构造函数virtual ~CLoginDlg();// 对话框数据enum { IDD = IDD_DIALOG_LOGIN };protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持DECLARE_MESSAGE_MAP()public:afx_msg void OnBnClickedOk();CString m_strUsername;CString m_strPassord;afx_msg void OnBnClickedButtonClose();afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnLButtonUp(UINT nFlags, CPoint point);afx_msg void OnMouseMove(UINT nFlags, CPoint point);private:BOOL m_bMoving;CPoint m_ptPreMove;public:CLinkCtrl m_cLinkRegister;CLinkCtrl m_cLinkFindpwd;static DWORD m_nIconID;//用于存放登录后托盘显示的图标afx_msg void OnNMClickSyslinkRegister(NMHDR *pNMHDR, LRESULT *pResult);afx_msg void OnNMClickSyslinkFindpwd(NMHDR *pNMHDR, LRESULT *pResult);virtual BOOL OnInitDialog();afx_msg void OnBnClickedButtonList();CButton m_btnList;afx_msg void OnPaint();afx_msg void OnOnlin();afx_msg void OnQme();afx_msg void OnLeave();afx_msg void OnBusy();afx_msg void OnDarao();afx_msg void OnYinshen();afx_msg LRESULT OnShowTask(WPARAM wParam, LPARAM lParam);void ToTray(BOOL Show);CButton m_btnJianPan;CButton m_btnConfig;CToolTipCtrl toolTipCtrl[3];NOTIFYICONDATA m_nid;virtual BOOL PreTranslateMessage(MSG* pMsg);afx_msg void Onshowwindow();afx_msg void OnOpenmainpanel();afx_msg void OnHideWindows();afx_msg void OnButtonClose();afx_msg void OnBnClickedButtonMin();afx_msg void OnBnClickedButtonJianpan();afx_msg void OnCbnSelchangeComboUsername();BOOL m_isRemPassword;afx_msg void OnBnClickedCheckSavepwd();BOOL m_isAutoLogin;afx_msg void OnBnClickedCheckAutologin();afx_msg void OnTimer(UINT_PTR nIDEvent);BOOL m_isFirstLoginAccount;//hj};登陆框.cpp// LoginDlg.cpp : 实现文件//#include"stdafx.h"#include"QQDemo.h"#include"LoginDlg.h"#include"RegisterDlg.h"#include"SeekDlg.h"#define WM_SHOWTASK WM_USER+1// CLoginDlg 对话框IMPLEMENT_DYNAMIC(CLoginDlg, CDialog)DWORD CLoginDlg::m_nIconID = IDI_IMONLINE;CLoginDlg::CLoginDlg(CWnd* pParent/*=NULL*/): CDialog(CLoginDlg::IDD, pParent), m_strUsername(_T("")), m_strPassord(_T("")), m_bMoving(FALSE), m_isRemPassword(TRUE), m_isAutoLogin(FALSE), m_isFirstLoginAccount(TRUE){}CLoginDlg::~CLoginDlg(){Shell_NotifyIcon(NIM_DELETE,&m_nid);//从托盘中删除}void CLoginDlg::DoDataExchange(CDataExchange* pDX){CDialog::DoDataExchange(pDX);DDX_CBString(pDX, IDC_COMBO_USERNAME, m_strUsername);DDX_Text(pDX, IDC_EDIT_PASSWORD, m_strPassord);DDX_Control(pDX, IDC_SYSLINK_REGISTER, m_cLinkRegister);DDX_Control(pDX, IDC_SYSLINK_FINDPWD, m_cLinkFindpwd);DDX_Control(pDX, IDC_BUTTON_LIST, m_btnList);DDX_Control(pDX, IDC_BUTTON_JIANPAN, m_btnJianPan);DDX_Control(pDX, IDC_BUTTON_CONFIG, m_btnConfig);DDX_Check(pDX, IDC_CHECK_SA VEPWD, m_isRemPassword);DDX_Check(pDX, IDC_CHECK_AUTOLOGIN, m_isAutoLogin);}BEGIN_MESSAGE_MAP(CLoginDlg, CDialog)ON_BN_CLICKED(IDOK, &CLoginDlg::OnBnClickedOk)ON_BN_CLICKED(IDC_BUTTON_CLOSE, &CLoginDlg::OnBnClickedButtonClose)ON_WM_LBUTTONDOWN()ON_WM_LBUTTONUP()ON_WM_MOUSEMOVE()ON_MESSAGE(WM_SHOWTASK, &CLoginDlg::OnShowTask)ON_NOTIFY(NM_CLICK, IDC_SYSLINK_REGISTER, &CLoginDlg::OnNMClickSyslinkRegister) ON_NOTIFY(NM_CLICK, IDC_SYSLINK_FINDPWD, &CLoginDlg::OnNMClickSyslinkFindpwd) ON_BN_CLICKED(IDC_BUTTON_LIST, &CLoginDlg::OnBnClickedButtonList)ON_WM_PAINT()ON_COMMAND(IDM_ONLIN, &CLoginDlg::OnOnlin)ON_COMMAND(IDM_QME, &CLoginDlg::OnQme)ON_COMMAND(IDM_LEA VE, &CLoginDlg::OnLeave)ON_COMMAND(IDM_BUSY, &CLoginDlg::OnBusy)ON_COMMAND(IDM_DARAO, &CLoginDlg::OnDarao)ON_COMMAND(IDM_YINSHEN, &CLoginDlg::OnYinshen)ON_COMMAND(ID_showWindow, &CLoginDlg::Onshowwindow)ON_COMMAND(IDC_BUTTON_CLOSE, &CLoginDlg::OnButtonClose)ON_COMMAND(1200,OnOpenmainpanel)ON_COMMAND(1201,OnHideWindows)ON_BN_CLICKED(IDC_BUTTON_MIN, &CLoginDlg::OnBnClickedButtonMin)ON_BN_CLICKED(IDC_BUTTON_JIANPAN, &CLoginDlg::OnBnClickedButtonJianpan)ON_CBN_SELCHANGE(IDC_COMBO_USERNAME, &CLoginDlg::OnCbnSelchangeComboUsername) ON_BN_CLICKED(IDC_CHECK_SA VEPWD, &CLoginDlg::OnBnClickedCheckSavepwd)ON_BN_CLICKED(IDC_CHECK_AUTOLOGIN, &CLoginDlg::OnBnClickedCheckAutologin)ON_WM_TIMER()END_MESSAGE_MAP()// CLoginDlg 消息处理程序void CLoginDlg::ToTray(BOOL Show){if(Show){UpdateData(TRUE);Shell_NotifyIcon(NIM_ADD,&m_nid); //放入托盘中ShowWindow(SW_HIDE); //隐藏主窗口}else{Shell_NotifyIcon(NIM_DELETE,&m_nid);//从托盘中删除}}//处理托盘的回调函数(也就是对托盘的一些消息响应如单击,右击,双击)LRESULT CLoginDlg::OnShowTask(WPARAM wParam, LPARAM lParam){switch(lParam){case WM_RBUTTONDOWN:{CRect rect;CPoint p;GetCursorPos(&p);CMenu menu;if(this->IsWindowVisible()){menu.CreatePopupMenu();menu.AppendMenu(MF_STRING,1201,_T("隐藏主面板"));menu.AppendMenu(MF_STRING,WM_DESTROY,_T("关闭"));menu.TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,this);}else{menu.CreatePopupMenu();menu.AppendMenu(MF_STRING,1200,_T("打开主面板"));menu.AppendMenu(MF_STRING,WM_DESTROY,_T("关闭"));menu.TrackPopupMenu(TPM_LEFTALIGN,p.x,p.y,this);}}break;case WM_LBUTTONDOWN:ShowWindow(SW_SHOW);break;}return 0;}void CLoginDlg::OnBnClickedOk(){UpdateData();BOOL isFind = FALSE;//判断是否已经找到密码CString temp;//存储格式化字符串if(m_strUsername == _T("")){MessageBox(_T("帐号不能为空!请重新输入!"));return;}if(m_strPassord == _T("")){MessageBox(_T("密码不能为空!请输入密码!"));return;}//判断该帐号是否已经注册(在qqData.ini文件中)//int nInqqdata;CString strAccountInqqData;CString strPasswordInqqData;int nCount=::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qqData.ini"));for(int i = 0;i < nCount;i++){temp.Format(_T("%d"),i + 1);::GetPrivateProfileString(_T("admin") + temp,_T("Account") + temp,m_strUsername, strAccountInqqData.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qqData.ini"));::GetPrivateProfileString(_T("admin") + temp,_T("Password") + temp,_T(""), strPasswordInqqData.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qqData.ini"));//如果账号,密码与配置文件中的数据一致则登录成功if (strAccountInqqData == m_strUsername){if(m_strPassord == strPasswordInqqData){isFind = TRUE;break;}}}if(!isFind){MessageBox(_T("账号或密码有错误,请确认后重新登录!"));return;}int bCount = ::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qq.ini"));CString strAccount;//存储本地读取文件中的账号CString strPassword;//存储本地文件中的密码CString strRemPassword;//存储配置文件中的记住密码状态CString strAutoLogin;//存储配置文件自动登录状态CString strLastLogin;//存储配置文件是否为上次登录状态BOOL isExistInqq=FALSE;//是否存在于本地的配置文件int nIndex;//帐号在配置文件中下标if (m_isRemPassword){strRemPassword = _T("1");}strRemPassword = _T("0");if (m_isAutoLogin){strAutoLogin = _T("1");}elsestrAutoLogin = _T("0");bCount++;//判断是否本地配置文件中已经存在该帐号的信息for (int i= 0;i < bCount;i++){nIndex=i + 1;temp.Format(_T("%d"),nIndex);::GetPrivateProfileString(_T("admin") + temp,_T("Account") + temp,_T(""), strAccount.GetBuffer(MAX_PA TH),MAX_PATH,_T(".\\qq.ini"));if(strAccount==m_strUsername){isExistInqq=TRUE;break;}}if (!isExistInqq){temp.Format(_T("%d"),bCount);::WritePrivateProfileString(_T("admin") +temp,_T("Account") + temp,m_strUsername,_T(".\\qq.ini"));//写入密码,当记住密码时为账户密码,否则密码为空if(m_isRemPassword){::WritePrivateProfileString(_T("admin") + temp,_T("Password") + temp,m_strPassord,_T(".\\qq.ini"));}else::WritePrivateProfileString(_T("admin") + temp,_T("Password") + temp,_T(""),_T(".\\qq.ini"));::WritePrivateProfileString(_T("admin") +temp,_T("isRemPassword") + temp,strRemPassword,_T(".\\qq.ini"));::WritePrivateProfileString(_T("admin") +temp,_T("isAutoLogin") + temp,strAutoLogin,_T(".\\qq.ini"));::WritePrivateProfileString(_T("FileCount"),_T("Count"),temp,_T(".\\qq.ini"));else{temp.Format(_T("%d"),nIndex);if(m_isRemPassword){::WritePrivateProfileString(_T("admin") + temp,_T("Password") + temp,m_strPassord,_T(".\\qq.ini"));}else::WritePrivateProfileString(_T("admin") + temp,_T("Password") + temp,_T(""),_T(".\\qq.ini"));::WritePrivateProfileString(_T("admin") + temp,_T("isRemPassword") + temp,strRemPassword,_T(".\\qq.ini"));::WritePrivateProfileString(_T("admin") + temp,_T("isAutoLogin") + temp,strAutoLogin,_T(".\\qq.ini"));}Shell_NotifyIcon(NIM_DELETE,&m_nid);//获得此时本地文件存在的帐号数目bCount = ::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qq.ini"));for(int i = 0;i < bCount;i++){temp.Format(_T("%d"),i + 1);::WritePrivateProfileString(_T("admin") + temp,_T("isLastLogin") + temp,_T("0"),_T(".\\qq.ini"));}//为现在这个帐号设置isLastLogin的值if (isExistInqq){temp.Format(_T("%d"),nIndex);::WritePrivateProfileString(_T("admin") + temp,_T("isLastLogin") + temp,_T("1"),_T(".\\qq.ini"));}else{temp.Format(_T("%d"),bCount);::WritePrivateProfileString(_T("admin") + temp,_T("isLastLogin") + temp,_T("1"),_T(".\\qq.ini"));}//对当前帐号的排名计数器设为,并写入本地配置文件中::WritePrivateProfileString(_T("admin") + temp,_T("Rank") + temp,_T("0"),_T(".\\qq.ini"));//遍历本地配置文件,除了本次登录的帐号外,其他帐号的排名计数都加for (int i = 0;i < bCount;i++){temp.Format(_T("%d"),i + 1);::GetPrivateProfileString(_T("admin") + temp,_T("isLastLogin") + temp,_T(""),strLastLogin.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));if (strLastLogin != _T("1")){int rank = GetPrivateProfileInt(_T("admin") + temp,_T("Rank") + temp,0,_T(".\\qq.ini"));rank++;CString strRank;strRank.Format(_T("%d"),rank);::WritePrivateProfileString(_T("admin") + temp,_T("Rank") + temp,strRank,_T(".\\qq.ini"));}}OnOK();}void CLoginDlg::OnLButtonDown(UINT nFlags, CPoint point){if (point.y <= 50){m_bMoving = TRUE;m_ptPreMove = point;ClientToScreen(&m_ptPreMove);//GetCapture();}CDialog::OnLButtonDown(nFlags, point);}void CLoginDlg::OnLButtonUp(UINT nFlags, CPoint point){m_bMoving = FALSE;CDialog::OnLButtonUp(nFlags, point);}void CLoginDlg::OnMouseMove(UINT nFlags, CPoint point){if (m_bMoving){CPoint ptTemp = point;ClientToScreen(&ptTemp);CPoint ptOffset = ptTemp - m_ptPreMove;m_ptPreMove = ptTemp;CRect rectWindow;GetWindowRect(&rectWindow);rectWindow += ptOffset;MoveWindow(&rectWindow);}CDialog::OnMouseMove(nFlags, point);}void CLoginDlg::OnNMClickSyslinkRegister(NMHDR *pNMHDR, LRESULT *pResult){// TODO: 在此添加控件通知处理程序代码//PNMLINK pNMLink = (PNMLINK)pNMHDR;//::ShellExecute(m_hWnd, _T("open"), pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);CRegisterDlg dlg;if(IDOK != dlg.DoModal())return;//把注册信息存入qqData注册表UpdateData();int nCount = ::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qqData.ini"));nCount++;CString temp;temp.Format(_T("%d"),nCount);::WritePrivateProfileString(_T("admin") + temp,_T("Account") + temp,dlg.m_Reg_strAccount,_T(".\\qqData.ini"));::WritePrivateProfileString(_T("admin") + temp,_T("Password") + temp,dlg.m_Reg_strPassword,_T(".\\qqData.ini"));::WritePrivateProfileString(_T("FileCount"),_T("Count"),temp,_T(".\\qqData.ini"));*pResult = 0;}void CLoginDlg::OnNMClickSyslinkFindpwd(NMHDR *pNMHDR, LRESULT *pResult){// TODO: 在此添加控件通知处理程序代码//PNMLINK pNMLink = (PNMLINK)pNMHDR;//::ShellExecute(m_hWnd, _T("open"), pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL);CSeekDlg dlg;dlg.DoModal();*pResult = 0;}BOOL CLoginDlg::OnInitDialog(){CDialog::OnInitDialog();// TODO: 在此添加额外的初始化ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW);CBitmap map1, map2, map3;map1.LoadBitmap(IDB_BITMAP1);m_btnList.SetBitmap(map1);map2.LoadBitmap(IDB_BITMAP9);m_btnJianPan.SetBitmap(map2);map3.LoadBitmap(IDB_BITMAP10);m_btnConfig.SetBitmap(map3);for (int i=0; i<3; ++i){toolTipCtrl[i].Create(this);}toolTipCtrl[0].AddTool(GetDlgItem(IDC_BUTTON_CONFIG), _T("设置"));toolTipCtrl[1].AddTool(GetDlgItem(IDC_BUTTON_MIN), _T("最小化"));toolTipCtrl[2].AddTool(GetDlgItem(IDC_BUTTON_CLOSE), _T("关闭"));m_nid.cbSize = (DWORD) sizeof(NOTIFYICONDATA);m_nid.hWnd = m_hWnd;m_nid.uID = IDI_OFFLINE;//IDR_MAINFRAME;m_nid.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_OFFLINE));m_nid.uFlags = NIF_ICON | NIF_MESSAGE|NIF_TIP;m_nid.uCallbackMessage = WM_SHOWTASK;wcscpy_s(m_nid.szTip,_T("QQ"));//实现任务栏无图标ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW,SWP_FRAMECHANGED);Shell_NotifyIcon(NIM_ADD, &m_nid);m_cLinkRegister.SetWindowText(_T("<ahref=\"/chs/index.html?from=client&ptlang=2052®key=&ADUIN=0&ADSESSION=0&ADT AG=CLIENT.QQ.4855_NewAccount_Btn.0&ADPUBNO=26095\">注册账号</a>"));m_cLinkFindpwd.SetWindowText(_T("<ahref=\"https:///cn2/findpsw/pc/pc_find_pwd_input_account?source_id=1003&ptlang=2052&aquin=105 8072426\">忘记密码</a>"));//获得本地配置文件中已经保存的账号数目int nCount = ::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qq.ini"));CString strAccount;//保存读取配置文件后的账号CString strPassword;//保存读取配置文件后的账号的密码CString temp;//保存格式化字符串int nShow;//显示帐号的个数//如果本地文件帐号数目小于四个,则把显示的数目设为帐号数目,否则显示四个if (nCount <= 4){nShow = nCount;}elsenShow = 4;//动态构造一个数组,存储每个帐号的登录排名计数(当前登录排名为,其他排名在之前基础上加)int *a = new int [nCount + 1];memset(a,0,nCount + 1);//把每个帐号的排名计数赋值给对应的数组元素for (int i = 0;i < nCount;i++){temp.Format(_T("%d"),i + 1);a[i] = ::GetPrivateProfileInt(_T("admin") + temp,_T("Rank") + temp,0,_T(".\\qq.ini"));}//对排名计数进行排序int i;int j;int k;for(i = 0;i < nCount;i++)for(j = i + 1;j < nCount;j++)if(a[i] > a[j]){k = a[i];a[i] = a[j];a[j] = k;}//把排名计数前指定位数增加到组合框for(int n= 0;n < nShow;n++){for (j = 0;j < nCount;j++){temp.Format(_T("%d"),j+1);if (a[n] == ::GetPrivateProfileInt(_T("admin") + temp,_T("Rank") + temp,0,_T(".\\qq.ini"))){::GetPrivateProfileString(_T("admin") + temp,_T("Account") + temp,_T(""), strAccount.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));((CComboBox*)GetDlgItem(IDC_COMBO_USERNAME))->InsertString(n,strAccount);break;}}}//把上次登录的帐号显示到组合框中CString isLastLogin;////保存配置文件中的是否为上次登录的账号int nIndex = 0;//存储上次登录账号的下标CString strRemPassword;//保存配置文件中的记住密码选择状态CString strAutoLogin;//保存配置文件中的自动登录选择状态for(int i = 0;i < nCount;i++){temp.Format(_T("%d"),i + 1);::GetPrivateProfileString(_T("admin") + temp,_T("isLastLogin") + temp,_T(""),isLastLogin.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));if (isLastLogin == _T("1")){nIndex = i + 1;break;}}//获得上一次登录的帐号,密码,记住密码状态,自动登陆状态temp.Format(_T("%d"),nIndex);::GetPrivateProfileString(_T("admin") + temp,_T("Account") + temp,_T(""), strAccount.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));::GetPrivateProfileString(_T("admin") + temp,_T("Password") + temp,_T(""), strPassword.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));::GetPrivateProfileString(_T("admin") + temp,_T("isRemPassword") + temp,_T(""), strRemPassword.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));::GetPrivateProfileString(_T("admin") + temp,_T("isAutoLogin") + temp,_T(""), strAutoLogin.GetBuffer(MAX_PATH),MAX_PA TH,_T(".\\qq.ini"));if (strRemPassword == _T("1")){m_isRemPassword = TRUE;}elsem_isRemPassword = FALSE;if (strAutoLogin == _T("1")){m_isAutoLogin = TRUE;m_isRemPassword = TRUE;}elsem_isAutoLogin = FALSE;m_strPassord = strPassword;UpdateData(FALSE);SetDlgItemText(IDC_COMBO_USERNAME,strAccount);SetTimer(1,5000,NULL);//设置定时器,用于自动登录//释放内存delete []a;return TRUE; // return TRUE unless you set the focus to a control// 异常: OCX 属性页应返回FALSE}void CLoginDlg::OnBnClickedButtonList(){// TODO: 在此添加控件通知处理程序代码CMenu menu, *pMenu;menu.LoadMenu(IDR_MENU1);pMenu = menu.GetSubMenu(0);CBitmap bitmap0,bitmap1,bitmap2,bitmap3,bitmap4,bitmap5,bitmap6,bitmap7;bitmap0.LoadBitmap(IDB_BITMAP1);bitmap1.LoadBitmap(IDB_BITMAP2);bitmap2.LoadBitmap(IDB_BITMAP3);bitmap3.LoadBitmap(IDB_BITMAP4);bitmap4.LoadBitmap(IDB_BITMAP5);bitmap5.LoadBitmap(IDB_BITMAP6);/*bitmap6.LoadBitmap(IDB_BITMAP7);bitmap7.LoadBitmap(IDB_BITMAP8);*/pMenu->SetMenuItemBitmaps(0, MF_BYPOSITION, &bitmap0, &bitmap0);pMenu->SetMenuItemBitmaps(1, MF_BYPOSITION, &bitmap1, &bitmap1);pMenu->SetMenuItemBitmaps(3, MF_BYPOSITION, &bitmap2, &bitmap2);pMenu->SetMenuItemBitmaps(4, MF_BYPOSITION, &bitmap3, &bitmap3);pMenu->SetMenuItemBitmaps(5, MF_BYPOSITION, &bitmap4, &bitmap4);pMenu->SetMenuItemBitmaps(7, MF_BYPOSITION, &bitmap5, &bitmap5);/*pMenu->SetMenuItemBitmaps(6, MF_BYPOSITION, &bitmap0, &bitmap0);pMenu->SetMenuItemBitmaps(7, MF_BYPOSITION, &bitmap0, &bitmap0);*/CRect rect;GetDlgItem(IDC_BUTTON_LIST)->GetWindowRect(&rect);pMenu->TrackPopupMenu(TPM_LEFTBUTTON,rect.right-rect.Width(), rect.bottom, this, 0);}void CLoginDlg::OnPaint(){CPaintDC dc(this); // device context for paintingCBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP12);CRect rect;GetClientRect(&rect);CDC demo;demo.CreateCompatibleDC(&dc);demo.SelectObject(&bitmap);//dc.StretchBlt(0, 0, rect.Width(), rect.Height(), &demo, 0, 0, bitMap.bmWidth, bitMap.bmHeight, SRCCOPY);dc.BitBlt(0, 0, rect.Width(), rect.Height(), &demo, 0, 0, SRCCOPY);// 不为绘图消息调用CDialog::OnPaint()}void CLoginDlg::OnOnlin(){// TODO: 在此添加命令处理程序代码CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP1);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_IMONLINE;}void CLoginDlg::OnQme(){CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP2);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_QME;// TODO: 在此添加命令处理程序代码}void CLoginDlg::OnLeave(){// TODO: 在此添加命令处理程序代码CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP3);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_AWAY;}void CLoginDlg::OnBusy(){// TODO: 在此添加命令处理程序代码CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP4);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_BUSY;}void CLoginDlg::OnDarao(){// TODO: 在此添加命令处理程序代码CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP5);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_MUTE;}void CLoginDlg::OnYinshen(){// TODO: 在此添加命令处理程序代码CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP6);m_btnList.SetBitmap(bitmap);m_nIconID = IDI_INVISIBLE;}BOOL CLoginDlg::PreTranslateMessage(MSG* pMsg){// TODO: 在此添加专用代码和/或调用基类if (pMsg->message== WM_LBUTTONDOWN ||pMsg->message== WM_LBUTTONUP ||pMsg->message== WM_MOUSEMOVE)for (int i=0; i<3; ++i){toolTipCtrl[i].RelayEvent(pMsg);}return CDialog::PreTranslateMessage(pMsg);}void CLoginDlg::Onshowwindow(){// TODO: 在此添加命令处理程序代码ShowWindow(SW_SHOW);}void CLoginDlg::OnButtonClose(){// TODO: 在此添加命令处理程序代码PostMessage(WM_QUIT);ToTray(TRUE);}void CLoginDlg::OnBnClickedButtonClose(){static CRect rectLarge;static CRect rectSmall;if (rectLarge.IsRectNull()){CRect rectSeparator;GetWindowRect(&rectLarge);//获得变小前的对话框面积GetDlgItem(IDC_STATIC)->GetWindowRect(&rectSeparator);rectSmall.left = rectLarge.left;rectSmall.top = rectLarge.top;rectSmall.right = rectLarge.right;rectSmall.bottom = rectSeparator.bottom;}for (int i = rectSmall.Height(); i>=0; i--){SetWindowPos(NULL, 0, 0, rectSmall.Width(), i, SWP_NOMOVE | SWP_NOZORDER);Sleep(5);}//OnOK();PostMessage(WM_QUIT);ToTray(TRUE);}void CLoginDlg::OnBnClickedButtonMin(){// TODO: 在此添加控件通知处理程序代码ShowWindow(SW_HIDE);ToTray(TRUE);}void CLoginDlg::OnBnClickedButtonJianpan(){// TODO: 在此添加控件通知处理程序代码}void CLoginDlg::OnCbnSelchangeComboUsername(){m_isFirstLoginAccount=FALSE;//表示不是第一次登录的账号//获取当前选择的行,并显示到列表框中int nIndex = ((CComboBox*)GetDlgItem(IDC_COMBO_USERNAME))->GetCurSel();int nCount = ::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qq.ini"));((CComboBox*)GetDlgItem(IDC_COMBO_USERNAME))->GetLBText(nIndex,m_strUsername);int n=0;//保存账号在配置文件中的下标CString temp;//保存格式化的字符串CString strAccount;//保存在配置文件中的读取到的账号CString strPassword;//保存在配置文件中的读取到的账号的密码CString strRemPassword;//保存最近一次账号登录的记住密码状态CString strAutoLogin;//保存最近一次账号登录的自动登录状态//遍历配置文件,判断上次保存的密码记住状态!for(int i = 0;i < nCount;i++){temp.Format(_T("%d"),i + 1);::GetPrivateProfileString(_T("admin")+temp,_T("Account")+temp,_T(""),strAccount.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));if (m_strUsername == strAccount){n=i+1;::GetPrivateProfileString(_T("admin")+temp,_T("isRemPassword")+temp,_T(""),strRemPassword.GetBuffe r(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));if (strRemPassword==_T("1")){m_isRemPassword=TRUE;}elsem_isRemPassword=FALSE;break;}}//再考虑自动登录框的选择状态::GetPrivateProfileString(_T("admin")+temp,_T("isAutoLogin")+temp,_T(""),strAutoLogin.GetBuffer(MAX_PATH),MAX_PA TH,_T(".\\qq.ini"));//如果是自动登录,那要记住密码if(strAutoLogin == _T("1")){m_isRemPassword = TRUE;m_isAutoLogin = TRUE;}elsem_isAutoLogin = FALSE;temp.Format(_T("%d"),n);::GetPrivateProfileString(_T("admin") + temp,_T("Password") + temp,_T(""), strPassword.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));m_strPassord = strPassword;SetDlgItemText(IDC_EDIT_PASSWORD,m_strPassord);CButton *ptn = (CButton*)GetDlgItem(IDC_CHECK_SA VEPWD); //获得CheckBox的指针ptn->SetCheck(m_isRemPassword);//设置记住密码框选择状态CButton *qtn = (CButton*)GetDlgItem(IDC_CHECK_AUTOLOGIN); //获得CheckBox的指针qtn->SetCheck(m_isAutoLogin);//设置自动登录框选择状态}void CLoginDlg::OnBnClickedCheckSavepwd(){//如果记住密码状态没有选,则自动登录也不能选CButton *pRemPassWord = (CButton*)GetDlgItem(IDC_CHECK_SA VEPWD);CButton *pBtnAutoLogin = (CButton*)GetDlgItem(IDC_CHECK_AUTOLOGIN);if (pRemPassWord->GetCheck() == 0){pBtnAutoLogin->SetCheck(0);}}void CLoginDlg::OnBnClickedCheckAutologin(){// TODO: 在此添加控件通知处理程序代码//如果当前不是自动登录状态,则单击后,为自动登录状态,否则取消自动登录状态if (!m_isAutoLogin){m_isAutoLogin = TRUE;m_isRemPassword = TRUE; //如果为自动登录状态,则应该记住密码CButton *q = (CButton*)GetDlgItem(IDC_CHECK_SA VEPWD);q->SetCheck(m_isRemPassword);}else{m_isAutoLogin = FALSE;}CButton *p = (CButton*)GetDlgItem(IDC_CHECK_AUTOLOGIN); //获得CheckBox的指针p->SetCheck(m_isAutoLogin);//设置选择状态}void CLoginDlg::OnTimer(UINT_PTR nIDEvent){// 如果是不是上一次登录的账号,则返回if(!m_isFirstLoginAccount)return;UpdateData();int nCount=::GetPrivateProfileInt(_T("FileCount"),_T("Count"),0,_T(".\\qq.ini"));CString temp;//存储格式化字符串CString strAccount;//存储读取文件中的账号CString strPassword;//存储读取文件中的密码CString strAutoLogin;//存储读取文件中的自动登录状态//遍历配置文件,找到当前输入的账号密码,取得该账号的自动登录的选择状态for(int i = 0;i < nCount;i++){temp.Format(_T("%d"),i + 1);::GetPrivateProfileString(_T("admin")+temp,_T("Account")+temp,m_strUsername, strAccount.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));::GetPrivateProfileString(_T("admin")+temp,_T("Password")+temp,_T(""), strPassword.GetBuffer(MAX_PA TH),MAX_PA TH,_T(".\\qq.ini"));if ((m_strUsername == strAccount)&&(m_strPassord == strPassword)){::GetPrivateProfileString(_T("admin")+temp,_T("isAutoLogin")+temp,_T(""), strAutoLogin.GetBuffer(MAX_PATH),MAX_PA TH,_T(".\\qq.ini"));//如果为自动登录状态,则调用OnOk,关闭定时器if (strAutoLogin == _T("1")){OnOK();KillTimer(1);break;}}}CDialog::OnTimer(nIDEvent);}void CLoginDlg::OnOpenmainpanel(){//托盘右键菜单实现,隐藏主面板ShowWindow(SW_SHOW);}void CLoginDlg::OnHideWindows(){//托盘右键菜单实现,打开主面板ShowWindow(SW_HIDE);}主界面.h// QQDemoDlg.h : 头文件//#pragma once#include"Linkname.h"#include"RoomDlg.h"#include"GroupDlg.h"#include"SessionDlg.h"#include"Twitter.h"#include"afxwin.h"#include"EditDlg.h"// CQQDemoDlg 对话框class CQQDemoDlg : public CDialog{// 构造public:CQQDemoDlg(CWnd* pParent = NULL); // 标准构造函数~CQQDemoDlg();// 对话框数据enum { IDD = IDD_QQDEMO_DIALOG };protected:virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持// 实现public:void ToTray(DWORD dwMessage,HICON hIcon);//用于托盘的增加,修改,删除操作protected://修正移动时窗口的大小void FixMoving(UINT fwSide, LPRECT pRect);//修正改改变窗口大小时窗口的大小void FixSizing(UINT fwSide, LPRECT pRect);//从收缩状态显示窗口void DoShow();//从显示状态收缩窗口void DoHide();//重载函数,只是为了方便调用BOOL SetWindowPos(const CWnd* pWndInsertAfter,LPCRECT pCRect, UINT nFlags = SWP_SHOWWINDOW);afx_msg void OnTimer(UINT nIDEvent);afx_msg void OnSizing(UINT fwSide, LPRECT pRect);afx_msg int OnCreate(LPCREA TESTRUCT lpCreateStruct);afx_msg void OnMoving(UINT fwSide, LPRECT pRect);。
基于JavaSocket网络编程的山寨QQ

基于Java Socket 网络编程的山寨QQ(学习韩顺平老师的视频整理出的笔记)内容含盖:1.Java 面向对象编程2.3.4.5.6.连入因特网,以及数据如何在它们之间传输的标准。
协议采用了4层的层级结构,每一层都呼叫它的下一层所提供的网络来完成自己的需求。
通俗而言:TCP负责发现传输的问题,一有问题就发出信号,要求重新传输,直到所有数据安全正确地传输到目的地。
而IP是给因特网的每一台电脑规定一个地址。
二、端口端口详解在开始讲什么是端口之前,我们先来聊一聊什么是 port 呢?常常在网络上听说『我的主机开了多少的 port ,会不会被入侵呀!?或者是说『开那个 port 会比较安全?又,我的服务应该对应什么 port 呀?呵呵!很神奇吧!怎么一部主机上面有这么多的奇怪的port 呢?这个 port 有什么作用呢?择大于 1024 以上(因为0-1023有特殊作用,被预定,如FTP、HTTP、SMTP等)的 port 号来进行!其 TCP 封包会将(且只将) SYN 旗标设定起来!这是整个联机的第一个封包;·如果另一端(通常为 Server ) 接受这个请求的话(当然啰,特殊的服务需要以特殊的port 来进行,例如 FTP 的 port 21 ),则会向请求端送回整个联机的第二个封包!其上除了 SYN 旗标之外同时还将 ACK 旗标也设定起来,并同时在本机端建立资源以待联机之需;·然后,请求端获得服务端第一个响应封包之后,必须再响应对方一个确认封包,此时封包只带 ACK 旗标(事实上,后继联机中的所有封包都必须带有 ACK 旗标);·只有当服务端收到请求端的确认( ACK )封包(也就是整个联机的第三个封包)之后,两端的联机才能正式建立。
这就是所谓的 TCP 联机的'三次握手( Three-Way Handshake )',21TCP攻击者可以达到对目标计算机的初步了解。
QQ程序源代码

//---------------------------------------------------------------------
//复制自身到系统目录
//pAim:[in,out],初始为存放目标文件名缓冲区的指针,
//函数向缓冲区返回完整路径的目标文件名
//成功返回0,否则返回非0
递归枚举hFatherWindow指定的窗口下的所有子窗口和兄弟窗口,
返回和lstyle样式相同的窗口句柄,如果没有找到,返回NULL
---------------------------------------------------------------------*/
HWND GetStyleWindow(HWND hFatherWindow, const long lstyle);
//将FullName指定的dll文件以远程线程方式插入到Pid指定的进程里
//成功返回0,失败返回1
int InjectDll(const char *FullName, const DWORD Pid);
/*---------------------------------------------------------------------
#include <windows.h>
//---------------------------------------------------------------------
//判断系统版本,9x返回1,NT、2000、xp、2003返回2,其它返回0
int GetOsVer(void);
首先,判断系统版本,如果就9x,将自己复制到系统目录,如果复制成功,说明自身没有在系统目录运行那么需要启动系统目录下的实例,然后自己退出。再创建一个互斥量,保证只有一个实例存在。接下来,用RegisterServiceProcess函数将自己注册成一个服务程序,这样在9x下按ctrl+alt+del就不会看到了。最后,调用GetQQPass函数,监视QQ登录的情况。如果是NT系统,将自己安装为自动启动的系统服务,服务启动后,任务就是释放两个要插入其他进程的dll,把监视QQ登录窗口的dll插入到winlogon.exe进程中,然后就停止,这样就不会在任务管理器里面看到不正常的进程了。插入到winlogon.exe里面的线程负责监视是否有QQ登录,发现后就将GetQQPass函数作为一个线程插入到QQ进程中,当GetQQPass函数捕获到号码和密码时,就向设置好的邮箱发一封信。至于为什么要插入到winlogon.exe进程,只是习惯而已,当然,也可以插入到其他的系统进程里,但是注意一定要插入到系统进程,不能是用户进程。因为只有系统进程里的线程才能在任何用户登录的情况下都有权限做远程线程插入的动作。GetQQPass函数我使用很简单的办法,就是向QQ的号码和密码窗口发送WM_GETTEXT消息得到它们的内容。判断哪个窗口是号码窗口和密码窗口的办法也是最常用的,就是靠它们的style。首先用QQ登录窗口的类名得到QQ的登录窗口的句柄,再通过这个句柄找到号码窗口和密码窗口的句柄。类名和子窗口的style都是用spy++得到的。这里有一个细节,就是“QQ注册向导”窗口里面,选中“使用已有的QQ号码”以后和选中以前的号码与密码窗口的style是不一样的,当然我们要选中以后的style了。发邮件部分也很简陋,现在只在163和sina的测试过,还能用。其中base64编码部分的代码是以前从网上copy的,忘了从哪里看的了,总之感谢这段代码的作者。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
关于山寨QQ的java的源代码
Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言,是由Sun Microsystems公司于1995年5月推出的Java程序设计语言和Java平台(即JavaSE, JavaEE, JavaME)的总称。
Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台、科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。
文库里没有关于山寨QQ的java的源代码,只能看了视频整理自己写了,特免费分享。
文档说明:根据java教学视频《韩顺平.循序渐进学.java.从入门到精通》(第87~94讲)整理得源相关代码。
代码调试无误,下载后调试有误的可评论留言联系。
image中图片附录在源代码后面。
工程文件夹:
(源代码)
/**
* 这是客户端连接服务器的后台
*/
package com.qq.client.model;
import com.qq.client.tools.*;
import java.util.*;
import .*;
import java.io.*;
import mon.*;
public class QqClientConServer {
public Socket s;
//发送第一次请求
public boolean sendLoginInfoToServer(Object o)
{
boolean b=false;
try {
// System.out.println("kk");
s=new Socket("127.0.0.1",9988);
ObjectOutputStream oos=new ObjectOutputStream(s.getOutputStream());
oos.writeObject(o);
ObjectInputStream ois=new ObjectInputStream(s.getInputStream());
Message ms=(Message)ois.readObject();
//这里就是验证用户登录的地方
if(ms.getMesType().equals("1"))
{
jp1.add(jb2);
this.add(jp1);
this.setSize(500, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
if(arg0.getSource()==jb1)
{
new MyQqServer();
}
}
}
Image文件夹中图片。