实例介绍
【实例截图】
【核心代码】
public partial class Main : Form
{
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr GetDlgItem(IntPtr hDlg, int nIDDlgItem);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, int childAfter, string className, int windowTitle);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr GetModuleHandle(string lpModuleName);
IntPtr hwndQQ;
IntPtr hwnd1;
IntPtr hwnd2;
IntPtr hwnd3;
IntPtr hwnd4;
private DateTime qqTimer = DateTime.Now;
private string configFile = "moban.iaoc";
private string removeIAOC_QQhao = "241181876,86762777,429212807,125364587,399795877,24431107,38927715,83737109,125926782,120748842,705378466,597140491,77861690,512431026,415455346,7499251,304741446";
private string removeIAOC_QQqun = "20075924,9553379,1566329,22191682,18529744";
private string removeChar = "毛泽东,邓小平,华国峰,江泽民,胡锦涛,刘少奇,法轮功,法轮大法,台湾";//禁止发布的文字
private string curSelect = "";
private string curQQhao = "";
private string curQQQunHao = "";
private bool start = false;//是否开始群发的标志
public Main()
{
InitializeComponent();
}
private void btnBegin_Click(object sender, EventArgs e)
{
if (start == false)
{
//CheckInput();
SaveConfig();
HideAll();
start = true;
this.btnBegin.Text = "停止群发";
this.timer1.Enabled = true;
}
else
{
ShowAll();
SaveConfig();
start = false;
this.timer1.Enabled = false;
this.btnBegin.Text = "开始群发";
}
}
private void Main_Load(object sender, EventArgs e)
{
this.timer1.Interval = 1;
this.timer1.Tick = new System.EventHandler(this.timer1_Tick);
try
{
if (!File.Exists(Application.StartupPath.ToString() "\\" configFile))
{
int tmpi = CreateInitConfig(configFile);
if (tmpi == 1)
{ MessageBox.Show("创建初始配置文件失败"); }
if (tmpi == 2)
{ MessageBox.Show("初始配置文件已经存在"); }
}
}
catch
{
MessageBox.Show("配置文件读写出错,无法创建默认配置文件,可能是权限不够,请检查");
this.Close();
}
DataBind(configFile);
}
/// <summary>
/// 建立初始配置,返回0成功,1建文件失败,2文件已经存在
/// </summary>
/// <param name="configFileName">配置文件名字</param>
/// <returns></returns>
private int CreateInitConfig(string configFileName)
{
int rvalue = 0;
if (!File.Exists(Application.StartupPath "\\" configFileName))
{
try
{
SZIE.CN.XMLOption xml = new SZIE.CN.XMLOption(configFileName);
xml.AddParentNode("set");
xml.AddChildNode("/IAOC/set", "message", "<*QQ消息群发器*>" Environment.NewLine "http://www.szie.cn/" Environment.NewLine "联系QQ:241181876");
xml.AddChildNode("/IAOC/set", "qqhao1", "700000000");
xml.AddChildNode("/IAOC/set", "qqhao2", "700000100");
xml.AddChildNode("/IAOC/set", "qunhao1", "9555555");
xml.AddChildNode("/IAOC/set", "qunhao2", "9555558");
xml.AddChildNode("/IAOC/set", "curselect", "qqhao");
xml.AddChildNode("/IAOC/set", "removeqq", "241181876");
xml.AddChildNode("/IAOC/set", "removequn", "123456");
xml.AddChildNode("/IAOC/set", "sendtime", "2000");
xml.AddChildNode("/IAOC/set", "curqqhao", "700000000");
xml.AddChildNode("/IAOC/set", "curqunhao", "9555555");
xml.SaveXmlDocument();
rvalue = 0;
}
catch
{
rvalue = 1;//创建出错
}
}
else
{
rvalue = 2;//文件已经存在
}
return rvalue;
}
/// <summary>
/// 将所有控件设置为不可操作
/// </summary>
private void HideAll()
{
this.label1.Enabled = false;
this.label2.Enabled = false;
this.label5.Enabled = false;
this.label6.Enabled = false;
this.txtBeginQQHao.Enabled = false;
this.txtEndQQHao.Enabled = false;
this.txtQQQunHao1.Enabled = false;
this.txtQQQunHao2.Enabled = false;
this.txtMessage.Enabled = false;
this.txtRemoveQQ.Enabled = false;
this.txtRemoveQQQun.Enabled = false;
this.txtSendTime.Enabled = false;
this.txtCurQQ.Enabled = false;
this.txtCurQQQun.Enabled = false;
this.btnCreate.Enabled = false;
this.btnSave.Enabled = false;
this.btnReg.Enabled = false;
this.btnOpen.Enabled = false;
if (curSelect == "qqhao")
{
this.txtRemoveQQ.Visible = true;
this.txtRemoveQQQun.Visible = false;
this.txtCurQQ.Visible = true;
this.txtCurQQQun.Visible = false;
this.rbQQQunHao.Enabled = false;
}
if (curSelect == "qqqun")
{
this.txtRemoveQQ.Visible = false;
this.txtRemoveQQQun.Visible = true;
this.txtCurQQ.Visible = false;
this.txtCurQQQun.Visible = true;
this.rbQQHaoDuan.Enabled = false;
}
}
/// <summary>
/// 恢复控件状态
/// </summary>
private void ShowAll()
{
this.txtMessage.Enabled = true;
this.btnCreate.Enabled = true;
this.btnSave.Enabled = true;
this.btnReg.Enabled = true;
this.btnOpen.Enabled = true;
this.rbQQHaoDuan.Enabled = true;
this.rbQQQunHao.Enabled = true;
this.txtSendTime.Enabled = true;
this.txtRemoveQQ.Enabled = true;
this.txtRemoveQQQun.Enabled = true;
this.txtCurQQ.Enabled = true;
this.txtCurQQQun.Enabled = true;
if (curSelect == "qqhao")
{
this.txtBeginQQHao.Enabled = true;
this.txtEndQQHao.Enabled = true;
this.txtQQQunHao1.Enabled = false;
this.txtQQQunHao2.Enabled = false;
this.label1.Enabled = true;
this.label2.Enabled = true;
this.label5.Enabled = false;
this.label6.Enabled = false;
this.txtRemoveQQ.Visible = true;
this.txtRemoveQQQun.Visible = false;
this.txtCurQQ.Visible = true;
this.txtCurQQQun.Visible = false;
}
if (curSelect == "qqqun")
{
this.txtBeginQQHao.Enabled = false;
this.txtEndQQHao.Enabled = false;
this.txtQQQunHao1.Enabled = true;
this.txtQQQunHao2.Enabled = true;
this.label1.Enabled = false;
this.label2.Enabled = false;
this.label5.Enabled = true;
this.label6.Enabled = true;
this.txtRemoveQQ.Visible = false;
this.txtRemoveQQQun.Visible = true;
this.txtCurQQ.Visible = false;
this.txtCurQQQun.Visible = true;
}
}
/// <summary>
/// 绑定数据
/// </summary>
/// <param name="configFile">指定配置文件</param>
private void DataBind(string configFile)
{
if (!string.IsNullOrEmpty(configFile))
{
try
{
SZIE.CN.XMLOption xml = new SZIE.CN.XMLOption(configFile);
this.txtMessage.Text = xml.GetXmlNodeValue("/IAOC/set/message");
this.txtBeginQQHao.Text = xml.GetXmlNodeValue("/IAOC/set/qqhao1");
this.txtEndQQHao.Text = xml.GetXmlNodeValue("/IAOC/set/qqhao2");
this.txtQQQunHao1.Text = xml.GetXmlNodeValue("/IAOC/set/qunhao1");
this.txtQQQunHao2.Text = xml.GetXmlNodeValue("/IAOC/set/qunhao2");
this.txtRemoveQQ.Text = xml.GetXmlNodeValue("/IAOC/set/removeqq");
this.txtRemoveQQQun.Text = xml.GetXmlNodeValue("/IAOC/set/removequn");
this.txtCurQQ.Text = xml.GetXmlNodeValue("/IAOC/set/curqqhao");
this.txtCurQQQun.Text = xml.GetXmlNodeValue("/IAOC/set/curqunhao");
this.txtSendTime.Text = xml.GetXmlNodeValue("/IAOC/set/sendtime");
curSelect = xml.GetXmlNodeValue("/IAOC/set/curselect");
curQQhao = xml.GetXmlNodeValue("/IAOC/set/curqqhao");
curQQQunHao = xml.GetXmlNodeValue("/IAOC/set/curqunhao");
if (xml.GetXmlNodeValue("/IAOC/set/curselect") == "qqhao")
{
this.rbQQHaoDuan.Checked = true;
progressBar1.Minimum = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/qqhao1"));
progressBar1.Maximum = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/qqhao2"));
progressBar1.Value = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/curqqhao"));
this.label1.Enabled = true;
this.label2.Enabled = true;
this.label5.Enabled = false;
this.label6.Enabled = false;
this.label7.Text = "排除QQ号";
this.txtBeginQQHao.Enabled = true;
this.txtEndQQHao.Enabled = true;
this.txtQQQunHao1.Enabled = false;
this.txtQQQunHao2.Enabled = false;
this.txtRemoveQQ.Visible = true;
this.txtRemoveQQQun.Visible = false;
this.txtCurQQ.Visible = true;
this.txtCurQQQun.Visible = false;
}
else
{
this.rbQQQunHao.Checked = true;
progressBar1.Minimum = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/qunhao1"));
progressBar1.Maximum = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/qunhao2"));
progressBar1.Value = Convert.ToInt32(xml.GetXmlNodeValue("/IAOC/set/curqunhao"));
this.label1.Enabled = false;
this.label2.Enabled = false;
this.label5.Enabled = true;
this.label6.Enabled = true;
this.label7.Text = "排除群号";
this.txtBeginQQHao.Enabled = false;
this.txtEndQQHao.Enabled = false;
this.txtQQQunHao1.Enabled = true;
this.txtQQQunHao2.Enabled = true;
this.txtRemoveQQ.Visible = false;
this.txtRemoveQQQun.Visible = true;
this.txtCurQQ.Visible = false;
this.txtCurQQQun.Visible = true;
}
}
catch
{
MessageBox.Show("读取配置文件出错,请检查是否有相应的读权限或检查配置文件是否手工修改导致数据格式错误");
}
}
}
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论