欢迎使用右键搜。这是一个使用 Autoit v3 编写的右键菜单增强小插件,用于在资源管理器文件右键菜单中增加一键搜索,让您快速调用在线搜索引擎查找与此文件相关的信息。
在整理文件时,经常需要上网搜一下某个文件的背景资料、相关信息。虽然"复制---打开浏览器---输入网址---粘贴---点击搜索"这一系列操作确实不难,但每天重复几十次,难免觉得过于繁琐。
文件在线搜索助手正是为了解决这个麻烦应运而生的。
安装后,在资源管理器文件右键菜单中就会出现 "使用 Web 搜索"命令,点击后选择搜索方式即可通过您选择的搜索引擎搜索此文件,也可在弹出右键菜单后直接按字母 W 快捷激活搜索。
本程序还支持自定义搜索引擎,可打开程序同目录下的 "SearchEngines.ini" 文件按示例格式增加/修改搜索引擎。
下载地址:
自定义搜索引擎配置示例
配置存放在程序同目录的 SearchEngines.ini文件,使用 ansi 编码, $kwd 表示搜索词,也就是文件名。
name 是显示在界面上的菜单文字, url 是搜索引擎网址。
ini
[Baidu]
name=百度搜索 "$kwd" (&B)
url=https://baidu.com/s?wd=$kwd&tn=baidurt&rn=50&pn=0&ie=utf-8
[Bing]
name=必应搜索 "$kwd" (&I)
url=https://cn.bing.com/search?q=$kwd
[Toutiao]
name=头条搜索 "$kwd" (&T)
url=https://so.toutiao.com/search?keyword=$kwd
[Sogou]
name=搜狗搜索 "$kwd" (&S)
url=https://sogou.com/web?query=$kwd&ie=utf8
[Weixin]
name=微信搜索 "$kwd" (&w)
url=https://weixin.sogou.com/weixin?query=$kwd&type=2
打包脚本
本程序使用 InnoSetup v6.7 制作安装包。
innoscript
#define MyAppName "右键搜"
#define MyAppVersion "1.0.0.0"
#define MyAppPublisher "cingzeoi.github.io"
#define MyAppURL "https://cingzeoi.github.io/"
#define MyAppExeName "WebSearch.exe"
[Setup]
; 注意:AppId 的值唯一标识此应用程序。切勿在其他应用程序的安装程序中使用相同的 AppId 值。
; (若要生成新的 GUID,请在 InnoSetup IDE 中单击 "工具 -> 生成 GUID"。)
AppId={{CF495A39-E6A3-459E-A005-16C0DD8BBFA1}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
VersionInfoVersion={#MyAppVersion}
VersionInfoProductVersion={#MyAppVersion}
VersionInfoCopyright=Copyright © {#MyAppPublisher}
VersionInfoDescription="{#MyAppName}" 安装程序
AppVerName={#MyAppName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\youjiansou
UninstallDisplayName={#MyAppName} ({#MyAppVersion})
UninstallDisplayIcon={app}\{#MyAppExeName}
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
InfoBeforeFile=D:\Inno\WebSearch\readme.txt
;PrivilegesRequired=lowest
OutputDir=youjiansou
OutputBaseFilename=Setup
SolidCompression=yes
WizardStyle=modern
CloseApplications=yes
DisableWelcomePage=no
[Languages]
Name: "chinesesimp"; MessagesFile: "compiler:Default.isl"
[Files]
Source: "D:\Inno\WebSearch\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion
Source: "D:\Inno\WebSearch\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "D:\Inno\WebSearch\welcome.wav"; Flags: dontcopy
[Registry]
Root: HKCR; Subkey: "*\shell\WebSearch"; ValueType: string; ValueData: "使用 Web 搜索 (&W)"; Flags: uninsdeletekey
; 动态写入程序路径:{app} 会自动替换为用户实际安装的路径
Root: HKCR; Subkey: "*\shell\WebSearch\Command"; ValueType: string; ValueData: """{app}\{#MyAppExeName}"" ""%1"""; Flags: uninsdeletekey
[Messages]
chinesesimp.WelcomeLabel1=欢迎使用"{#MyAppName}"安装程序!
chinesesimp.WelcomeLabel2=本向导将在您的电脑上安装:【{#MyAppName} ({#MyAppVersion}版)】。%n在继续之前,强烈建议您先关闭所有其他应用程序。
[Code]
// 实现安装程序启动后自动播放音频
// 导入 Windows 播放多媒体的 API
function mciSendString(lpstrCommand, lpstrReturnString: String; uReturnLength, hWndCallback: Integer): Integer;
external 'mciSendStringW@winmm.dll stdcall';
// "InitializeSetup" 是安装程序启动时最早触发的事件
function InitializeSetup(): Boolean;
var
WavePath: String;
begin
Result := True;
try
// 将音频文件解压到临时目录 {tmp}
ExtractTemporaryFile('welcome.wav');
WavePath := ExpandConstant('{tmp}\welcome.wav');
// 调用 MCI 指令播放
// 'open' 打开文件并取别名为 'welcome_sound'
mciSendString('open "' + WavePath + '" alias welcome_sound', '', 0, 0);
// 'play' 后不加 'repeat',音频播放完会自动停止
mciSendString('play welcome_sound', '', 0, 0);
except
// 如果播放失败(比如用户没声卡),静默处理,不影响安装
end;
end;
// 安装程序被关闭时,清理资源
procedure DeinitializeSetup();
begin
mciSendString('stop welcome_sound', '', 0, 0);
mciSendString('close welcome_sound', '', 0, 0);
end;
主程序代码
本程序使用 au3 编写。
au3
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ScrollBarsConstants.au3>
#include <GUIScrollBars.au3>
#NoTrayIcon
; 获取并解析启动参数
If $CmdLine[0] = 0 Then Exit
; $CmdLine[1] 获取第一个参数
Local $sRawFileName = StringRegExpReplace($CmdLine[1], "^.*\\", "")
If $sRawFileName = "" Then Exit
Local $sKwd = _URIEncode($sRawFileName)
; 读取搜索引擎配置
Local $sIniPath = @ScriptDir & "\SearchEngines.ini"
If Not FileExists($sIniPath) Then
MsgBox(48, "错误", "找不到配置文件: " & $sIniPath)
Exit
EndIf
; IniReadSectionNames 返回的数组,$aSections[0] 是数量
Local $aSections = IniReadSectionNames($sIniPath)
If @error Then
MsgBox(48, "错误", "配置文件格式不正确!")
Exit
EndIf
; 计算规划界面布局
Local $iBtnHeight = 40
Local $iBtnMargin = 10
Local $iWinWidth = 320
Local $iMaxWinHeight = 400 ; 窗口最大高度限制
Local $iCount = $aSections[0]
Local $iContentHeight = $iCount * ($iBtnHeight + $iBtnMargin) + $iBtnMargin
Local $iDisplayHeight = ($iContentHeight > $iMaxWinHeight) ? $iMaxWinHeight : $iContentHeight
; 创建窗口并设置标题 "Web 搜索 [文件名]"
Local $hMain = GUICreate("Web 搜索 [" & $sRawFileName & "]", $iWinWidth, $iDisplayHeight, -1, -1, BitOR($WS_CAPTION, $WS_SYSMENU))
; 根据搜索引擎的配置动态创建按钮
Local $aBtnID[$iCount + 1] ; 存储按钮控件ID
Local $aBtnURL[$iCount + 1] ; 存储对应的URL
For $i = 1 To $iCount
Local $sSectionName = $aSections[$i]
Local $sBtnText = IniRead($sIniPath, $sSectionName, "name", "Search")
Local $sTargetUrl = IniRead($sIniPath, $sSectionName, "url", "")
; 执行 "$kwd" 宏变量替换
$sBtnText = StringReplace($sBtnText, "$kwd", $sRawFileName)
Local $sFinalUrl = StringReplace($sTargetUrl, "$kwd", $sKwd)
; 创建按钮
$aBtnID[$i] = GUICtrlCreateButton($sBtnText, 10, $iBtnMargin + ($i-1) * ($iBtnHeight + $iBtnMargin), $iWinWidth - 40, $iBtnHeight)
$aBtnURL[$i] = $sFinalUrl
Next
; 处理滚动条
If $iContentHeight > $iMaxWinHeight Then
_GUIScrollBars_Init($hMain)
_GUIScrollBars_ShowScrollBar($hMain, $SB_VERT, True)
_GUIScrollBars_SetScrollRange($hMain, $SB_VERT, 0, $iContentHeight)
EndIf
GUISetState(@SW_SHOW)
; 消息循环
While true
Local $nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case 1 To 9999
For $j = 1 To $iCount
If $nMsg = $aBtnID[$j] Then
ShellExecute($aBtnURL[$j])
Exit
EndIf
Next
EndSwitch
WEnd
; URL 编码函数(编码为utf8)
Func _URIEncode($sText)
Local $bUTF8 = StringToBinary($sText, 4)
Local $sHex = StringTrimLeft(String($bUTF8), 2)
Local $sEncoded = ""
For $i = 1 To StringLen($sHex) Step 2
Local $sByte = StringMid($sHex, $i, 2)
Local $iDec = Dec($sByte)
If ($iDec >= 48 And $iDec <= 57) Or ($iDec >= 65 And $iDec <= 90) Or ($iDec >= 97 And $iDec <= 122) Then
$sResult = Chr($iDec)
$sEncoded &= $sResult
Else
$sEncoded &= "%" & $sByte
EndIf
Next
Return $sEncoded
EndFunc