实例介绍
【实例简介】
【实例截图】
【核心代码】
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml;
using System.IO;
namespace QQLogin
{
public partial class QQLogin : Form
{
/// <summary>
/// QQ帐号信息
/// </summary>
public List<QQAccount> QQAccountList = new List<QQAccount>();
/// <summary>
/// QQ信息存储文件的路径
/// </summary>
private string qqInfoPath = Environment.SystemDirectory Constants.STR_QQ_DATE_FILE_NAME;
public QQLogin()
{
InitializeComponent();
}
/// <summary>
/// 加载窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void QQLogin_Load(object sender, EventArgs e)
{
QQAccountList.Clear();
initQQAccountList();
initListView();
}
/// <summary>
/// 关闭程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void QQLogin_FormClosing(object sender, FormClosingEventArgs e)
{
//保存当前listView中的QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
/// <summary>
/// 读取QQ信息,初始化QQAccountList
/// </summary>
private void initQQAccountList()
{
if (!File.Exists(qqInfoPath))
{
//从指定路径创建QQ信息
File.Create(qqInfoPath).Close();
XmlTextWriter xmlWriter = new XmlTextWriter(qqInfoPath, Encoding.UTF8);
xmlWriter.WriteStartDocument();
xmlWriter.Close();
QQAccountList = new List<QQAccount>();
}
else
{
//从指定路径读取QQ信息
QQAccountList = QQFileAccess.Get(qqInfoPath);
}
}
/// <summary>
/// 初始化ListView显示
/// </summary>
private void initListView()
{
QQInfoListView.Items.Clear();
if (null == QQAccountList)
{
QQAccountList = new List<QQAccount>();
return;
}
//循环添加所有QQ信息
foreach (QQAccount qqAcnt in QQAccountList)
{
string name = qqAcnt.Name;
//有昵称时显示昵称,否则显示QQ号码
if (name == null || name.Length == 0)
{
name = qqAcnt.Number;
}
ListViewItem qqItem = new ListViewItem(name);
qqItem.SubItems.Add(qqAcnt.LastLoginDate);
qqItem.Checked = qqAcnt.IsChecked;
//根据是否隐身,显示不同的图标
if (qqAcnt.IsStealth)
{
qqItem.ImageIndex = 0;
}
else
{
qqItem.ImageIndex = 1;
}
QQInfoListView.Items.Add(qqItem);
}
}
/// <summary>
/// 启动选定帐号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStrtAcnt_Click(object sender, EventArgs e)
{
if (QQInfoListView.Items.Count == 0)
{
return;
}
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//未设置QQ路径错误提示
if (string.IsNullOrEmpty(qqPath))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_NULL);
return;
}
//路径设置选择程序不是QQ,提示错误
if (!qqPath.ToLower().EndsWith("qq.exe"))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_ERR);
return;
}
//循环登录所有选择的QQ帐号
foreach (ListViewItem qqItem in QQInfoListView.Items)
{
QQAccount qqAcnt = QQAccountList[qqItem.Index];
if (qqItem.Checked)
{
qqAcnt.IsChecked = true;
string strAcntNum = qqAcnt.Number;
string strPsw = qqAcnt.Psword;
bool blAcntSts = qqAcnt.IsStealth;
qqAcnt.LastLoginDate = DateTime.Now.ToLongDateString() DateTime.Now.ToShortTimeString();
//通过指定参数启动QQ
Process.Start(qqPath, "/START QQUIN:" strAcntNum " PWDHASH:" strPsw " /STAT:" (blAcntSts ? "40" : "41"));
}
else
{
qqAcnt.IsChecked = false;
}
}
}
/// <summary>
/// 创建快捷登录
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnCreateLnk_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//获取当前选择的帐号信息
QQAccount acnt = this.QQAccountList[this.QQInfoListView.FocusedItem.Index];
//创建快捷登录脚本
StreamWriter sw = new StreamWriter("C:\\CreateLink.vbs", false, System.Text.Encoding.GetEncoding("GB2312"));
sw.WriteLine("Set C = CreateObject(\"WScript.Shell\")");
sw.WriteLine("DesktopPath = C.SpecialFolders(\"Desktop\")");
//创建桌面快捷方式,快捷方式以QQ昵称或QQ号码命名
sw.WriteLine("Set link = C.CreateShortcut(DesktopPath & \"\\" (string.IsNullOrEmpty(acnt.Name) ? acnt.Number : acnt.Name) ".lnk\")");
sw.WriteLine("link.IconLocation = \"" qqPath ",0\"");
//QQ启动参数
string temp = "/START QQUIN:" acnt.Number " PWDHASH:" acnt.Psword " /STAT:" (acnt.IsStealth ? "40" : "41");
sw.WriteLine("link.Arguments =\"" temp "\"");
sw.WriteLine("link.Description = \"QQ自动登录器 - Aspx1\"");
sw.WriteLine("link.TargetPath = \"" qqPath "\"");
sw.WriteLine("link.WindowStyle =0");
sw.WriteLine("link.Save");
sw.WriteLine("Dim oFS");
sw.WriteLine("Set oFS = CreateObject(\"Scripting.FileSystemObject\")");
//删除脚本
sw.WriteLine("oFS.DeleteFile \"c:\\CreateLink.vbs\"");
sw.WriteLine("Set OFS = Nothing");
sw.Close();
//启动进程隐藏执行脚本文件
ProcessStartInfo psi = new ProcessStartInfo("c:\\CreateLink.vbs");
psi.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(psi);
MessageBox.Show("成功创建快捷方式.");
}
/// <summary>
/// 启动QQ
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStrtQQ_Click(object sender, EventArgs e)
{
//从注册表获取QQ主程序的路径
string qqPath = QQLoginRegistry.GetQQRegistryValue(Constants.STR_QQ_REG_KEY_PRGRM_PATH);
//未设置QQ路径错误提示
if (string.IsNullOrEmpty(qqPath))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_NULL);
return;
}
//路径设置选择程序不是QQ,提示错误
if (!qqPath.ToLower().EndsWith("qq.exe"))
{
MessageBox.Show(Constants.STR_QQ_WARN_PRGRM_PATH_ERR);
return;
}
//启动QQ程序
Process.Start(qqPath);
}
/// <summary>
/// 添加帐号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAddAcnt_Click(object sender, EventArgs e)
{
AddAccount addAccount = new AddAccount();
if (addAccount.ShowDialog() == DialogResult.OK)
{
QQAccount acnt = addAccount.GetAddQQInfo();
for (int i = 0; i < QQInfoListView.Items.Count; i )
{
if (acnt.Number == QQInfoListView.Items[i].Text)
{
MessageBox.Show("号码已存在");
return;
}
}
this.QQAccountList.Add(acnt);
initListView();
//保存QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
}
/// <summary>
/// 设置QQ程序路径
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnSetting_Click(object sender, EventArgs e)
{
SetPath setQQPath = new SetPath();
setQQPath.ShowDialog();
}
/// <summary>
/// 显示关于窗体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAbout_Click(object sender, EventArgs e)
{
About a = new About();
a.ShowDialog();
}
/// <summary>
/// 退出程序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnExt_Click(object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// 修改QQ信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ltvQQInfo_DoubleClick(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
//获取要修改的QQ号码
string qqAcntNum = QQAccountList[this.QQInfoListView.FocusedItem.Index].Number;
//获取要修改的QQ昵称
string qqName = QQAccountList[this.QQInfoListView.FocusedItem.Index].Name;
AddAccount chgQQAcntInfo = new AddAccount();
chgQQAcntInfo.initChangeStatus(qqName,qqAcntNum);
if (chgQQAcntInfo.ShowDialog() == DialogResult.OK)
{
QQAccount acnt = this.QQAccountList[this.QQInfoListView.FocusedItem.Index];
//删除原有的QQ帐号信息
this.QQAccountList.Remove(acnt);
//添加修改后的信息
this.QQAccountList.Add(chgQQAcntInfo.GetAddQQInfo());
initListView();
//保存QQ信息
QQFileAccess.Set(qqInfoPath, QQAccountList);
}
}
/// <summary>
/// 菜单删除事件,删除选定的QQ信息
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuDelItem_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
QQAccountList.RemoveAt(QQInfoListView.FocusedItem.Index);
initListView();
}
/// <summary>
/// 菜单隐身事件,设置QQ隐身或上线
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuShowItem_Click(object sender, EventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
int intSelectItem = this.QQInfoListView.FocusedItem.Index;
this.QQAccountList[intSelectItem].IsStealth = !this.QQAccountList[intSelectItem].IsStealth;
initListView();
}
/// <summary>
/// 选中行事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ltvQQInfo_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
{
if (0 == QQInfoListView.Items.Count || this.QQInfoListView.FocusedItem == null)
{
return;
}
int intSelectItem = this.QQInfoListView.FocusedItem.Index;
this.QQAccountList[intSelectItem].IsChecked = !this.QQAccountList[intSelectItem].IsChecked;
initListView();
//设置选中行的样式
this.QQInfoListView.Items[intSelectItem].Focused = true;
this.QQInfoListView.Items[intSelectItem].BackColor = Color.Blue;
this.QQInfoListView.Items[intSelectItem].ForeColor = Color.White;
}
}
}
好例子网口号:伸出你的我的手 — 分享!
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


支持(0) 盖楼(回复)
支持(0) 盖楼(回复)