发现电脑里以前编写的下载程序。。。

做个记录,那时做的挺匆忙的,没用委托,通过公开出窗体来修改下载进度,做的比较乱... ==!!

程序具体功能(流程):

1.检测系统托盘图标内的进程名是否符合要求 (xp时可以,win7部分机器可以,该功能无意义)

2.抓取页面,进行正则匹配下载的文件地址(可以改成自己想要的任何情况)

3.开多线程下载(建立多个文件)

4.合并文件

5.下载完毕后,发送ipmsg

---下面是部分代码,个人认为有参考价值---

1.检测系统托盘图标内的进程名

 1 #region P/Invoke
 2 
 3 [DllImport("User32.dll", EntryPoint = "FindWindow")]
 4 private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
 5 
 6 [DllImport("User32.dll", EntryPoint = "FindWindowEx")]
 7 private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,
 8  string lpClassName, string lpWindowName);
 9 
10 //[DllImport("User32.dll", EntryPoint = "GetClientRect")]
11 //static extern bool GetClientRect(IntPtr hWnd, out RECT lpRect);
12 
13 [DllImport("user32.dll", EntryPoint = "PostMessageA")]
14 private static extern int PostMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
15 
16 #endregion
17 
18 private void btnFind_Click(object sender, EventArgs e)
19 {
20     SysTrayWnd.TrayItemData[] trayItems = SysTrayWnd.GetTrayWndDetail();
21     this.dataGridView1.Columns.Clear();
22     this.dataGridView1.Columns.Add("colTrayItemWinHandle", "窗口句柄");
23     this.dataGridView1.Columns.Add("colTrayItemProcHandle", "进程句柄");
24     this.dataGridView1.Columns.Add("colTrayItemPID", "进程ID");
25     this.dataGridView1.Columns.Add("colTrayItemProcImagePath", "进程映象路径");
26     this.dataGridView1.Columns.Add("colTrayItemIconTipText", "托盘图标提示内容");
27     this.dataGridView1.Columns.Add("colTrayItemIconHandle", "托盘图标句柄");
28     //this.dataGridView1.Columns.Add("colTrayItemIcon", "托盘图标");
29     this.dataGridView1.Columns.Add(new DataGridViewImageColumn());
30     this.dataGridView1.Columns[6].HeaderText = "托盘图标";
31     this.dataGridView1.Columns[6].Name = "colTrayItemIcon";
32     this.dataGridView1.Columns.Add("test", "test");
33 
34     this.dataGridView1.Rows.Add(trayItems.Length);
35     int iRowIndex = 0;
36     foreach (SysTrayWnd.TrayItemData trayItem in trayItems)
37     {
38     //窗口句柄  
39     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemWinHandle"].Value = trayItem.hWnd.ToString("X").ToUpper();
40     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemWinHandle"].ToolTipText = trayItem.hWnd.ToString();
41     //进程句柄  
42     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemProcHandle"].Value = trayItem.hProcess.ToString("X").ToUpper();
43     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemProcHandle"].ToolTipText = trayItem.hProcess.ToString();
44     //进程ID  
45     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemPID"].Value = trayItem.dwProcessID.ToString();
46     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemPID"].ToolTipText = trayItem.dwProcessID.ToString();
47     //进程映象路径  
48     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemProcImagePath"].Value = trayItem.lpProcImagePath;
49     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemProcImagePath"].ToolTipText = trayItem.lpProcImagePath;
50     //托盘图标提示内容  
51     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIconTipText"].Value = trayItem.lpTrayToolTip;
52     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIconTipText"].ToolTipText = trayItem.lpTrayToolTip;
53     //托盘图标句柄  
54     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIconHandle"].Value = trayItem.hIcon.ToString("X").ToUpper();
55     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIconHandle"].ToolTipText = trayItem.hIcon.ToString();
56     //托盘图标  ;
57     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIcon"].ValueType = typeof(byte[]);
58     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIcon"].Value = Icon.FromHandle(trayItem.hIcon);
59     this.dataGridView1.Rows[iRowIndex].Cells["colTrayItemIconHandle"].ToolTipText = trayItem.hIcon.ToString();
60     //test
61     System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(trayItem.dwProcessID);
62     this.dataGridView1.Rows[iRowIndex].Cells["test"].Value = p.ProcessName;
63 
64     iRowIndex++;
65     }
66 
67     doAboutHostCheck(trayItems);
68 }
69 
70 private void doAboutHostCheck(SysTrayWnd.TrayItemData[] trayItems)
71 {
72 
73     foreach (SysTrayWnd.TrayItemData trayItem in trayItems)
74     {
75     System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(trayItem.dwProcessID);
76     if (hostCheckPName.Equals(p.ProcessName))
77     {
78         t.Stop();
79         setFormValue("hostCheck错误发生,开始联网查找解决方案", null, null);
80         doDownload();
81         break;
82     }
83     }
84 }
View Code

相关文章: