在WebBrowser中用SendMessage模拟鼠标点击

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace BrowserMouseClick
{
  public partial class Form1 : Form
  {
	  [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
	  static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);

	  [DllImport("user32.dll", SetLastError = true)]
	  static extern IntPtr GetWindow(IntPtr hWnd, uint uCmd);

	  [DllImport("user32.dll", CharSet = CharSet.Auto)]
	  static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

	  public Form1()
	  {
		  InitializeComponent();
	  }

	  private void Form1_Load(object sender, EventArgs e)
	  {
		  webBrowser1.Navigate("http://www.devpub.com");
	  }

	  private void btnMouseClick_Click(object sender, EventArgs e)
	  {
		  int x = 100; // X coordinate of the click
		  int y = 80; // Y coordinate of the click
		  IntPtr handle = webBrowser1.Handle;
		  StringBuilder className = new StringBuilder(100);
		  while (className.ToString() != "Internet Explorer_Server") // The class control for the browser
		  {
			  handle = GetWindow(handle, 5); // Get a handle to the child window
			  GetClassName(handle, className, className.Capacity);
		  }

		  IntPtr lParam = (IntPtr)((y << 16) | x); // The coordinates
		  IntPtr wParam = IntPtr.Zero; // Additional parameters for the click (e.g. Ctrl)
		  const uint downCode = 0x201; // Left click down code
		  const uint upCode = 0x202; // Left click up code
		  SendMessage(handle, downCode, wParam, lParam); // Mouse button down
		  SendMessage(handle, upCode, wParam, lParam); // Mouse button up
	  }
  }
}

想在WebBrowser控件里面模拟鼠标点击,在百度上找了半天,怎么也找不到,还是google强大,在一个国外网站上找到的,代码比较清楚了,不做说明。

用SendMessage在不同程序间发送消息

窗体1中的代码:

	/////////////////////////////////////////
	///file name: Note.cs
	///
	public class Note
	{
		//声明 API 函数
		[DllImport( "User32.dll", EntryPoint = "SendMessage" )]
		private static extern int SendMessage(
			  int hWnd,     // handle to destination window
			  int Msg,     // message
			  int wParam,   // first message parameter
			  int lParam   // second message parameter
		);
		[DllImport( "User32.dll", EntryPoint = "FindWindow" )]
		private static extern int FindWindow( string lpClassName, string lpWindowName );
		//定义消息常数
		public const int USER = 0x500;
		public const int TEST = USER + 1;

		//向窗体发送消息的函数
		private void SendMsgToMainForm( int MSG )
		{
			int WINDOW_HANDLER = FindWindow( null, @"Note Pad" );
			if( WINDOW_HANDLER == 0 )
			{
				throw new Exception( "Could not find Main window!" );
			}
			SendMessage( WINDOW_HANDLER, MSG, 100, 200 );
		}
	}

Read More »

如何启动Android SDK 1.5版的模拟器

装完Java JDK后。。。进入CMD….

如何启动Android SDK 1.5模拟器 Read More »

javascript里面的小数计算出现近似值的解决办法

在javascript里面,小数只能进行相似计算,例如:5.06+1.30,你得到的结果会是6.359999999999999,但有的小数计算又是正确的,如果计算出现了近似值,你可以用如下的方法计算:

var number1 = 5.06;
var number2 = 1.30;
var sum = (number1 * 100 + number2 * 100) / 100; //sum=6.36,不是一个近似值

这样计算可以得到一个准确的结果。

强迫Firefox安装低版本的扩展,不检查扩展兼容性

Firefox升级后,很多时候一些扩展都用不了了,有什么办法能让Firefox不检查扩展的兼容性呢?在config里面添加或者修改布尔值extensions.checkCompatibility,设置为false,这样可以避开Firefox的兼容性检查,但也存在一个风险,可能会导致Firefox不能启动,如果真的不能启动Firefox了,那只能把扩展都删掉了。

IETab居然下架了,Coral IETab代替

Firefox升级到3.6,一直使用的IETab无法使用了,本以为改了maxVersion可以用,没想到打开还是一片漆黑。在官方扩展区搜索IETab,居然都找不到了,看来这个扩展是真的停止开发了。本来以前也试过Coral IETab,但老是崩溃,现在没办法了,只能用Coral IETab顶上了,不知道现在的版本还会不会经常崩溃。

NetBeans中使用的Consolas字体并显示中文

安装了NetBeans,默认的字体实在看不下去,在设置里面把字体改为Consolas后,NetBeans怎么都显示不了中文,中文都变成了方块,解决问题的方法比较复杂,要修改Java配置文件,因为swing程序中的字体会在一个文件中进行配置。
首先要找到这个文件的地址,在netbeans的安装目录下的etc目录下有一个netbeans.conf的文件,打开这个文件找到netbeans所使用的jdk的路径。

在上图所示的路径下的jre\lib\文件夹下找到fontconfig.properies文件(如果没有——一般是没有的——就将fontconfig.properties.src复制或改名就ok),打开此文件,要修改3处地方。
1、在最后添加四行:

filename.Consolas=consola_1.ttf
filename.Consolas_Bold=consola_1.ttf
filename.Consolas_Italic=consola_1.ttf
filename.Consolas_Bold_Italic=consola_1.ttf

2、找到monospace.plain.**的这一行,按下面进行修改:

#monospaced.plain.alphabetic=Courier New
monospaced.plain.alphabetic=Consolas
monospaced.plain.chinese-ms950=MingLiU
monospaced.plain.hebrew=David
monospaced.plain.japanese=MS Gothic
monospaced.plain.korean=GulimChe

