WinForm制作定时显示基金净值的桌面小工具
来源:互联网 发布:大连淘宝店铺 编辑:程序博客网 时间:2024/04/28 11:51
基金网每隔一分钟会更新净值估算,每次要打开网站看挺麻烦的,于是制作了一个桌面小工具,在桌面顶层并且透明显示,每隔一分钟抓取数据显示。
净值估算例子如下:
http://fund.eastmoney.com/000167.html
<div id="statuspzgz" class="fundpz"><span class="green bold">1.1843</span><div id="statuszdf" class="fundzf"><p class="green">-0.0067</p><p class="green">-0.56%</p></div><p class="time">2014-03-06 15:00</p></div>
解析用到的路径为:
//div[@id='statuspzgz']/span
//div[@id='statuszdf']/p[1]
//div[@id='statuszdf']/p[2]
//div[@id='statuspzgz']/p[@class='time']
净值估算例子如下:
http://fund.eastmoney.com/000167.html
开发完成后的结果如下:
开发过程:
http://www.cnblogs.com/echosong/p/3500563.html
2、在中间放一个Label显示信息、在工具栏拉一个ContextMenuStrip和NotifyIcon作为最小化到托盘时的显示和退出菜单操作,其中notifyIcon1的ContextMenuStrip属性设为contextMenuStrip1,Icon属性设为本地一个IOCN图标文件。<div id="statuspzgz" class="fundpz"><span class="green bold">1.1843</span><div id="statuszdf" class="fundzf"><p class="green">-0.0067</p><p class="green">-0.56%</p></div><p class="time">2014-03-06 15:00</p></div>
解析用到的路径为:
//div[@id='statuspzgz']/span
//div[@id='statuszdf']/p[1]
//div[@id='statuszdf']/p[2]
//div[@id='statuspzgz']/p[@class='time']
完整代码如下:
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using HtmlAgilityPack;using System.Threading.Tasks;using System.Threading;using System.Runtime.InteropServices;namespace Demo{ public partial class Form8 : Form { const string url = "http://fund.eastmoney.com/000167.html"; public Form8() { InitializeComponent(); lblInfo.Text = ""; this.ShowInTaskbar = false;//任务栏不显示 this.Opacity = 0.60;//透明度 this.TopMost = true;//顶层显示 Task.Factory.StartNew(() => Do(cts)); } CancellationTokenSource cts = new CancellationTokenSource(); private void Do(CancellationTokenSource cts) { while (!cts.IsCancellationRequested) { string html = Utils.GetHtmlSource(url, Encoding.UTF8); if (string.IsNullOrEmpty(html)) return; HtmlNode rootNode = null; HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument(); document.LoadHtml(html); rootNode = document.DocumentNode; string s1 = GetNodeText(rootNode, "//div[@id='statuspzgz']/span"); string s2 = GetNodeText(rootNode, "//div[@id='statuszdf']/p[1]"); string s3 = GetNodeText(rootNode, "//div[@id='statuszdf']/p[2]"); string s4 = GetNodeText(rootNode, "//div[@id='statuspzgz']/p[@class='time']"); this.SafeCall(() => { lblInfo.Text = s1 + "\r\n" + s2 + "\r\n" + s3 + "\r\n" + s4; }); Thread.Sleep(1000 * 60); //每隔60s查询 } } private string GetNodeText(HtmlNode rootNode, string path) { HtmlNode temp = rootNode.SelectSingleNode(path); if (temp != null) return temp.InnerText; return ""; } [DllImport("user32.dll")] //方法扑捉 public static extern bool ReleaseCapture(); [DllImport("user32.dll")] public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam); public const int WM_SYSCOMMAND = 0x0112; public const int SC_MOVE = 0xF010; public const int HTCAPTION = 0x0002; void Panel2MouseDown(object sender, MouseEventArgs e) { //扑捉事件 ReleaseCapture(); //发送消息给window Api 来实现 SendMessage(this.Handle, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);// } private void label2_Click(object sender, EventArgs e) { Application.Exit(); } /// <summary> /// 隐藏窗体,并显示托盘图标 /// </summary> private void HideForm() { this.Visible = false; this.WindowState = FormWindowState.Minimized; notifyIcon1.Visible = true; } /// <summary> /// 显示窗体 /// </summary> private void ShowForm() { this.Visible = true; this.WindowState = FormWindowState.Normal; notifyIcon1.Visible = false; } private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e) { ShowForm(); } private void ToolStripMenuItemShow_Click(object sender, EventArgs e) { ShowForm(); } private void toolStripMenuItemExit_Click(object sender, EventArgs e) { Application.Exit(); } private void label1_Click(object sender, EventArgs e) { HideForm(); } }}其中GetHtmlSource方法可以参考另一文章:
C#采集CSDN单个博客所有文章
http://blog.csdn.net/gdjlc/article/details/11620915
0 0
- WinForm制作定时显示基金净值的桌面小工具
- WinForm制作定时显示基金净值的桌面小工具(续)
- 桌面小工具
- 定时提醒小工具
- WPF制作的天气预报小工具
- Googel桌面小工具使用手记
- Ubuntu----使用桌面小工具
- 实用win7桌面小工具
- 一个桌面整理小工具
- 写了一个桌面切换的小工具
- android app widget,安卓桌面小工具的使用
- MFC之桌面小工具仿360的一些功能
- 用Python写的一个monkeyrunner小工具(支持手机截图与定时截图,手机屏幕的显示)
- Java-Swing写的一个定时关机的小工具
- 一款保护眼睛,定时休息提醒的小工具
- 单词表制作小工具
- Java制作的快速打开文件夹、程序的小工具
- WIN7\Vista 边栏小工具的制作 HelloWorld
- fscanf读取double类型数据
- Eclipse解决乱码问题
- Android开发(01)-TextView显示丰富的文本
- GetLongPathName的使用
- hdu 3172:Virtual Friends
- WinForm制作定时显示基金净值的桌面小工具
- 一位ACMer过来人的心得
- JAVA中的时间操作
- 两台linux服务器传输文件
- 面对不确定的未来,马云有更大的不安全感
- UItextField
- java线程安全问题之静态变量、实例变量、局部变量
- 微信公共服务平台开发(.Net 的实现)13-------网页授权(下 :C#代码的实现 )
- REST