利用外部函数
本工具作者是VimDesktop群的Array,在脚本中调用quricol32.dll中的函数生成二维码。 这里单独列出代码供参考:
Code: Select all
#SingleInstance, Force
#NoTrayIcon
SetBatchLines, -1
GUI,GQR:Add,Edit,x10 y10 w500 h400 Limit850
GUI,GQR:Add,Button,x10 y420 w90 h30 gClip,打开剪切板(&V)
GUI,GQR:Add,Button,x320 y420 w90 h30 gSTART,生成二维码(&G)
GUI,GQR:Add,Button,x420 y420 w90 h30 gGQRGUIClose,关闭(&C)
GUI,GQR:Show,w520 h460,GenQR
Return
GQRGUIEscape:
GQRGUIClose:
ExitApp
return
Clip:
GUI,GQR:Default
GUIControl,,Edit1,% Substr(Clipboard,1,850)
return
START:
GUI,GQR: Default
GUIControlGet,Test,,Edit1
GUI,pic:Destroy
GUI,pic:Add,Pic,x20 y20 w500 h-1 hwndhimage,% f:=GEN_QR_CODE(Test)
GUI,pic:Add,Text,x20 y542 h24,按Esc取消
GUI,pic:Add,Button,x420 y540 w100 h24 gSaveAs,另存为(&S)
GUI,pic:Show,w540 h580
return
PICGUIEscape:
GUI,pic:Destroy
return
SaveAs:
Fileselectfile,nf,s16,,另存为,PNG图片(*.png)
If not strlen(nf)
return
nf := RegExMatch(nf,"i)\.png") ? nf : nf ".png"
Filecopy,%f%,%nf%,1
return
GEN_QR_CODE(string,file="")
{
sFile := strlen(file) ? file : A_Temp "\" A_NowUTC ".png"
DllCall( A_ScriptDir "\quricol32.dll\GeneratePNG","str", sFile , "str", string, "int", 4, "int", 2, "int", 0)
Return sFile
}
纯AHK实现
从实用性考虑,上面的工具基本足够了,不过从学习或兴趣角度看,完全用AHK实现也是个美妙的想法,重要的是有人实现了:
- BARCODER.ahk库(作者Gio),把文本编码成一维(用于CODE39/CODE ITF)和二维数组(用于QR CODE)的库函数;
- GDIP.ahk库(作者Tic),生成二维码图像;
已知问题(来自原贴的介绍和一些用户的介绍):
- 尚不支持中、日、韩文字;
- 生成速度较慢;