#monospaced.bold.alphabetic=Courier New Bold
monospaced.bold.alphabetic=Consolas Bold
monospaced.bold.chinese-ms950=PMingLiU
monospaced.bold.hebrew=David Bold
monospaced.bold.japanese=MS Gothic
monospaced.bold.korean=GulimChe

#monospaced.italic.alphabetic=Courier New Italic
monospaced.italic.alphabetic=Consolas Italic
monospaced.italic.chinese-ms950=PMingLiU
monospaced.italic.hebrew=David
monospaced.italic.japanese=MS Gothic
monospaced.italic.korean=GulimChe

#monospaced.bolditalic.alphabetic=Courier New Bold Italic
monospaced.bolditalic.alphabetic=Consolas Bold Italic
monospaced.bolditalic.chinese-ms950=PMingLiU
monospaced.bolditalic.hebrew=David Bold
monospaced.bolditalic.japanese=MS Gothic
monospaced.bolditalic.korean=GulimChe

3、修改字体的search顺序,按下图找到并修改:

# Search Sequences

sequence.allfonts=alphabetic/default,dingbats,symbol

sequence.serif.GBK=alphabetic,chinese-ms936,dingbats,symbol
sequence.sansserif.GBK=alphabetic,chinese-ms936,dingbats,symbol
sequence.monospaced.GBK=alphabetic,chinese-ms936,dingbats,symbol
sequence.dialog.GBK=alphabetic,chinese-ms936,dingbats,symbol
sequence.dialoginput.GBK=alphabetic,chinese-ms936,dingbats,symbol

现在在NetBeans中只要将字体设置成Consolas就可以显示漂亮的英文和中文了。

chrome扩展:显示网站收录数和反向链接数、PR及Alexa

看到有人在“GreaseMonkey脚本:显示每个网站的收录数和外链数及PR、Alexa”留言说要chrome上的扩展,今天有时间就把那个脚本修改了一下,翻了下chrome的扩展文档,简单的弄了个chrome上面的扩展,可以查常用的搜索引擎收录数和反链、alexa排名、PR、域名注册日期,扩展显示如下(搜狗的第一次查询要输入验证码才能查):

相比GM的那个脚本,没有弄设置项,没有快捷键(也不知道如何弄chrome扩展的快捷键),本来开始修改的时候弄的跟Firefox里面一样显示的,也是显示在网页里面,不是从chrome的扩展栏点击那个图标弹出popup小窗口,但弄到最后,才发现包含在页面里面的脚本居然不能跨域请求,郁闷死,非要放在popup页里或者其它包含页里才能跨域(即使设置了permission也不行),只好弄成现在这样了,这样就失去了快捷键的功能,先就只能这样了。欢迎拍砖!

扩展下载地址:http://www.junstyle.com.cn/upload/files/SEInformation.rar,先把压缩包解压,然后把里面的SEInfomation.crx拖到chrome里面就可以安装了,或者用chrome打开它也行!

火狐Firefox里九个非常有用的快捷键

1:Alt+D

你可以使用该快捷键直接把光标转到火狐的地址栏。非常有用。

2:网址后缀.org和.net的自动完成

我们知道,如果我们在地址栏输入google,然后按下Ctrl+Enter ,然后浏览器就会转到www.google.com。但是如果我们想对网址输入.org或者.net后缀呢?在火狐中,Shift+Enter 会自动给网址后缀加入.net ,Ctrl+Shift+Enter会自动给网址后缀加入.org。所以如果你想去Problogger,只需要在火狐地址栏输入该单词,然后按下 Shift+Enter。

3:Ctrl+T和Ctrl+Shift+T

Ctrl+T帮你打开一个新标签,Ctrl+Shift+T重新打开上次关闭的标签。

这个快捷键显得非常便捷在你意外关闭一个标签后。另外一种方法就是到历史→最近关闭的标签来找到并打开。

4:使用Delete键

Delete非常有用因为你可以用来删除浏览器的一些历史栏的或者自动填充表格的特定地址。比如在下边表格,当我在google的地址栏输入“a”你可以看到三个下拉条目。如果我想在自动完成历史里删除掉第二个条目,我把鼠标指向它然后按下Delete键就可以了。

5:Ctrl+Tab

Ctrl+Tab可以帮你在不同火狐标签间轻松切换。

6:鼠标中键

这不是一个键盘快捷键但是是一个很好的快捷键。指向任何一个链接并按下鼠标中键(即滚轮),然后该页面会在新标签打开。

7:Alt+Enter

这个是一个非常有用的快捷键。它可以在你选中自动完成列表里边的项目时自动在另外一个标签打开一个网站。例如,你想去Facebook,你开 始在地址栏输入www.face…,同时它开始在下拉列表显示。你仅需使用下方向键选中(该例子中是facebook.com)同时按下 Alt+Enter这样就可以在新标签打开。

8:Ctrl+[1,2….9]

Ctrl+Tab可以用来在交替切换不同的标签,但是如果你是像我一样喜欢打开很多标签的用户同时希望转到一个特定的标签,你可以使用Ctrl+相应标签的序号。比如:转到第三个标签使用Ctrl+3。

9:空格键和Shift+空格键或者PageDown和PageUp

空格键或者PageUp键可以下翻当前页面,Shift+空格键和PageUp可以上翻当前页面。

百度site首页出现两个不同的结果

今天加一个友情链接,在百度site了一下他的网站,百度居然出现了这样的结果,首页的出现了两天记录,分别排第一和第二,而且快照时间也不一样,很是奇怪!看下图:

两个首页的标题有点区别,可能这段时间修改过标题,百度就把修改前和修改后的首页都保存了?