星期四, 九月 24, 2009

算法挑战 36进制条码序列号生成器[修正]

问题描述:
条码打印.要求是唯一的序列.中间有一个日期,最后3位为流水号.但打印的张数会超过999;
因此必须用到26个大写字母,用36进制的话3位可以表示36*36*36=46656个数字。
现在要求如下:
999以前就是普通数字(001~999),再多就开始在百位使用字母
即999的后一个数字为A00此时十位和个位还不能使用字母(平时打印会少于3600张,为了客户看起来方便),
只有在百位将Z用完后才允许在十位使用字母,十位用完才允许个位使用字母
注意事项:
1)不能重复
2)数字个数应达到46656个
3)效率不能太低
4)请在本地测试没有重复序列号
博客: http://www.cnblogs.com/shinn/archive/2008/04/22/1147473.html 给了算法思路,但他的代码有问题。
我的分析:

 

[jjwt.png]

[jieguo.png]

我的代码:

/*


 * Created by SharpDevelop.


 * User: liuyk


 * Date: 2009-9-22


 * Time: 22:05


 */


using System;


namespace ConvertTo36X


{


    /// <summary>


    /// 把[0-46655]转换成36进制的3位序列.


    /// </summary>


    public class ConvertTo36X


    {


        private readonly char[] Char26=new char[]{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};


        private readonly char[] Char36=new char[]{'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};


 


        public string ConvertNum(int num)


        {


        if(num<0 || num>46655)


        {


        throw new Exception("输入的数字超出范围");


        }


        else if(num>=12960)


        {


        string value="";


        num-=12960;


        char h=Char36[((int) (num/936))%36];


        char t=Char36[((int) (num/26))%36];


        char d=Char26[num%26];


        return value+h+t+d;


        }


        else if(num>=3600)


        {


        string value="";


        num-=3600;


        char h=Char36[(int)((num%360)/10)];


        char t=Char26[(int)(num/360)];


        int d=num%10;


        return value+h+t+d;


        }


        else if(num>=10)


        {


        string value="";


        char h=Char36[(int)(num/100)];


        num=num%100;


        int t=(int)(num/10);


        int d=num%10;


        return value+h+t+d;


        }


        else


        {


        return "00"+num;


 


        }


 


        }


 


    }


 


 


 }






/*


 * Created by SharpDevelop.


 * User: liuyk


 * Date: 2009-9-24


 * Time: 17:09


 * 


 * To change this template use Tools | Options | Coding | Edit Standard Headers.


 */


using System;


using   System.IO;   


namespace ConvertTo36X


{


    class TestConvertTo36


    {


        public static void Main(string[] args)


        {


            Console.WriteLine("Hello World!");


 


            // TODO: Implement Functionality Here


                        ConvertTo36X xx=new ConvertTo36X();


            FileStream   fileName  =   new   FileStream("Temp.txt",FileMode.OpenOrCreate);  


            StreamWriter sw = new StreamWriter(fileName);


 


 


            //System.Console.WriteLine(xx.ConvertNum(46655));


        for (int j=0;j<=46655;j++){


            System.Console.WriteLine(j);


            sw.WriteLine(xx.ConvertNum(j)); 


 


        }


            sw.Close();


 


 


            Console.Write("Press any key to continue . . . ");


            Console.ReadKey(true);


        }


    }


}

把数字转换成36进制

把数字转换成36进制
36进制包括0-9和a-z,只有整形的可以转换。
long i=1234567890L;
System.out.println(Long.toString(i,36).toLowerCase());
输出:kf12oi

星期四, 九月 03, 2009

如何让Chrome支持MonkeyGTD、Tiddly本地存储?

问题:
————————————————————————————————————————
有用以下GTD工具的吗?
MonkeyGTD 3.0----GTD system based on MPTW.
d3 (new version)----GTD system from dcubed.ca (http://www.dcubed.ca/Welcome_to_d-cubed.html 需要翻墙)
我现在只能用Firefox使用上述工具,IE太慢,GoogleChrome不能本地存储。 想请问各位高人,如何让Chrome打开JavaScript本地存储功能?
——————————————————————————————————————————
解答:
1、到 http://monkeygtd.blogspot.com/2008/09/monkeygtd-and-chrome-new-best-friends.html 网站下载TiddlySaver.jar
2、到http://java.com 下载最新版 java
3、把TiddlySaver.jar 和monkeygtd.html或者d3_doit_delegateit_deferit的htm文件
放到同一个路径下。
4、在最新版本的Chrome里打开本地的monkeygtd.html,提示安装时点同意。

Puff the magic dragon

http://hi.baidu.com/fiber/blog/item/7c0b9cef7de244e6ce1b3e2c.html

星期一, 六月 01, 2009

blogspot.com是不是又抽风了?

刚用得舒服,就不能访问了。郁闷。。。不知何故

星期五, 五月 15, 2009

[转]Chrome启动参数方案

下面是常用的一些启动参数:
–user-data-dir=UserDataDir 自定义用户数据目录
–start-maximized 启动就最大化
–no-sandbox 取消沙盒模式
–single-process 单进程运行
–process-per-tab 每个标签使用单独进程
–process-per-site 每个站点使用单独进程
–in-process-plugins 插件不启用单独进程
–disable-popup-blocking 禁用弹出拦截
–disable-javascript 禁用JavaScript
–disable-java 禁用Java
–disable-plugins 禁用插件
–disable-images 禁用图像
A Complete list to Google Chrome Startup Switches…
see below
-disable-hang-monitor
-disable-metrics
-disable-metrics-reporting
-assert-test
-renderer-assert-test
-crash-test
-renderer-crash-test
-renderer-startup-dialog
-plugin-startup-dialog
-testshell-startup-dialog
-plugin-launcher
-channeltesting-channel
-homepagestart-renderers-manuallyrenderer
-renderer-pathplugin
-single-process
-process-per-tab
-process-per-site
-in-process-plugins
-no-sandbox
-safe-plugins
-trusted-plugins
-test-sandbox
-user-data-dir
-appupload-file
-dom-automation
-plugin-pathjs-flags
-geoidlangdebug-children
-wait-for-debugger-children
-log-filter-prefix
-enable-logging
-dump-histograms-on-exit
-disable-logging
-remote-shell-port
-uninstallomnibox-popup-count
-automation-channel
-restore-last-session
-record-mode
-playback-mode
-no-events
-hide-icons
-show-icons
-make-default-browser
-proxy-server
-dns-log-details
-dns-prefetch-disable
-debug-print
-allow-all-activex
-disable-dev-tools
-always-enable-dev-tools
-memory-model
-tab-count-to-load-on-session-restore
-memory-profile
-enable-file-cookies
-start-maximized
-enable-watchdogfirst-run
-message-loop-strategy
-message-loop-histogrammer
-importsilent-dump-on-dcheck
-disable-prompt-on-repost
-disable-popup-blocking
-disable-javascript
-disable-java
-disable-plugins
-disable-images
-use-lf-heap
-new-http

本文来源于谷歌Chrome中文站 http://www.downdig.com/chrome , 原文地址:

Chrome启动参数及地址栏功能

Chrome启动参数及地址栏功能,希望各位大力支持(持续更新)。
转: http://bbs.webmou.com/thread-2343-1-1.html

启动参数
--disable-plugins 禁用插件
--User-data-dir=dir 设置缓存
--single-process 单线程模式
--no-sandbox 非沙箱模式
process-per-tab 每个标签使用单独进程
process-per-site 每个站点使用单独进程
in-process-plugins 插件不启动单独进程
start-maximized 启动就最大化
first-run 第一次运行
disable-popup-blocking 禁用弹出拦截
disable-javascript 禁用javascript
disable-java 禁用java
disable-images 禁用图像

disable-hang-monitor
disable-metrics
disable-metrics-reporting
assert-test
renderer-assert-test
crash-test
renderer-crash-test
renderer-startup-dialog
plugin-startup-dialog
testshell-startup-dialog
plugin-launcher
channel
testing-channel
homepage
start-renderers-manually
renderer
renderer-path
plugin
safe-plugins
trusted-plugins
test-sandbox
app
upload-file
dom-automation
plugin-path
js-flags
geoid
lang
debug-children
wait-for-debugger-children
log-filter-prefix
enable-logging
disable-logging
log-level
dump-histograms-on-exit
remote-shell-port
uninstall
omnibox-popup-count
automation-channel
restore-last-session
record-mode
playback-mode
no-events
hide-icons
show-icons
make-default-browser
proxy-server
dns-log-details
dns-prefetch-disable
debug-print
allow-all-activex
disable-dev-tools
always-enable-dev-tools
memory-profile
memory-model
enable-file-cookies
enable-watchdog
message-loop-histogrammer
import
silent-dump-on-dcheck
disable-prompt-on-repost
use-lf-heap
gears-plugin-path
gears-in-renderer
new-http
javascript-debugger-path
enable-p13n


地址栏功能:
about:version - 显示当前版本 也可以是chrome-resource://about/
about:plugins - 显示已安装插件,Google Chrome支持Active X!
about:histograms - 显示历史记录
about:dns - 显示DNS状态
about:cache, 重定向到 view-cache: 显示缓存页面
view-cache:stats - 缓存状态
about:stats - 显示状态
about:network - 很酷的网络工具
about:internets - 这应该算是一个彩蛋
chrome-resource://new-tab/ - 新标签页
about:memory - 可以查看内存和进程占用。也可以Shift+ESC,点击Statistics for nerds(傻瓜统计信息)

谷歌浏览器(Google Chrome)不支持本地js文件

I am using the jQuery Cookie plugin (download and demo and source code with comments) to set and read a cookie. I'm developing the page on my local machine.

The following code will successfully set a cookie in FireFox 3, IE 7, and Safari (PC). But if the browser is Google Chrome AND the page is a local file, it does not work.

$.cookie("nameofcookie", cookievalue, {path: "/", expires: 30}); 

What I know:

  • The plugin's demo works with Chrome.
  • If I put my code on a web server (address starting with http://), it works with Chrome.

So the cookie fails only for Google Chrome on local files.

Possible causes:

  • Google Chrome doesn't accept cookies from web pages on the hard drive (paths like file:///C:/websites/foo.html)
  • Something in the plugin implentation causes Chrome to reject such cookies

Chrome doesn't support cookies for local files unless you start it with the --enable-file-cookies flag. You can read a discussion about it at http://code.google.com/p/chromium/issues/detail?id=535.


Get organized with GTDTiddlyWiki

Get organized with GTDTiddlyWiki

by Jason Thomas

Everyone has to find their own killer personal organizational app, and for me, it's a single, free HTML document calledGTDTiddlyWiki. The self-contained standalone mini-wiki is packed with features but it doesn't dictate how you work - it provides a canvas on which you can design your own process improvements and workflows.

Don't let GTDTiddlyWiki's unusual name put you off. It's one of the best organization apps available, and in fact it beats the pants off all the commercial organizational software I've tried.

If you're looking for your killer app, today I've got a primer on how I've put GTDTiddlyWiki to work for me.

What's GTDTiddlyWiki?

GTDTW is an HTML document that you save to your local hard drive and edit there using your web browser. When you save information, it edits itself, and stores what you've written in an internal data format. This is very convenient for people who are into portable apps on USB keys, because it's completely self-contained, always with you and only requires a web browser to edit. It's also very easy to back it up: just send it up to your Gmail account every few days, or better yet schedule a job to do it for you.

To download GTDTW, right-click this GTDTiddlyWiki link and save it to a folder on your desktop. Don't save it to your desktop if you intend to keep it there; I'll explain why in a minute. In fact, you don't even need to save it at all: you can follow through most of this tutorial with the one that's up there on the site.

Now that you've saved it, load it up in Firefox. You're going to see something like this (click to enlarge):

Over there on the left is a menu. That's all editable, and it's one way you can get around in GTDTW.

Over on the right are what they call "tiddlers." These are analogous to pages in a traditional wiki. You could also say that they're like notecards in a Hipster PDA, and that's no accident: GTDTW was designed from the get-go to work like index card stacks. You can even print tiddlers to index cards, so you have a nice way of dumping out lists and so on for when you're on the go.

Editing GTDTiddlyWiki

GTDScreenshot2.jpg

There's a button on the menu to the left that says "CreateNewTiddler." Click it. On the right, you'll see a new card appear. Double-click it, enter a title — for now, call it Lists — and type in some text. When you're finished, click "done" or just hit Ctrl-Enter. Your tiddler's finished now. But it's not saved permanently yet. To do so, click "save changes" on the menu. Your first time it will trigger a Firefox warning telling you that the Javascript wants to save something on your local hard drive. Click the "Allow" button and check off "Remember this decision" so you don't get asked every time. You're good to go now, and next time you load up GTDTW your new tiddler will show up in the system.

Note: If you've never done much with wikis before, the formatting involved can seem daunting at first. GTDTW syntax is a simplified version of the highly evolved app that runs Wikipedia, but it does take getting used to. Bear with me; after a little practice it becomes automatic.

Building your GTDTiddlyWiki

You've probably evolved a number of organizational methods of your own that fit your own work style. You're probably going to want to edit the menu to reflect your own process. To do that, click on the "MainMenu" button in the menu. It pops up a tiddler. That's right — the menu itself lives on a tiddler, and you can edit it just like any other card. Click the yellow "edit" button on the MainMenu tiddler. You'll see a number of entries in brackets. Add a new one: type "[[Lists]]" and close the card. Now, over on the left, you should see the item appear in the menu. Click the menu item Lists and the new card you made earlier should appear. Snazzy.

You might want to call it something more descriptive than that. I have one called "Ideas" that I use to reference other cards containing ideas for articles, projects, etc. Here's how to link to other cards from within a tiddler:

Say you're going on vacation and you need to remember to bring everything with you. That would be a new list, so you want it to be referenced from your "Lists" card.

Open up "Lists" from the menu, or if you already have it open, just double-click it to edit the card. On it, you have whatever you typed earlier. Now, type "VacationList" and close the tiddler. It's important that you make it one single word with two capitals ("camel case"). That's a WikiWord, and it's how wiki's indicate links to other pages. Alternatively, you can just enclose the word in double brackets like we did above.

You'll see that VacationList link is on there, and it's in italics. The italics mean that the tiddler hasn't been created yet. Click that link and it'll create a new tiddler called VacationList. You can edit that tiddler to indicate everything you need to bring with you. You can make it a bulleted list by typing an asterisk ahead of each word.

If you want, just paste the following text into your new card:

!Packing
*Into Suitcase
**Scarf
**Gloves
**iPod

!Shopping
*Sporting Goods Store
**New Boots
**Trail Mix
**Pocket Heaters

When you click "Done," here's what it should look like:

GTDScreenshot4.jpg

Here's a tip for things like shopping or packing lists you might print out to index cards: If you use a double asterisk, it'll result in an empty circle instead of a solid bullet. That way, when you finish each item on the list, just fill in the corresponding circle. Make sure to use a sharp number 2 pencil! That and numerous other tips are on the FormattingInstructions menu item.

Configuring GTDTiddlyWiki

GTDScreenshot3.jpg

There are a few little usability issues with GTDTW, but they're easy to get around. Firstly, you should go into "options" on the menu and click "AutoSave." I also uncheck "EnableAnimations," because sometimes the animations can result in slowness, especially if you're running from remote over X or through something like VMWare.

The reason AutoSave is so important is because GTDTW lives in Firefox. More specifically, it lives in a Firefox tab. It's real easy to forget and start up multiple instances of GTDTW, making you run into version control issues. You also might just accidentally close the tab GTDTW is on, and even though it'll ask you to confirm, you don't want to be adding a lot of cards to the system, switch to another tab and forget to save it.

In Options, you'll also notice a checkbox labeled "Save Backup." That button is the reason why you don't want to throw GTDTW onto your desktop. It saves incremental backups every time you make a change, each one in its own new file. This is nice in case you make a mistake or need to revert, but it can result in clutter that you don't really need, so you want to place GTDTW in its own separate folder. Once your GTDTW file grows to a few megs or so, you'll also want to go into its folder and clear out some of the older backup files occasionally to save disk space, because it can add up.

When I want to back up my GTDTW, I just send it to a Gmail account I've set up for handling backups. I have a Linux cron job that sends it up there every day. That way, you keep running incremental backups of your work over time. It's not good to use Gmail as a primary file storage, but it's great for backups like this because it keeps everything nicely organized by date. You could also just use your "Gmail This" bookmarklet and add your saved GTDTW file as an attachment. Here's a previous Lifehacker feature on emailing yourself backups on Windows.

External links to your other capture tools

For a while, I was adding everything under the sun into GTDTW. Now, not so much. The file will get big, bloated and unwieldy. For a while, I was linking to files on my local hard drive (see the LinktoFolders tiddler under FormattingInstructions), but that's unwieldy too if you move from computer to computer.

Better to link to your Google Notebooks and store information there. Just add an external link to a tiddler like so:[[MyNotebook|http://www.google.com/notebook/]]. If you're logged into Google Notebook, it'll bring up your full page view. In Firefox, you can just middle-click the link and it will open in a new tab.

Ready to print something to notecards? Just hit "Print" from your browser and the tiddlers you have open will print just as nice as could be.

You'll find that your methods for using GTDTW will evolve over time. For a while, I was using GTDTW for my monthly planner. Now, under my "Agenda" menu item, I have a link to my Google calendar. You guessed it— it's just the same as above, except the link looks like this: [[http://www.google.com/calendar/]].

GTDTW is a great tool for research, organizing different clippings, images and whatnot into an format that's easy to navigate and search. In fact, you might want to save Google searches to look at later. Just link to them:[[Lifehacker|http://www.google.com/search?q=lifehacker]]

I could go on for probably twenty more pages about all the ways I've used GTDTW. I'm not even touching on how to use tags, or the search utility, or the full-featured regular expression searching that it offers.

GTDTiddlyWiki took getting used to, but now I use it every day. But in its customizability lies a pitfall: it has the potential to be an incredible distraction and time-waster. Don't just play with it like a new toy and then discard it. Work up a system and stick with it for a while, actually use it. Then, after you've integrated it into your workflow, start refactoring: look at the way you're using it and figure out how you can streamline your process. That's how you get continual improvement over time.

For more ideas of what you can do with these great apps, check tiddlywiki.com. Also, thank the developers. They deserve it.


4 Free Proxies To Block Ads in Google Chrome (or any browser)

4 Free Proxies To Block Ads in Google Chrome (or any browser)


So you've tested Google Chrome and decided that you like it. You say you'd switch, but there's no adblocker? Fortunately for you, there are several free, tiny filtering proxy applications available that can do the job.

The best part is, they'll help block ads in any browser - including Chrome.

Before I get into a list, it's important to know that several of these apps haven't been updated in ages. However, content filtering is a pretty straightforward operation, so even the old ones work just fine - and you can always tweak the blocking rules yourself.

CyberGuard WebWasher Classic
is another great option. It's small, fast, and very customizable. It's got additional capabilities to block popups, scripts, referrers, cookies, and prefixes. New filters are incredibly easy to set up, and there's no noticeable lag in load times. Of the apps I tested, WebWasher was my favorite.

Proxomitron has a god awful GUI, but it works well enough that its appearance can be overlooked (you can create your own bitmaps if you really hate it). It offers extremely flexible bloxing rules, and the default set is extrmely effective. Blocked ads are replaced with [red text in brackets], and pages load times weren't adversely affected.


iReject Trash is a tiny download (200k) and works extremely well. Its log view also gives you an interesting insight into the pages you're visiting. CNET.com, for example, had 33 items blocked. Out-of-the-box the blocking was very good, and the rules are fully customizable. You can block by host, pattern, or image dimensions. Page load times were a bit slower on certain sites.

Lifehacker suggests Privoxy
as an option (via GeekZone NZ). Privoxy is more low-fi: all your configuration tweaks are done by editing text files. It is, however, very easy on processor usage and it also does a very good job with no tweaking. I didn't notice any difference in page load times with Privoxy.

There are tons of other options for blocking ads (just check the Google Directory), so don't give up on Chrome just because there's no AdBlock. Grab one of these apps, and give it another try - then tell us how it went!

星期四, 五月 14, 2009

WINRAR KEY 注册码

选择对应的代码复制到TXT文本文档中,命名为rarreg.key放入WinRAR 的安装目录中的文件中(如果没有就自己创建一个)!!
呃,多嘴说一句,使用方法不是双击 RarReg.key 导入注册表
而是把 RarReg.key 放到 WinRAR 的安装目录
WinRAR 的安装目录通常在 C:\Program Files\WinRAR

3.6 beta8版以下:

RAR registration data
Alexander Aymanov
Single PC usage license
UID=dc1d9fdb26f9be064d83
64122122504d83d04ee243231738b88600fb267f1d3b9632421295
d1048b98780395138be06035c6ab9048e2c5c62f0238f183d28519
aa87488bf38f5b634cf28190bdf438ac593b1857cdb55a7fcb0eb0
c3e4c2736090b3dfa45384e08e9de05c58609e0915bfdc561003a6
755c95e82155892c0f36e7ff4b3d62f55230e8ad51b6756d092d0b
89e5c480d3449cc0c7d9ab1d3d4abb32baf07ebabe0e145e608494
e628198aaef1e665f9d63f719cb57ef19f3443f31a830478060233

3.71版以下:
RAR registration data
Ian Gledhill
Single PC usage license
UID=1b80823684224d9b748a
6412212250748a81108382cda7d3d039b93ea05369c1b3222bcc93
248e0a5c901e7a89b5946035c6ab9048e2c5c62f0238f183d28519
aa87488bf38f5b634cf28190bdf438ac593b1857cdb55a7fcb0eb0
c3e4c2736090b3dfa45384e08e9de05c58604100fe88f402153c05
aa6e9cf44271379afcc502a027ec9ef029e9691f1d734d58eb8016
4dfef1ff926eee74128b50442ab561e9abfdd6b8490e36e46004bb
71874b07a0fb27a6c5d662140fae567747083ae2ed070249382990

3.80版以下:

RAR registration data
Database Administrators
5 PC usage license
UID=54d582e921e445f1bfe8
6412212250bfe8e73e20bdb947f60ef0da9624150bcf8668412c68
84affda559742bbb686d6071302587655a7ba28d516e17834b7616
47cd79a293eb4c0e4fbf5e9f967e6ed5b28a02418d0ab2549fc4da
19e4644f2345190bf26ff7bcd0c819f12560b57cf28adc164a00c6
3174fcbb69509912e7c7c4793779b941901c6c793b7319cc395ee0
8bddb923fa08fc20019b59d0b246e0ac325d2e5854d4f97a602fc0
a4357b8f857cfb717545410ecad088fb28a2a3cf0dff2102863273

3.60 beta8 :

RAR registration data
vncodered
Single PC usage license
UID=1779147d103f2fdbd317
6412212250d317d5ea5a69ea5936c8a67dd60fc5eb0e3b230a0cce
d95d6cc8c4b5248e40986035c6ab9048e2c5c62f0238f183d28519
aa87488bf38f5b634cf28190bdf438ac593b1857cdb55a7fcb0eb0
c3e4c2736090b3dfa45384e08e9de05c5860266bd3d416f192e71b
c2ec1d27fd4b058c495a2bf7e1ad7bbddbbee27df7988217761f42
45d28472a7591f8faaf3e78c78f9f97112fcd8a662a5401c60d21a
2e9f208d4dd673099d78613e7a1bc45bac1f6d65a10a1775209829

WinRAR 3.8 key!注册文件(共2个,任选一个都行,


请复制另存为文本文件,命名为以下名称 rarreg。key,并保存在winrar文件夹里。}

WinRAR v3.80 Final working key





注册码1
=================================================

RAR registration data
Federal Agency for Education
1000000 PC usage license
UID=b621cca9a84bc5deffbf
6412612250ffbf533df6db2dfe8ccc3aae5362c06d54762105357d
5e3b1489e751c76bf6e0640001014be50a52303fed29664b074145
7e567d04159ad8defc3fb6edf32831fd1966f72c21c0c53c02fbbb
2f91cfca671d9c482b11b8ac3281cb21378e85606494da349941fa
e9ee328f12dc73e90b6356b921fbfb8522d6562a6a4b97e8ef6c9f
fb866be1e3826b5aa126a4d2bfe9336ad63003fc0e71c307fc2c60
64416495d4c55a0cc82d402110498da970812063934815d81470829275

=================================================

RAR registration data
Database Administrators
5 PC usage license
UID=54d582e921e445f1bfe8
6412212250bfe8e73e20bdb947f60ef0da9624150bcf8668412c68
84affda559742bbb686d6071302587655a7ba28d516e17834b7616
47cd79a293eb4c0e4fbf5e9f967e6ed5b28a02418d0ab2549fc4da
19e4644f2345190bf26ff7bcd0c819f12560b57cf28adc164a00c6
3174fcbb69509912e7c7c4793779b941901c6c793b7319cc395ee0
8bddb923fa08fc20019b59d0b246e0ac325d2e5854d4f97a602fc0
a4357b8f857cfb717545410ecad088fb28a2a3cf0dff2102863273

星期三, 五月 13, 2009

SUDOKU破解与生成程序1.0

不多说了,增加了第三逻辑和对可能情况的遍历(也就是当不能用逻辑区分的时候的暴力破解)。
http://lostabaddon.spaces.live.com/cns!EB06676D0B60BFBD!1986.entry
FrmSudoku.FRM:
Option Explicit
Dim SUDOKU(9, 9, 9) As Integer
Dim SudokuSolution As New ClsSudoku
Private Sub CmdClear_Click()
Dim I As Integer, J As Integer, K As Integer
For I = 1 To 9
For J = 1 To 9
For K = 0 To 9
SUDOKU(I, J, K) = 0
Next K
Next J
Next I
ShowSUDOKU
End Sub
Private Sub Form_Load()
Dim I As Integer, J As Integer, X As Integer, Y As Integer
Dim T As Integer
Dim P As Single
P = (Me.ScaleWidth - 3700) / 2
TxtInput(0).Visible = False
For I = 1 To 3
For J = 1 To 3
For X = 1 To 3
For Y = 1 To 3
T = ((I - 1) * 3 + (J - 1)) * 9 + ((X - 1) * 3 + Y)
Load TxtInput(T)
TxtInput(T).Left = ((I - 1) * 3 + X - 1) * 400 + (I - 1) * 50 + P
TxtInput(T).Top = ((J - 1) * 3 + Y - 1) * 400 + (J - 1) * 50
TxtInput(T).Visible = True
TxtInput(T) = ""
Next Y
Next X
Next J
Next I
CmdStart.Top = Me.ScaleHeight - CmdStart.Height
CmdGenerate.Top = Me.ScaleHeight - CmdGenerate.Height
CmdStart.Left = (Me.ScaleWidth - CmdStart.Width - CmdGenerate.Width) / 2
CmdGenerate.Left = (Me.ScaleWidth - CmdStart.Width - CmdGenerate.Width) / 2 + CmdStart.Width
End Sub
Private Sub CmdStart_Click()
ReadSUDOKU
If SudokuSolution.Solution(SUDOKU) Then
ShowSUDOKU
End If
ShowSUDOKU
End Sub
Private Sub CmdGenerate_Click()
SudokuSolution.Build SUDOKU
ShowSUDOKU
Me.Caption = "Sudoku Solution"
End Sub
Private Sub TxtInput_DblClick(Index As Integer)
Dim A As Integer
A = Int((Index - 1) / 9) + 1
Dim X As Integer, Y As Integer
X = A - Int(A / 3) * 3
If X = 0 Then X = 3
Y = Int((A - 1) / 3 + 1)
A = Index - ((Y - 1) * 3 + X - 1) * 9
Dim I As Integer, J As Integer
I = A - Int(A / 3) * 3
If I = 0 Then I = 3
J = Int((A - 1) / 3 + 1)
MsgBox Str((X - 1) * 3 + I) & "," & Str((Y - 1) * 3 + J)
End Sub
'辅助区
Private Sub ReadSUDOKU()
Dim I As Integer, J As Integer, X As Integer, Y As Integer
Dim T As Integer, Q As Integer, K As Integer
For I = 1 To 3
For J = 1 To 3
For X = 1 To 3
For Y = 1 To 3
T = ((I - 1) * 3 + (J - 1)) * 9 + ((X - 1) * 3 + Y)
Q = Val(TxtInput(T))
If Q >= 0 Then
SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, 0) = Q
End If
For K = 1 To 9
SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, K) = 0
Next K
Next Y
Next X
Next J
Next I
End Sub
Private Sub ShowSUDOKU()
Dim I As Integer, J As Integer, X As Integer, Y As Integer
Dim T As Integer, Q As Integer
For I = 1 To 3
For J = 1 To 3
For X = 1 To 3
For Y = 1 To 3
T = ((I - 1) * 3 + (J - 1)) * 9 + ((X - 1) * 3 + Y)
Q = SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, 0)
If Q > 0 Then
TxtInput(T).Text = Q
Else
TxtInput(T).Text = ""
End If
Next Y
Next X
Next J
Next I
End Sub
'辅助区结束
ClsSudoku.CLS:
Option Explicit
Dim SUDOKU(9, 9, 9) As Integer
'功能区
Public Function Solution(ByRef S() As Integer) As Boolean
Dim I As Integer, J As Integer, T() As Integer, K As Integer
Dim IsOK As Boolean
ReDim T(0)
GetSUDOKU S
Solution = False
If Check Then
If Not CheckEmpty Then
Exit Function
End If
Else
Exit Function
End If
IsOK = True
Do While IsOK
IsOK = Deal Or ThirdLogic
Loop
Solution = IsFinished
If Solution Then
BackSUDOKU S
Else
Find I, J, T
If UBound(T) = 0 Then Solution = False: Exit Function
For K = 1 To UBound(T)
If Try(I, J, T(K)) Then BackSUDOKU S: Solution = True: Exit For
Next K
End If
End Function
Public Sub Build(ByRef S() As Integer)
'初始化最原始SUDOKU
Dim I As Integer
For I = 1 To 9
SUDOKU(I, 1, 0) = I
Next I
For I = 1 To 3
SUDOKU(6 + I, 2, 0) = I
SUDOKU(I, 3, 0) = 6 + I
Next I
For I = 1 To 6
SUDOKU(I, 2, 0) = 3 + I
SUDOKU(3 + I, 3, 0) = I
Next I
For I = 1 To 8
SUDOKU(I, 4, 0) = I + 1
SUDOKU(I + 1, 7, 0) = I
Next I
SUDOKU(3, 4, 0) = 1
SUDOKU(6, 4, 0) = 4
SUDOKU(9, 4, 0) = 7
SUDOKU(1, 7, 0) = 3
SUDOKU(4, 7, 0) = 6
SUDOKU(7, 7, 0) = 9
For I = 1 To 5
SUDOKU(I, 5, 0) = I + 4
SUDOKU(I + 1, 8, 0) = I + 3
Next I
SUDOKU(6, 5, 0) = 7
SUDOKU(7, 5, 0) = 2
SUDOKU(8, 5, 0) = 3
SUDOKU(9, 5, 0) = 1
SUDOKU(3, 5, 0) = 4
SUDOKU(1, 8, 0) = 6
SUDOKU(4, 8, 0) = 9
SUDOKU(7, 8, 0) = 3
SUDOKU(8, 8, 0) = 1
SUDOKU(9, 8, 0) = 2
For I = 1 To 5
SUDOKU(I + 3, 6, 0) = I + 1
SUDOKU(I + 4, 9, 0) = I
Next I
SUDOKU(1, 6, 0) = 8
SUDOKU(2, 6, 0) = 9
SUDOKU(3, 6, 0) = 7
SUDOKU(6, 6, 0) = 1
SUDOKU(9, 6, 0) = 4
SUDOKU(1, 9, 0) = 9
SUDOKU(2, 9, 0) = 7
SUDOKU(3, 9, 0) = 8
SUDOKU(4, 9, 0) = 3
SUDOKU(7, 9, 0) = 6
'SUDOKU混排
I = 5 + Int(Rnd() * 10)
Do While I > 0
If Rnd() > 0.5 Then
RowTrans 1 + Int(Rnd() * 3), 1 + Int(Rnd() * 3)
Else
ColTrans 1 + Int(Rnd() * 3), 1 + Int(Rnd() * 3)
End If
I = I - 1
Loop
For I = 1 To 6
RowTrans 1 + Int(Rnd() * 3), 1 + Int(Rnd() * 3)
ColTrans 1 + Int(Rnd() * 3), 1 + Int(Rnd() * 3)
Next I
Cycle
Cover
BackSUDOKU S
End Sub
'功能区结束
'辅助区
Private Function Try(ByVal I As Integer, ByVal J As Integer, ByVal T As Integer) As Boolean
Dim SS(9, 9, 9) As Integer
BackSUDOKU SS
SS(I, J, 0) = T
Dim SSS As New ClsSudoku
Try = SSS.Solution(SS)
If Try Then
GetSUDOKU SS
End If
End Function
Private Sub Find(ByRef I As Integer, ByRef J As Integer, ByRef T() As Integer)
Dim A As Integer, B As Integer, C As Integer
Dim D As Integer, E As Integer
E = 10
For A = 1 To 9
For B = 1 To 9
If SUDOKU(A, B, 0) = 0 Then
D = 0
For C = 1 To 9
If SUDOKU(A, B, C) = 1 Then D = D + 1
Next C
If D < E And D > 0 Then
ReDim T(0)
For C = 1 To 9
If SUDOKU(A, B, C) = 1 Then
ReDim Preserve T(UBound(T) + 1)
T(UBound(T)) = C
End If
Next C
I = A
J = B
End If
End If
Next B
Next A
End Sub
Private Function IsFinished() As Boolean
IsFinished = False
Dim I As Integer
Dim J As Integer
If Not Check Then Exit Function
For I = 1 To 9
For J = 1 To 9
If SUDOKU(I, J, 0) = 0 Then Exit Function
Next J
Next I
IsFinished = True
End Function
Private Function Check() As Boolean
Dim I As Integer, J As Integer, X As Integer, Y As Integer
Dim T As Integer, Q As Integer
Dim P1(9) As Integer, P2(9) As Integer, P3(9) As Integer
Check = True
For I = 1 To 3
For X = 1 To 3
For T = 1 To 9
P1(T) = T
P2(T) = T
P3(T) = T
Next
For J = 1 To 3
For Y = 1 To 3
Q = SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, 0)
If P1(Q) > 0 Or Q = 0 Then
P1(Q) = 0
Else
Check = False
Exit Function
End If
Q = SUDOKU((J - 1) * 3 + Y, (I - 1) * 3 + X, 0)
If P2(Q) > 0 Or Q = 0 Then
P2(Q) = 0
Else
Check = False
Exit Function
End If
Q = SUDOKU((I - 1) * 3 + J, (X - 1) * 3 + Y, 0)
If P3(Q) > 0 Or Q = 0 Then
P3(Q) = 0
Else
Check = False
Exit Function
End If
Next
Next
Next
Next
End Function
Private Function CheckEmpty() As Boolean
Dim I As Integer, J As Integer
Dim P As Integer
For I = 1 To 9
For J = 1 To 9
P = P + SUDOKU(I, J, 0)
Next J
Next I
If P = 0 Then
CheckEmpty = False
Else
CheckEmpty = True
End If
End Function
Private Sub GetSUDOKU(ByRef S() As Integer)
Dim I As Integer, J As Integer, K As Integer
For I = 1 To 9
For J = 1 To 9
SUDOKU(I, J, 0) = S(I, J, 0)
For K = 1 To 9
SUDOKU(I, J, K) = 0
Next K
Next J
Next I
End Sub
Private Sub BackSUDOKU(ByRef S() As Integer)
Dim I As Integer, J As Integer, K As Integer
For I = 1 To 9
For J = 1 To 9
S(I, J, 0) = SUDOKU(I, J, 0)
For K = 1 To 9
S(I, J, K) = SUDOKU(I, J, K)
Next K
Next J
Next I
End Sub
'辅助区结束
'SUDOKU生成区
Private Sub RowTrans(ByVal SupN As Integer, ByVal SubN As Integer)
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim R As Integer
Dim S As Integer
Dim A(9) As Integer, B(9) As Integer
I = (SupN - 1) * 3
J = I
Select Case SubN
Case 1
I = I + 2
J = J + 3
Case 2
I = I + 1
J = J + 3
Case 3
I = I + 1
J = J + 2
End Select
For K = 1 To 9
A(K) = SUDOKU(I, K, 0)
B(K) = SUDOKU(J, K, 0)
Next K
K = Int(Rnd() * 5) + 1
S = SUDOKU(J, K, 0)
R = SUDOKU(I, K, 0)
A(K) = S
B(K) = R
Do While S <> R
For K = 1 To 9
If SUDOKU(I, K, 0) = S Then Exit For
Next K
S = SUDOKU(J, K, 0)
A(K) = SUDOKU(J, K, 0)
B(K) = SUDOKU(I, K, 0)
Loop
For K = 1 To 9
SUDOKU(I, K, 0) = A(K)
SUDOKU(J, K, 0) = B(K)
Next K
End Sub
Private Sub ColTrans(ByVal SupN As Integer, ByVal SubN As Integer)
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim R As Integer
Dim S As Integer
Dim A(9) As Integer, B(9) As Integer
I = (SupN - 1) * 3
J = I
Select Case SubN
Case 1
I = I + 2
J = J + 3
Case 2
I = I + 1
J = J + 3
Case 3
I = I + 1
J = J + 2
End Select
For K = 1 To 9
A(K) = SUDOKU(K, I, 0)
B(K) = SUDOKU(K, J, 0)
Next K
K = Int(Rnd() * 5) + 1
S = SUDOKU(K, J, 0)
R = SUDOKU(K, I, 0)
A(K) = S
B(K) = R
Do While S <> R
For K = 1 To 9
If SUDOKU(K, I, 0) = S Then Exit For
Next K
S = SUDOKU(K, J, 0)
A(K) = SUDOKU(K, J, 0)
B(K) = SUDOKU(K, I, 0)
Loop
For K = 1 To 9
SUDOKU(K, I, 0) = A(K)
SUDOKU(K, J, 0) = B(K)
Next K
End Sub
Private Sub Cycle()
Dim T(9) As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Randomize
Do While I < 9
J = Int(Rnd() * 9) + 1
If J = 10 Then J = 1
K = K + J
If K > 9 Then K = K - 9
Do While T(K) > 0
K = K + 1
If K = 10 Then K = 1
Loop
I = I + 1
T(K) = I
Loop
For I = 1 To 9
For J = 1 To 9
SUDOKU(I, J, 0) = T(SUDOKU(I, J, 0))
Next J
Next I
End Sub
Private Sub Cover()
Dim Total As Integer
Total = 25 + Int((Rnd() + Rnd()) / 2 * 9)
Total = 81 - Total
Dim I As Integer
Dim J As Integer
Do While Total > 0
I = Int(Rnd() * 9) + 1
If I = 10 Then I = 1
J = Int(Rnd() * 9) + 1
If J = 10 Then J = 9
If SUDOKU(I, J, 0) > 0 Then
SUDOKU(I, J, 0) = 0
Total = Total - 1
End If
Loop
End Sub
'SUDOKU生成区结束
'排除法分析区
Private Function AnalyzeRestH(ByVal Index As Integer) As Integer()
Dim I As Integer
Dim J As Integer
Dim P() As Integer
ReDim P(0)
J = 1
For I = 1 To 9
If SUDOKU(Index, I, 0) > 0 Then
ReDim Preserve P(J)
P(J) = SUDOKU(Index, I, 0)
J = J + 1
End If
Next I
AnalyzeRestH = P
End Function
Private Function AnalyzeRestV(ByVal Index As Integer) As Integer()
Dim I As Integer
Dim J As Integer
Dim P() As Integer
ReDim P(0)
J = 1
For I = 1 To 9
If SUDOKU(I, Index, 0) > 0 Then
ReDim Preserve P(J)
P(J) = SUDOKU(I, Index, 0)
J = J + 1
End If
Next I
AnalyzeRestV = P
End Function
Private Function AnalyzeRestR(ByVal Index As Integer) As Integer()
Dim I As Integer
Dim J As Integer
Dim P() As Integer
ReDim P(0)
I = Int(Index / 3)
J = Index - I * 3
If J = 0 Then J = 3: I = I - 1
I = I + 1
Dim T As Integer
T = 1
Dim X As Integer, Y As Integer
For X = 1 To 3
For Y = 1 To 3
If SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, 0) > 0 Then
ReDim Preserve P(T)
P(T) = SUDOKU((I - 1) * 3 + X, (J - 1) * 3 + Y, 0)
T = T + 1
End If
Next
Next
AnalyzeRestR = P
End Function
Private Function Union(ByRef A() As Integer, B() As Integer, C() As Integer) As Integer()
Dim I As Integer
Dim P(9) As Integer
Dim Q() As Integer
ReDim Q(0)
For I = 1 To 9
P(I) = 1
Next
For I = 1 To UBound(A)
P(A(I)) = 0
Next
For I = 1 To UBound(B)
P(B(I)) = 0
Next
For I = 1 To UBound(C)
P(C(I)) = 0
Next
Dim J As Integer
J = 1
ReDim Union(0)
For I = 1 To 9
If P(I) = 1 Then
ReDim Preserve Q(J)
Q(J) = I
J = J + 1
End If
Next
Union = Q
End Function
'排除法分析区结束
'外推法分析区
Private Function Surround(ByVal Number As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal I As Integer, ByVal J As Integer) As Boolean
Dim A As Integer, B As Integer, C As Integer, D As Integer
Dim M As Integer, N As Integer, P As Integer, Q As Integer
GetBoundary X, M, N
GetBoundary Y, P, Q
GetBoundary I, A, B
GetBoundary J, C, D
Dim Ans As Integer, Res As Integer
Dim T As Integer, R As Integer
Dim Fin As Boolean
Dim TmpA As Integer, TmpB As Integer
Dim Tmp(4) As Integer
T = X * 3 - 3 + A
Fin = False
If SUDOKU(T, Y * 3 - 2, 0) > 0 And SUDOKU(T, Y * 3 - 1, 0) > 0 And SUDOKU(T, Y * 3, 0) > 0 Then
Ans = 1
Else
For R = P * 3 - 2 To P * 3
If SUDOKU(T, R, 0) = Number Then Ans = 1: Fin = True: Exit For
Next R
If Not Fin Then
For R = Q * 3 - 2 To Q * 3
If SUDOKU(T, R, 0) = Number Then Ans = 1: Fin = True: Exit For
Next R
End If
If Fin Then Tmp(1) = 1
End If
T = X * 3 - 3 + B
Fin = False
If SUDOKU(T, Y * 3 - 2, 0) > 0 And SUDOKU(T, Y * 3 - 1, 0) > 0 And SUDOKU(T, Y * 3, 0) > 0 Then
Ans = Ans + 1
Else
For R = P * 3 - 2 To P * 3
If SUDOKU(T, R, 0) = Number Then Ans = Ans + 1: Fin = True: Exit For
Next R
If Not Fin Then
For R = Q * 3 - 2 To Q * 3
If SUDOKU(T, R, 0) = Number Then Ans = Ans + 1: Fin = True: Exit For
Next R
End If
If Fin Then Tmp(2) = 1
End If
T = Y * 3 - 3 + C
Fin = False
If SUDOKU(X * 3 - 2, T, 0) > 0 And SUDOKU(X * 3 - 1, T, 0) > 0 And SUDOKU(X * 3, T, 0) > 0 Then
Res = 1
Else
For R = M * 3 - 2 To M * 3
If SUDOKU(R, T, 0) = Number Then Res = 1: Fin = True: Exit For
Next R
If Not Fin Then
For R = N * 3 - 2 To N * 3
If SUDOKU(R, T, 0) = Number Then Res = 1: Fin = True: Exit For
Next R
End If
If Fin Then Tmp(3) = 1
End If
T = Y * 3 - 3 + D
Fin = False
If SUDOKU(X * 3 - 2, T, 0) > 0 And SUDOKU(X * 3 - 1, T, 0) > 0 And SUDOKU(X * 3, T, 0) > 0 Then
Res = Res + 1
Else
For R = M * 3 - 2 To M * 3
If SUDOKU(R, T, 0) = Number Then Res = Res + 1: Fin = True: Exit For
Next R
If Not Fin Then
For R = N * 3 - 2 To N * 3
If SUDOKU(R, T, 0) = Number Then Res = Res + 1: Fin = True: Exit For
Next R
End If
If Fin Then Tmp(4) = 1
End If
If Ans = 2 And Res = 2 Then Surround = True: Exit Function
TmpA = SUDOKU(X * 3 - 3 + I, Y * 3 - 3 + C, 0)
TmpB = SUDOKU(X * 3 - 3 + I, Y * 3 - 3 + D, 0)
If Ans = 2 And ((TmpA > 0 And TmpB > 0) Or (Tmp(4) = 1 And TmpA > 0) Or (Tmp(3) = 1 And TmpB > 0)) Then Surround = True: Exit Function
TmpA = SUDOKU(X * 3 - 3 + A, Y * 3 - 3 + J, 0)
TmpB = SUDOKU(X * 3 - 3 + B, Y * 3 - 3 + J, 0)
If Res = 2 And ((TmpA > 0 And TmpB > 0) Or (Tmp(2) = 1 And TmpA > 0) Or (Tmp(1) = 1 And TmpB > 0)) Then Surround = True: Exit Function
End Function
Private Function Environment(ByVal Number As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal I As Integer, ByVal J As Integer) As Boolean
Dim A As Integer, B As Integer, C As Integer, D As Integer
Dim M As Integer, N As Integer, P As Integer, Q As Integer
GetBoundary X, M, N
GetBoundary Y, P, Q
GetBoundary I, A, B
GetBoundary J, C, D
Dim Tmp(1) As Boolean
Dim Found As Boolean
Dim T As Integer
Dim K As Integer
Dim Tmps As Integer
Environment = False
Found = True
K = X * 3 - 3 + I
For T = 1 To 3 '当所在列出现该数的存在概率时
If SUDOKU(K, P * 3 - 3 + T, Number) = 1 Or SUDOKU(K, Q * 3 - 3 + T, Number) = 1 Then Found = False: Exit For
Next T
If Found Then
K = X * 3 - 3 + A
If SUDOKU(K, Y * 3 - 3 + J, 0) > 0 Then
Found = True
Else
For T = 1 To 3
If SUDOKU(K, P * 3 - 3 + T, Number) = 1 Then Exit For
If SUDOKU(K, Q * 3 - 3 + T, Number) = 1 Then Exit For
If SUDOKU(K, P * 3 - 3 + T, 0) = Number Then Exit For
If SUDOKU(K, Q * 3 - 3 + T, 0) = Number Then Exit For
Next T
If T < 4 Then Found = True
End If
If Found Then
Found = False
K = X * 3 - 3 + B
If SUDOKU(K, Y * 3 - 3 + J, 0) > 0 Then
Found = True
Else
For T = 1 To 3
If SUDOKU(K, P * 3 - 3 + T, Number) = 1 Then Exit For
If SUDOKU(K, Q * 3 - 3 + T, Number) = 1 Then Exit For
If SUDOKU(K, P * 3 - 3 + T, 0) = Number Then Exit For
If SUDOKU(K, Q * 3 - 3 + T, 0) = Number Then Exit For
Next T
If T < 4 Then Found = True
End If
End If
End If
If Found Then Tmp(0) = True
Found = True
K = Y * 3 - 3 + J
For T = 1 To 3 '当所在列出现该数的存在概率时
If SUDOKU(M * 3 - 3 + T, K, Number) = 1 Or SUDOKU(N * 3 - 3 + T, K, Number) = 1 Then Found = False: Exit For
Next T
If Found Then
K = Y * 3 - 3 + C
If SUDOKU(X * 3 - 3 + I, K, 0) > 0 Then
Found = True
Else
For T = 1 To 3
If SUDOKU(M * 3 - 3 + T, K, Number) = 1 Then Exit For
If SUDOKU(N * 3 - 3 + T, K, Number) = 1 Then Exit For
If SUDOKU(M * 3 - 3 + T, K, 0) = Number Then Exit For
If SUDOKU(N * 3 - 3 + T, K, 0) = Number Then Exit For
Next T
If T < 4 Then Found = True
End If
If Found Then
Found = False
K = Y * 3 - 3 + D
If SUDOKU(X * 3 - 3 + I, K, 0) > 0 Then
Found = True
Else
For T = 1 To 3
If SUDOKU(M * 3 - 3 + T, K, Number) = 1 Then Exit For
If SUDOKU(N * 3 - 3 + T, K, Number) = 1 Then Exit For
If SUDOKU(M * 3 - 3 + T, K, 0) = Number Then Exit For
If SUDOKU(N * 3 - 3 + T, K, 0) = Number Then Exit For
Next T
If T < 4 Then Found = True
End If
End If
End If
If Found Then Tmp(1) = True
If Tmp(0) And Tmp(1) Then Environment = True: Exit Function
If Tmp(0) And SUDOKU(X * 3 - 3 + I, Y * 3 - 3 + C, 0) > 0 And SUDOKU(X * 3 - 3 + I, Y * 3 - 3 + D, 0) > 0 Then Environment = True: Exit Function
If Tmp(1) And SUDOKU(X * 3 - 3 + A, Y * 3 - 3 + J, 0) > 0 And SUDOKU(X * 3 - 3 + B, Y * 3 - 3 + J, 0) > 0 Then Environment = True
End Function
Private Sub GetBoundary(ByVal Index As Integer, ByRef Down As Integer, ByRef Up As Integer)
Select Case Index
Case 1
Down = 2: Up = 3
Case 2
Down = 1: Up = 3
Case 3
Down = 1: Up = 2
End Select
End Sub
'外推法分析区结束
Private Function Deal() As Boolean
Deal = False
Dim HasNew As Boolean
HasNew = True
Dim I As Integer, J As Integer, K As Integer
Dim P1() As Integer, P2() As Integer, P3() As Integer, P4() As Integer
Dim T As Integer
Do While HasNew = True
HasNew = False
For I = 1 To 9
P1 = AnalyzeRestH(I)
For J = 1 To 9
If SUDOKU(I, J, 0) = 0 Then
P2 = AnalyzeRestV(J)
P3 = AnalyzeRestR(Int((I - 1) / 3) * 3 + Int((J - 1) / 3) + 1)
P4 = Union(P1, P2, P3)
If UBound(P4) = 1 Then
SUDOKU(I, J, 0) = P4(1)
HasNew = True
Else
For T = 1 To UBound(P4)
If Surround(P4(T), Int((I - 1) / 3 + 1), Int((J - 1) / 3 + 1), I - Int((I - 1) / 3) * 3, J - Int((J - 1) / 3) * 3) Then
SUDOKU(I, J, 0) = P4(T)
HasNew = True
Exit For
End If
Next T
End If
End If
Next
Next
If HasNew Then Deal = True
Loop
End Function
Private Function ThirdLogic() As Boolean
ThirdLogic = False
Dim HasNew As Boolean
HasNew = True
Dim I As Integer, J As Integer
Dim T As Integer, K As Integer
Dim X As Integer, Y As Integer
Dim P1() As Integer, P2() As Integer, P3() As Integer, P4() As Integer
For I = 1 To 9
P1 = AnalyzeRestH(I)
For J = 1 To 9
For T = 1 To 9
SUDOKU(I, J, T) = 0
Next T
If SUDOKU(I, J, 0) = 0 Then
P2 = AnalyzeRestV(J)
P3 = AnalyzeRestR(Int((I - 1) / 3) * 3 + Int((J - 1) / 3) + 1)
P4 = Union(P1, P2, P3)
If UBound(P4) > 1 Then
For T = 1 To UBound(P4)
SUDOKU(I, J, P4(T)) = 1
Next
End If
End If
Next J
Next I
Do While HasNew = True
HasNew = False
For I = 1 To 9
For J = 1 To 9
For T = 1 To 9
If SUDOKU(I, J, T) = 1 Then
X = Int((I - 1) / 3 + 1)
Y = Int((J - 1) / 3 + 1)
If Environment(T, X, Y, I - Int((I - 1) / 3) * 3, J - Int((J - 1) / 3) * 3) Then
SUDOKU(I, J, 0) = T
For K = 1 To 9
SUDOKU(I, K, T) = 0
SUDOKU(K, J, T) = 0
Next K
For K = 1 To 3
SUDOKU(X * 3 - 2, Y * 3 - 3 + K, T) = 0
SUDOKU(X * 3 - 1, Y * 3 - 3 + K, T) = 0
SUDOKU(X * 3, Y * 3 - 3 + K, T) = 0
Next K
HasNew = True
Exit For
End If
End If
Next T
Next J
Next I
If HasNew Then ThirdLogic = True
Loop
End Function

华为 OptiX OSN 2500

OptiX OSN 2500 智能光传输系统是继承了MSTP技术的全部特点,与传统SDH、MSTP网络保持兼容,融SDH、PDH、Ethernet、WDM、ATM、ESCON、FC/FICON、DVB-ASI(Digital Video Broadcast-Asynchronous Serial Interface)、RPR等技术为一体的新一代2.5G/622M多业务光传输平台(MSTP),主要应用在城域网络中的汇聚与接入层,为现有SDH设备向智能光网络设备过渡提供了完善的解决方案。
功能描述: 高性价比的平台化 OptiX OSN 7500/3500/2500/1500业务板件、软件完全兼容,构成统一平台。这样可以大大降低维护成本以及备板备件的成本。OSN智能平台在业务能力方面高效组合,给运营商最高性价比的解决方案;同时与华为已有的设备可以混合组网,可以纳入华为光网络网管解决方案进行统一管理。 灵活的设备配置 STM-16/4兼容设备; 支持网络设备从622M到2.5G的在线升级。 大容量调度 支持20G高低阶全交叉:高阶128×128 VC-4,低阶8064×8064 VC-12或等效的VC-3交叉能力。 多业务提供 业务接口 支持STM-1(O/E); 支持STM-4/16标准或级联业务; 支持E1/T1/E3/T3/E4;支持FE、GE业务的透传和交换; 支持ATM业务;   支持IMA业务;  支持SAN业务和视频业务; 提供基于GMPLS的快速端到端业务
特征与优势: 高度集成 子架集成度:子架尺寸为460mm(高)×440mm(宽)×295mm(深),单子架具备9个业务板位,8个接口板位。 REG功能 支持基于 OSN 2500 设计的硬件REG设备; 强组网能力 支持Mesh网络节点即插即用 支持Mesh网络在线任意速率升级扩容; 支持Mesh网络中多达40个光方向的组网; 支持链、环、相交环、相切环等多种SDH组网拓扑;   支持RPR、VP-RING环网; 单子架可实现1×STM-64四纤环或2×STM-16四纤环或4×STM-16二纤环。 内置波分技术 提供双路光分叉复用单板; 提供任意速率光波长转换单板。 完善的网络生存机制 Mesh恢复 支持分布式可恢复重路由保护; 提供5类更细化的业务保护方案,根据不同SLA提供:钻石级、金级、银级、铜级、铁级业务。 SDH保护 支持2F/4F MSP、SNCP、DNI、共享光线虚拟路径保护等。 数据业务保护 支持以太业务RPR环网保护,STP生成树保护; 支持ATM业务VP-RING环网保护。 完备的设备保护机制 智能控制单元保护:1+1热备份; 支持关键单元如交叉、时钟1+1热备份保护; 电源保护; TPS保护。
技术规格: OptiX OSN 2500 电源接入 -48V DC、通过外置UPM实现交流220V接入 安装方式 ETSI 300mm深机柜、ETSI 600mm深机柜、19英寸机柜中安装 尺寸 460mm(高)×440mm(宽)×295mm(深) 典型重量 24kg 典型功耗 206W

读代码学ahk 系列之10

1、MsgBox命令有几种格式?
MsgBox, 文本 或 MsgBox [, 类型,标题, 文本, 显示时间 ]
2、MsgBox命令按钮有几种类型?
OK—0
OK/Cancel—1
Abort/Retry/Ignore—2
Yes/No/Cancel—3
Yes/No—4
Retry/Cancel—5
Icon Hand (stop/error)—16
Icon Question—32
Icon Exclamation—48
Icon Asterisk (info)—64
Make 2nd button the default—256
Make 3rd button the default—512
System Modal (always on top) —4096
Task Modal—8192 这些参数允许相加而得到复合效果。
3、显示含有yes/no按钮并总在顶端的对话框?
msgbox,4100,标题,内容
4、MsgBox如何换行?
MsgBox,你好,欢迎关注静海安澜阁 `n 请继续关注

5、如何对MsgBox命令的选择结果进行处理?
IfMsgBox, ButtonName
ButtonName可选项: Yes No OK Cancel Abort Ignore Retry Timeout
6、对话框显示时间,并以秒为单位?
msgbox , , 标题 , 内容 , 5
7、运行外部可执行程序或者直接打开文件?
Run, 目标文件[ , 工作目录 , Max|Min|Hide|UseErrorLevel , 输出PID 变量]
8、如何运行记事本并以最大化状态显示?
Run, Notepad.exe , , Max
9、如何直接打开文件?
Run, MyFile.txt
10、命令行解释器cmd.exe 用那个宏来表示?
%ComSpec% /k在执行完命令后保留命令提示窗口,而/c则在执行完命令之后关闭提示窗口
11、命令“dir c:\Windows\system32”如何实现?
Run, %ComSpec% /k dir c:\Windows\system32
12、如何打开网页?
Run, http://hi.baidu.com/xuejinglan
13、如何打开系统属性窗口?
Run control sysdm.cpl 需要的话可以搜索所有的*.cpl文件
14、打开控制面板?
run,control
15、如何打开搜索窗口且指定搜索位置?
Run, find C:\
16、如何显示指定文件的属性窗口?
Run, properties MyFile.txt 注意:AHK 在退出前将自动关闭打开的属性窗口!
17、如何打印指定文件?
Run, print MyFile.txt
18、等待窗口出现、被激活、被关闭用那些命令?
WinWait/WinWaitActive/WinWaitClose
19、如何使目标窗口出现之前不执行后面语句?
WinWait [, 窗口标题, 窗口文本, 超时时间, 排除标题, 排除文本]
20、如何使目标窗口成为活动窗口?
WinActivate [,窗口标题, 窗口文本, 排除标题, 排除文本]
21、关闭窗口有几种方式?
正常关闭窗口(WinClose ),强行关闭窗口(WinKill):
WinClose/WinKill [ , 窗口标题, 窗口文本, 超时时间, 排除标题, 排除文本]
22、同名窗口使我们无法用窗口标题准确标识窗口,如何使用窗口ID来准确定位窗口?
使用获得窗口句柄的命令WinGet
WinGet[, 输出变量, CMD, 窗口标题, 窗口文本, 排除标题, 排除文本]
23、如何用窗口ID来替代窗口标题?
ahk_pid %ThisPID%
24、那个命令把鼠标点击事件发送到目标窗口的目标控件上?
ControlClick [, 目标控件或坐标位置, 窗口标题, 窗口文本, 鼠标按钮, 点击次数, 选项, 排除标题,排除文本]
25、ControlClick命令中,目标控件参数主要是什么?
目标控件参数是指要点击的控件的类别名(ClassNN)或控件文本,还可以使用控件句柄(若用的是控件句柄则第一个参数需留空,
并在第二个参数中使用ahk_id %控件句柄%)。
26、如何获得目标控件信息?
先打开你要进行操作的目标窗口,然后运行AutoIt3 Window Spy,把鼠标移到目标控件上
27、鼠标单击系统属性确定按钮代码是?
ControlClick, 确定, 系统属性
ControlClick, Button2, 系统属性
28、目标窗口或控件是隐藏状态,ControlClick还可以点击目标控件吗?
可以点击目标控件,但不能保证成功率。
29、如何设置控件文本?
ControlSetText [, 目标控件, 新文本, 窗口标题, 窗口文本, 排除标题, 排除文本]
例如:ControlSetText, Edit1, D:\foobar2000, Setup foobar
30、如何选中和取消单选框和复选框项目中的选择项目?
Control [, 命令, 值, 目标控件, 窗口标题, 窗口文本, 排除标题, 排除文本]
其中,“命令”就是让我们指定要进行何种设置的参数。对这些单选框/复选框按钮来说,适用的命令是“Check”和“UnCheck ”。
例如:Control, Check, , Button5, foobar
Control, UnCheck, , Button7, foobar
31、如何选择下拉列表的项目?
仍是使用Control命令,适用的命令是“Choose, N”和“ChooseString, String”,分别表示选中第N个项目和选中与字符串String
匹配的项目;例如:
Control, Choose, 5, ComboBox1, Installer
Control, ChooseString, 简体中文, ComboBox1, Installer
32、键盘如何重定义?
a::b
33、字符串如何进行自动替换?
::is::island of resistance或者
::china::
Clipboard=中华人民共和国
send,^V
Return
34、屏蔽或开启键盘、鼠标?
BlockInput 命令后,紧跟on,则屏蔽键盘鼠标操作,紧跟off,则重新启用用户输入。
如何仅仅屏蔽鼠标?如何恢复? BlockInput,MouseMove 恢复为:BlockInput, MouseMoveOff
35、如何建立一个弹出式窗口例示文本?如何关闭?
SplashTextOn [, 宽度, 高度, 标题, 文本]
`n 可以在MsgBox和SplashTextOn等命令中对显示的文本进行换行。
SplashTextOff 为关闭SplashTextOn命令建立的弹出式窗口。
36、如何将一系列指令重复执行指定次数? Loop [, Count]
{
循环体……
}
37、Loop中的count允许是表达式或者变量吗?
Count不允许是表达式,但允许是一个变量。
如何知道loop现在循环到第几次? loop 指令隐含有一个变量 A_Index ,用来记录当前状态是第几次循环
38、如何中断循环?
if a_index > 25
break ; 中断循环
39、如何跳过本次循环?
if a_index < 20
continue ; 跳过本次循环,开始一次新的循环
40、如何使使脚本等待指定时间?
Sleep,时间 单位为毫秒
41、如进行数学运算,使用什么符来把表达式运算的结果赋予某变量?
使用冒号等号符。如:NetPrice := Price * (1 - Discount/100)

42、i := i+1 的简化写法是什么?
i + =1
43、如何获取指定区间的随机数?
Random, 输出变量 [, 最小值, 最大值]
44、如何从指定文本中读取指定行?
FileReadLine, 输出变量, 文件名, 行数
45、如何判断文本超出边界?
ErrorLevel 是命令内置的一个变量,当读取文件超出边界时将被赋值为1.
46、ErrorLevel 为0和1时一般代表什么?
一般情况下,为0代表操作成功,为1,代表操作失败。
47、一般情况下,编写弹出式菜单代码的顺序是什么?
1、先定义子菜单项;2、编写菜单项;3、编写令菜单显示的代码;4、编写删除代码;5、编写响应代码。
48、如何添加子菜单?
Menu,add,子菜单项,:子菜单变量如:menu,mymenu,add,常用程序,:amenu
49、用来在弹出式菜单中显示一条分割线的代码是?
Menu, MenuName, add
50、正常菜单项的代码是?
Menu, MenuName, add,菜单项,响应标志
51、响应代码的格式是?
响应标志:
响应代码……
return
52、形如:Menu,amenu,add,txt 的代码是什么意思?
它其实是Menu,amenu,add,txt,txt 的一种简写,代表菜单项和响应标志
53、在指定坐标处显示菜单项的代码是?
Menu,MenuName,show,X坐标,Y坐标 如省略坐标,则在鼠标当前位置显示菜单项。
54、如何指定显示菜单的背景色?
Menu,MenuName,color,颜色代码
55、删除所有菜单的代码是什么?有什么作用?
Menu,mymenu,deleteall
如果没有这句代码,代码中分割线会在菜单重显时翻倍。如无分割线,可免
56、重启、关闭、注销系统的指令是什么?
Shutdown 后跟0为注销1为关机,2为重启,4为强制关闭 8为关闭关闭电源
57、隐藏脚本图标有几种方法?
Menu , tray , noicon 或者#NoTrayIcon
58、显示脚本图标的代码?
Menu , tray , icon
59、脚本图标的气泡提示如何显示?
Menu , tray , tip , 我自己的脚本
60、如何设置脚本的图标?
Menu , tray , icon , %systemroot%\system32\shell32.dll ,22或者Menu , tray , icon , e:\ico\1.ico
61、如何利用快捷键退出脚本?
#x::ExitApp
62、如何移除托盘图标的所有标准菜单项?
Menu , tray , NoStandard

63、如何插入托盘图标菜单?
Menu , tray , add , myitem
64、如何显示托盘图标的标准菜单项?
Menu , tray , standard
65、在托盘图标显示一个二级菜单代码如何表示?
menu,mymenu,add,boke
menu,mymenu,add,luntan
menu,tray,add,相关网站,:mymenu
Return 注意:响应标志后是 :不是::
66、如何使非热键类的脚本持久运行?
#Persistent
67、显示一个标准的文件选择对话框的代码为?
FileSelectFile, OutputVar [, Options, RootDir, Prompt, Filter]
Option 参数如被省略,则为单选。M 多选,M后允许随意跟随一个数字。S: 显示保存对话框。数字为一般为3,即文件及路径必须存在。Filter 参数格式如:Example: Audio (*.wav; *.mp2; *.mp3)
68、FileSelectFile命令如用户选择了多个文件,输出变量如何分割?
输出变量用(`n)字符分割。第一个参数为路径,随后紧跟选定的各个文件名。
if files =
{
MsgBox, 用户放弃选择。
}
Loop, parse, files, `n
{
if a_index = 1
mypath = %A_LoopField%
else
{
runwait, %mypath%\%A_LoopField%
}
}
return
69、运行并等待程序完成的指令是?
runwait
70、从某字符串中逐次分解出一个个的子串。
Loop, Parse , 某字符串 , 用于分割的特征变量
71、用对话框显示音量递增10%?
MsgBox, 音量递增10`%
72、使静音或者取消静音状态?
SoundSet, +1, , mute 或者Send,{Volume_Mute}
73、使主音量提升(降低)10%?
SoundSet ,+(-)10, MASTER
74、使音量中波形音量提升(降低)10%?
SoundSet , +(-)10, WAVE
75、#NoEnv 作用是什么?
主要是为了与以后兼容,也可以改善性能
76、如何对某些多媒体功能键重定义?
建个脚本内容为#InstallKeybdHook并执行,双击图标,窗口中选择菜单 view 第四项 key 开头的然后按多媒体键,f5刷新,看第二列内容比如a,显示的值是01e 。使用时就是sc01e::msgbox
77、显示器的宽度和高度用那两个常数表示?
A_ScreenWidth 和 A_ScreenHeight
78、如何移动鼠标光标?
MouseMove, X, Y [, Speed, R] Speed 参数的范围在 0 (最快) to 100 (最慢)之间取值.
R 参数 如果有此参数,则鼠标移动将以当前位置为基准,进行 x 和 y 像素的位移.
79、如何获取当前鼠标坐标?
MouseGetPos, X, Y
80、MouseGetPos还有什么作用?
MouseGetPos 指令用来返回鼠标的当前位置,以及鼠标当前悬停的窗口和控件。格式为:
MouseGetPos, [OutputVarX, OutputVarY, OutputVarWin, OutputVarControl
OutputVarWin 这个变量存储了当前鼠标悬停的窗口的ID ,即使窗口未处于激活状态。OutputVarControl 这个变量存储了当前鼠标悬停的控件的名称(ClassNN)。
81、MouseGetPos 命令在最后有1、2、3参数是什么意思?
1:在多文档界面程序(例如 SysEdit 或 TextPadThis )中可以准确的获取激活或置顶的子窗口信息。对其它情况就不那么准确了。2 :在 OutputVarControl 中存储 control's HWND/窗口句柄。3 :同时包含 1 和 2 的功能。
82、如何在屏幕上建立一个紧随鼠标的弹出式窗口?
ToolTip [, Text, X, Y]
83、如何获得当前位置像素的颜色RGB的值?
PixelGetColor, OutputVar, X, Y [, RGB]
84、如何在系统托盘建立一个弹出式窗口?
TrayTip [, Title, Text, Seconds, Options] 注意senconds的取值一般在10到30之间
85、如何用指定时间间隔自动或重复激发某子程序?
SetTimer , Label , 时间间隔
86、关闭某进程的代码是?
Process,close,autohotkey.exe
87、如何检索鼠标所在位置的信息?
MouseGetPos , , , id , control ; 得到鼠标所在位置窗口的id及控件名称
WinGetTitle, title, ahk_id %id% ;检索到相应id对应窗口的标题
WinGetClass, class, ahk_id %id% ;检索到相应id对应窗口的类名
88、如何得到当天的日期?
dd = %A_YYYY%年%A_MM%月%A_DD%日
89、如何给剪贴板赋值?
clipboard = %var%
90、当前桌面那个常数表示?
%A_Desktop%
91、如何设置鼠标速度?
SetDefaultMouseSpeed 30; 默认的是2 ,可以从0调到100,越小越快
92、如何设置鼠标动作结束之后的延迟?
SetMouseDelay 30; 默认是10毫秒
93、如何实现ctrl+鼠标双击?
send ^{click 100,200 2}
94、使滚轮向上滚2次?
click wheelup 2 ; wheelup 可以写成WU
95、滚轮向下滚一次?
click wheeldown ;wheeldown 可以简化为WD
96、使鼠标滚轮向下滚5次有几种方法?
Click , WD,5或
loop 5
click WD
97、当前位置鼠标单击左键
click ;
right 右键,left左键(默认可省略),middle 中键
98、当前位置鼠标双击左键?
click 2
99、移动鼠标到30,40?
click 30 , 40 , 0
100、点击鼠标右键的代码如何编写?
Click , 100 , 200 , right
101、如果鼠标点击的坐标是动态的如何表达?
Click %x% %y%
102、拖动某图标?
click 30,40 down
click 50,60 up
103、如何设置一个进度条?
Progress , %i% , 进度条下文本 , 进度条上文本 , 标题
104、如何创建快捷方式?
FileCreateShortcut, 目标文件, 快捷方式名 [, 工作目录, 用空格分开的参数, 描述, 图标, 快捷键, 图标标号, 运行状态]
注意:只需指定单个按键,所有的快捷键被指定为 CTRL+ALT + 快捷键,如果给该参数指定 B,将会产生一个 CTRL-ALT-B 的快捷键。运行状态1 - 正常(默认)3 - 最大化7 - 最小化
105、空格键
{space}
106、向左的箭头
{Left}
107、ctrl键?
^
108、alt键?
!
109、回车?
{enter}
110、小键盘的1?
Numpad1
111、Windows键?
#
112、Shift键?
+
113、逻辑与,把多个按键或鼠标组合成一个自定义键?
&
114、一对按键中的左边的按键?
< 如115、一对按键中的右边的按键?
>
116、通配符,表示热键被按下时,即使同时还有其他的按键按下,依然有效?
*
117、热键被触发后,动作不会被阻塞?
~
118、禁用某键?
在::后紧跟return即可。如:RWin::return
119、按键重映射?
a::b 如:RAlt::Rbutton 右alt映射为鼠标右键Lbutton::return 鼠标左键被屏蔽
120、仅在notepad中交换a、b键?
#IfWinActive ahk_class Notepad
a::b ;
#IfWinActive ;
121、鼠标定义?
LButton RButton MButton WheelDown WheelUp
122、键盘定义?
Space Tab Enter (or Return) Escape (or Esc) Backspace (or BS) Delete (or Del) Insert (or Ins) Home End PgUp PgDn Up Down Left Right ScrollLock CapsLock NumLock Numlock ON Numlock OFF Numpad0 NumpadPgUp NumpadDot (.) NumpadDel NumpadDiv (/) NumpadDiv (/) NumpadMult (*) NumpadMult (*) NumpadAdd (+) NumpadAdd (+) NumpadSub (-) NumpadSub (-) NumpadEnter NumpadEnter 1 a A LWin Control (or Ctrl) Alt Shift F1 PrintScreen CtrlBreak Pause Break
123、注释
;跟在需注释的语句之后,注意语句和分号之间至少要有一个空格。如果要注释多个语句可以使用/* */
124、函数?
Add(x, y)
{
return x + y ; "Return" expects an expression.
}
函数调用时,变量的后面使用 := 例如:Var := Add(2, 3) ;
由于一个函数调用就是一个表达式,所以函数的参数列表里面的变量前面不能加百分号“%”,相反的,字符串要使用引号。当一个命令的参数调用函数的时候,如果命令的参数不支持表达式,就必须使用百分号“%”,如:
MsgBox % "The answer is: " Add(3, 2)
125、如果要想在热字符串替换后加上空格?
在语句的后边加上 `,:*:btw::By the way `
126、弹出光驱
Drive, Eject,, 0
127、收回光驱
Drive, Eject,, 1
128、使窗口透明,值在1-255之间?
WinSet, Transparent, 100,我的电脑
129、创建或更新启动界面?
SplashImage,d:\1.jpg,b fs18
Sleep,5000
b fs 18 可以去除界面边框。原因不明
130、修改脚本之后,按住左键后按R重新载入脚本
~LButton & r::
reload
return
131、打开/激活记事本
IfWinExist 无标题 - 记事本
{
WinActivate
}
Else
{
Run Notepad
WinWait 无标题 - 记事本
WinActivate
}
132、隐藏任务栏 WinHide ahk_class Shell_TrayWnd
显示任务栏 WinShow ahk_class Shell_TrayWnd
133、如何强制单线程?
#SingleInstance force
134、屏蔽Ctrl+Alt+Del?
Regwrite,REG_SZ,HKEY_LOCAL_MACHINE,SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskmgr.exe, Debugger, Hotkey Disabled
解除屏蔽 RegDelete,HKLM,SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\taskmgr.exe

135、双击启动A程序.再双击,自动关闭A程序.
ifexist, 程序窗口标题
winkill, 程序窗口标题
else
run, 程序文件路径
return
136、当前窗口始终置于顶层?
WinSet AlwaysOnTop, on, A
137、关闭当前窗口置于顶层状态?
WinSet AlwaysOnTop, off, A
138、窗口还可以用表示?
ahk_class class、ahk_pid %PID%、ahk_id %ID%
139、音乐播放或暂停?
Send , {Media_Play_Pause}
140、音乐播放停止?
Send , {Media_Stop}
141、播放上一首?
Send , {Media_Prev}
142、播放下一首?
Send , {Media_Next}
143、按下浏览器回退键?
Send , {BROWSER_BACK}
144、按下浏览器 向前键?
Send , {BROWSER_FORWARD}
145、按下浏览器刷新键?
Send , {BROWSER_REFRESH}
146、按下浏览器停止键?
Send , {BROWSER_STOP}
147、按下浏览器搜索键?
Send , {BROWSER_SEARCH}
148、按下浏览器收藏键?
Send , {BROWSER_FAVORITES}
149、按下浏览器主页键?
Send , {BROWSER_HOME}
150、使静音?
Send , {VOLUME_MUTE}

推荐一款极其强大的软件 - AutoHotkey

AutoHotkey 这是一个很神奇的工具。是的,只能用神奇来形容。他的功能类似于按键精灵,可以帮助你完成一系列的动作。或许你已经用过按键精灵,但是在此之前你不会想到 AHK是多么的强大。你可以让他帮助你迅速打开常去的几个网站并且登陆邮箱,或者迅速的运行那些藏的很深的程序,你可以用他来做网游的挂机程序,也可以来做格斗游戏中连续技的脚本。只有你有足够的想象力,没有什么是AHK做不到的。与之类似的还有一个AtuoIt3,不过他的代码看起来要郁闷一些,相比之下我还是更喜欢AHK。
如你所见,AHK的所有工作都是通过你所写的脚本来完成的。而这个脚本实际上就是一个普通的文本文件,AHK按照你所写的顺序一行一行的执行下去。写代码确实令人有些头痛,所以很多人对这个软件都望而却步。但是假如你愿意深入的研究一下,就会发现他的代码实际上非常简单易学。与之相对的是,软件自带了非常强大的帮助文件,可惜是英文的。所以我就写了这样一篇文章,希望可以让大家对AHK产生兴趣^_^

首先是转自__ Scripting Life __的官方文档翻译
介绍
AutoHotkey 是一款免费的、Windows平台下开放源代码的热键脚本语言。有了它,您就可以:

通过发送键盘或鼠标的键击动作命令来实现几乎所有操作的自动化。您可以自己编写 宏 或者使用宏录制器来生成;
为键盘,游戏操纵杆和鼠标创建 热键。 事实上任何的按键、按钮或组合键都可以被设置为热键;
当键入您自定义的缩写时可以 扩展缩写。例如, 键入“btw”就可以自动扩展为“by the way”;
创建自定义的数据输入表格、用户界面、菜单等。详情请看 图形界面 部分;
映射 键盘、游戏操纵杆和鼠标上的按键或按钮;
运行现有的AutoIt v2脚本 并用 新功能 来增强它们;
将脚本文件 编译 成EXE可执行文件,使得程序在没有安装AutoHotkey的机器上得以运行;
借助 相关工具 以实现更强大的功能。
更多关于热键的说明
AutoHotkey 可令键盘、游戏操纵杆和鼠标的所有潜能都发挥出来。例如,除了典型的Control、Alt和Shift键之外,你还可以定义Win键(徽标键)和 Capslock键作为调节键。 而实际上你还可以设置任意的键盘按键或鼠标按键作为调节键。详细内容请看 高级热键 部分。
其他功能

调节音量、设置静音,以及其他 关于声卡的设置;
令指定窗口变为 透明,顶层窗口,或改变 外形;
用 游戏操纵杆 或 键盘 代替鼠标;
监控 您的系统。例如,当您不希望见到的窗口出现时自动关闭它们;
获取并改变 剪贴板的内容, 包括从资源管理器中复制的文件的名称;
关闭或屏蔽 Windows自有的快捷键,例如Win+E和Win+R;
取替Alt-Tab (通过按键、鼠标滚轮或按钮)从而减轻RSI(肢体重复性劳损 );
使用您喜欢的图标、工具提示(ToolTip)、菜单项目和子菜单来自定义 托盘图标菜单 ;
显示 对话框、工具提示(Tooltips)、气球提示 以及 弹出菜单,与用户交互;
执行脚本动作来 响应 系统关闭或注销;
检测系统 空闲时间。例如, 在系统空闲的时候执行高CPU负荷的任务;
通过检测 图像 和 象素色彩来自动执行游戏中的动作;
读取、写入 以及 解释 文本文件比起其他语言更容易;
针对一组与 通配符 匹配的文件进行操作;
可对 注册表 和 INI文件 进行操作。


搞定以后就可以开始写脚本了。任何地方点击右键-新建,选择AutoHotkeyScript(AHK脚本),当然你也可以直接在文本编辑器里写好以后另存为.ahk文件。AutoHotkey会在关联后执行这些.ahk的文件,当然你也可以转换成exe的可执行文件(附带有此工具)。


这里开始,是我的一个示例脚本。平时我需要经常运行很多软件,很麻烦,所以就写了这样一个程序。
首先,我喜欢在上网的同时听歌,平时比较喜欢用foobar2000,所以打算在按下Win+1键时开始用它听歌;
其次,玩游戏的时候经常配合gapa这个颜色优化工具,他的效果非常好,不过每次都要按F4更改配色方案,现在我希望按一下Win+2就可以自动帮我完成;
然后,上网时候经常有需要记住的东西,所以我希望在按Win+3之后他可以把我当前复制的东西保存下来,也就是粘贴到记事本里去;
最后,这个程序可以方便的退出。
知道了要求之后,我们就来看看写出的脚本吧:

Copy code
;这里是我的一个示例脚本
#InstallKeybdHook ;安装键盘钩子,不过其实这里可以不装
msgbox, 这是我的常用软件运行脚本 `n按Win+1运行Foobar2000,并且开始播放 `n按Win+2运行gapa色彩优化工具,并且设置配色方案 `n按Win+3运行将当前复制的内容粘贴入记事本 `n按Win+X退出 ;只是一个弹出的对话框,`n是换行

#1:: ;按下Win+1键
Run, D:foobar2000foobar2000.exe, D:foobar2000 ;运行我的Foobar2000,为了防止出现意外把他设置为所在目录启动,以下同
sleep, 500 ;还是稍微等一下吧,等程序运行
send, !p ;按Alt+P,开始播放的快捷键
return ;返回

#2:: ;这是Win+2
Run, %userprofile%Desktop色彩优化工具gapa.exe, %userprofile%Desktop色彩优化工具 ;执行gapa,在桌面上
sleep, 500 ;再等待一下
send {F4} ;按下F4修改配色方案
return ;返回

#3:: ;这是Win+3
IfWinExist, Untitled - Notepad ;检测窗口是否存在,注意我的英文版xp记事本标题为Untitled - Notepad,如果你是中文版的话,应该为 未命名 - 记事本,下同
{
WinActivate ;如果存在就激活他
}
else ;否则
{
Run, Notepad ;运行notepad
WinWait, Untitled - Notepad ;等一下
WinActivate ;然后激活窗口
}
sleep, 500 ;继续等一下
send, {enter}{enter}^v ;加入两个回车(空行),然后按ctrl+v粘贴
return ;返回

#x:: ;这是Win+X
MsgBox, 4,, 你确定要退出吗 ;弹对话框,4,,是加入了Yes/No的选择
IfMsgBox Yes ;如果点了是
ExitApp ;退出当前脚本
else ;否则
MsgBox 程序还在运行中 ;弹出对话框
return ;返回


;号后面都是我的注释,每一行都做了注释,应该还能看懂吧^_^。他整体代码的感觉比较类似于JS,不是很难。更详细的说明都可以在帮助文件中找到。
另外,gapa这个程序我在每次退出时,都要按F6键返回默认配色,否则桌面时比较难受。所以可以继续做出如下修改:


#4:: ;按Win+4
send {F6} ;按下F6恢复默认配色
process, close, gapa.exe ;结束进程gapa.exe

星期二, 五月 12, 2009

姚明、李开复:30幅画 读懂灾区孩子的内心

孩子们总在用各种方式让我们惊讶与感动,尤其是在一年后,当我们重新面对5•12这个沉重的日子时,更是如此。
大地震后,上海的美术老师张贵和奔赴灾区支教。期间,他和其他老师组织孩子们用画笔来表达内心,用色彩和线条记录情感。于是,就有了现在大家看到的这 30 幅稚嫩却充满真情的画作

姚基金与谷歌中国的很多同事们,都看到了这些作品,并无一例外地被深深触动。是的,只有灾区的孩子们,才会画出如此“雷同”的题材——所有的画作都与地震、与灾难相关。而且,这些画作中经常出现的冷峻色彩、沉甸甸的笔触、呼之欲出的思念,恐怕也绝少在普通孩子的绘画作品中出现。

在其中的一幅画作里,辛勤的鸟妈妈为巢里的鸟儿带回食物,大树下,想念妈妈的孩子淌着泪水仰望树梢,画面里写满了“妈妈”、“妈妈”的字样……



真的只有沉重与悲伤吗?我们被这群童真的孩子引领着,还看到了感恩、希望、笑容,甚至与年龄不符的坚强。

在5•12一周年祭的时候,在全国各界纷纷用各自的方式缅怀逝者的时刻,我们很想通过自己的微薄努力,让更多的人看到这些画,去传递这份感动,去体会灾区孩子的内心。那些幼小的心灵,有阴霾需要去驱散,有伤口需要去抚平,却总是美丽真诚。

从今天起,在最为便捷的网络平台上,谷歌会把孩子们的画作直接展现在网友面前,并同时展开“让音乐传递你我祝福”的5•12专题纪念活动,请网友们为这些画作配上声音,用歌曲为孩子们提供祝福与安慰。姚基金则会把网友们挑选出的歌曲收录在音乐播放器中,转交给那些可爱的小作者们。

我们相信,当孩子们的画作和无数网友的祝福在网络上传播的时候,网络真正联结的应该是每一个人的心灵。作为大人,我们会记住我们的责任,我们会记住5•12的举国同悲,我们不会忘记那些逝去的同胞,我们不会忘记帮助灾区的孩子们坚强长大。5•12一周年祭的时候,我们愈发确认:泱泱中华,总能共渡时艰。

走进孩子们的心灵 了解画作详情:g.cn/music/512

姚明送给孩子们的画: