如上图。
如下代码。
GUICtrlRichEdit如何像Word一样设置两端对齐或分散对齐?右边空白多并且参差不齐,如果两边对齐的话可能好些。
以及如何预先设置字体、字大小、颜色、行间距呢?
_GUICtrlRichEdit_SetCharColor以及_GUICtrlRichEdit_SetFont好像只能后发设置,可以看到闪烁而过的切换变化
#include <GUIConstantsEx.au3>
#include <GuiRichEdit.au3>
#include <WindowsConstants.au3>
Local $Str = _
' 叁十功名何所求,' & @CRLF & _
' 恨萍聚散谁人偶;' & @CRLF & _
' 居仙笑谓人生戏,' & @CRLF & _
' 士人但求仙鹤楼。' & @CRLF & _
' ----------------------------------------------------------------------------------------' & @CRLF & _
' 说明:' & @CRLF & _
' 该说的“提问智慧”里边已经说了,这里不重复了。不要拿“新手”作借口。。。。。。。。 太多的重复提问贴提问,只会让人看而生厌,并且有浪费时间的嫌疑,这里重复一句,学会搜索论坛。提问区“已解决”版块里的问题都是解决了的,建议新手多翻下,多看下。这里发些常见的问题解答。' & @CRLF & _
' 声明:' & @CRLF & _
' 此贴只发www.autoitx.com,其他的都是转贴。转贴请注明出处,多谢合作。' & @CRLF & _
' 常见问题:' & @CRLF & _
' Q1 如何调试脚本?' & @CRLF & _
' MsgBox(0,"测试",$var)' & @CRLF & _
' ConsoleWrite("var=" & $var & @CRLF)' & @CRLF & _
' Q2 操作CMD相关命令' & @CRLF & _
' Q2.1 如何运行DOS命令?' & @CRLF & _
' Run(@ComSpec & ' & "'" & ' /c dir>d:\dir.txt' & "'" & ',"", @SW_HIDE)' & @CRLF & _
' #include <Process.au3>' & @CRLF & _
' $rc = _RunDos("start Http://www.autoitx.com")' & @CRLF & _
' Q2.2 运行DOS命令如何连接AU3变量?' & @CRLF & _
' Local $var="d:\dir.txt"' & @CRLF & _
' Run(@ComSpec & ' & "'" & ' /c dir>"' & "'" & '&$var&' & "'" & '"' & "'" & ',"", @SW_HIDE)' & @CRLF & _
' Q2.3 运行DOS命令如何自动应答?(注意:这并不属于AU3的问题,这里附带说一下。)' & @CRLF & _
' RunWait(@ComSpec & ' & "'" & ' /c echo y|cacls %systemroot%\system32\wpcap.dll /d everyone' & "'" & ', @SystemDir, @SW_HIDE)' & @CRLF & _
' Q2.4 多层DOS命令如何用?如netsh,diskpart等。' & @CRLF & _
' $dns="192.168.0.1"' & @CRLF & _
' RunWait(@ComSpec & ' & "'" & ' /C netsh -c interface ip set dns 本地连接 source=static addr="' & "'" & ' & $dns &' & "'" & '" register=PRIMARY ' & "'" & ',"", @SW_HIDE )' & @CRLF & _
' Q2.5 运行DOS命令如何直接截取回显?' & @CRLF & _
' ;注意:回显截取只支持Run而不是RunWait' & @CRLF & _
' #include <Constants.au3>' & @CRLF & _
' Opt("MustDeclareVars",1)' & @CRLF & _
' _test()' & @CRLF & _
' Func _test()' & @CRLF & _
' Local $foo,$line,$lines' & @CRLF & _
' $foo = Run(@ComSpec & " /c sc query Alerter", @SystemDir, @SW_HIDE, $STDOUT_CHILD)' & @CRLF & _
' $lines = ""' & @CRLF & _
' While 1' & @CRLF & _
' $line = StdoutRead($foo)' & @CRLF & _
' If @error Then ExitLoop' & @CRLF & _
' $lines &= $line' & @CRLF & _
' Wend' & @CRLF & _
' MsgBox(0,"test",$lines)' & @CRLF & _
' EndFunc' & @CRLF & _
' Q3 如何防止程序重复运行?' & @CRLF & _
' $g_szVersion = "test"' & @CRLF & _
' If WinExists($g_szVersion) Then Exit' & @CRLF & _
' AutoItWinSetTitle($g_szVersion)' & @CRLF & _
' #include <Misc.au3>' & @CRLF & _
' _Singleton("test")' & @CRLF & _
' Q4 如何直接运行系统程序关联的文件?如[.txt, .msi, .pdf, .jpg, .lnk, .msc]等等!!!' & @CRLF & _
' ShellExecute("Notepad.exe")' & @CRLF & _
' ShellExecute("test.txt", "", @ScriptDir, "edit")' & @CRLF & _
' ShellExecute("http://www.autoitx.com")' & @CRLF & _
' ShellExecute("C:\boot.ini", "", "", "print")' & @CRLF & _
' ShellExecute("test.lnk","",@ScriptDir)' & @CRLF & _
' ShellExecute("gpedit.msc", "", "", "open", @SW_MAXIMIZE)' & @CRLF & _
' Q5 如何控制系统服务?' & @CRLF & _
' API的控制服务' & @CRLF & _
' _StartService() 开始服务' & @CRLF & _
' _StopService() 停止服务' & @CRLF & _
' _ServiceExists() 检测服务' & @CRLF & _
' _ServiceRunning() 运行服务' & @CRLF & _
' _CreateService() 建立服务' & @CRLF & _
' _DeleteService() 删除服务' & @CRLF & _
' WMI的控制服务' & @CRLF & _
' _ServStart() 开始服务' & @CRLF & _
' _ServStop() 停止服务' & @CRLF & _
' _ServDelete() 删除服务' & @CRLF & _
' _ServGetDetails() 服务详情' & @CRLF & _
' _ServGetState() 服务状态' & @CRLF & _
' _ServListInstalled() 服务列表' & @CRLF & _
' _ServPause() 暂停服务' & @CRLF & _
' _ServResume() 服务改名' & @CRLF & _
' _SerSetState() 设置服务状态' & @CRLF & _
' http://www.autoitx.com/forum.php?mod=viewthread&tid=176 链接已修正 -- afan' & @CRLF & _
' Q6 如何操作注册表?' & @CRLF & _
' Q6.1 常用的注册表设置' & @CRLF & _
' ;读取注册表指定的值' & @CRLF & _
' $var = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProgramFilesDir")' & @CRLF & _
' MsgBox(4096, "Program files 文件夹位于:", $var)' & @CRLF & _
' ;创建一个主键、子键或值项。' & @CRLF & _
' RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\Test", "TestKey", "REG_SZ", "Hello this is a test")' & @CRLF & _
' ;删除注册表指定的值 (注意:这里删除的是键项,而不是键值。)' & @CRLF & _
' RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE", "TestKey")' & @CRLF & _
' ;其他还有RegEnumKey(),RegEnumVal(),详细应用请参考帮助。' & @CRLF & _
' Q6.2 注册表权限设置' & @CRLF & _
' http://www.autoitx.com/forum.php?mod=viewthread&tid=1099 链接已修正 -- afan' & @CRLF & _
' Q7 如何不重启刷新注册表马上生效?' & @CRLF & _
' Do' & @CRLF & _
' ProcessClose("explorer.exe")' & @CRLF & _
' Until Not ProcessExists("explorer.exe")' & @CRLF & _
' Run("gpupdate /force","",@SW_HIDE)' & @CRLF & _
' ;强烈推存应用这个' & @CRLF & _
' DllCall("user32.dll","int","SendMessageTimeout","hwnd",65535,"int",26,"int",0,"int",0,"int",0,"int",1000,"str","dwResult")' & @CRLF & _
' Q8 AU3编写的程序如何带参数运行?' & @CRLF & _
' If $cmdline[0] <> 0 Then' & @CRLF & _
' $filename = $cmdline[1]' & @CRLF & _
' MsgBox(4096, "测试", ' & "'" & '你输入的命令行参数是 "' & "'" & ' & $filename & ' & "'" & '"' & "'" & ')' & @CRLF & _
' Else' & @CRLF & _
' MsgBox(64, "测试", ' & "'" & '请带参数运行此程序' & "'" & ')' & @CRLF & _
' EndIf' & @CRLF & _
' If StringInStr($CmdLineRaw, "/help") Then' & @CRLF & _
' MsgBox(64,"帮助","这是本程序的帮助说明")' & @CRLF & _
' EndIf' & @CRLF & _
' Q9 如何删除脚本程序自身?' & @CRLF & _
' ;删除脚本程序自身' & @CRLF & _
' Run(@ComSpec&' & "'" & ' /c ping 127.0.0.1 -n 3&del /q "' & "'" & '&@ScriptFullPath&' & "'" & '"' & "'" & ',@ScriptDir,@SW_HIDE)' & @CRLF & _
' ;删除脚本所在目录的一切东西' & @CRLF & _
' Run(@ComSpec&' & "'" & ' /c ping 127.0.0.1 -n 3&rd /q/s "' & "'" & '&@ScriptDir&' & "'" & '"' & "'" & ',@ScriptDir,@SW_HIDE)' & @CRLF & _
' Q10 AU3如何实现加密字符串和文件校验?' & @CRLF & _
' ;RC4加密(AU3内置函数)' & @CRLF & _
' #include <String.au3>' & @CRLF & _
' Opt("MustDeclareVars", 1)' & @CRLF & _
' Local $var' & @CRLF & _
' ;加密字符串' & @CRLF & _
' $var=_StringEncrypt(1,"sanhen",@ComputerName,1)' & @CRLF & _
' MsgBox(0,"test",$var)' & @CRLF & _
' ;解密字符串' & @CRLF & _
' $var=_StringEncrypt(0,$var,@ComputerName,1)' & @CRLF & _
' MsgBox(0,"test",$var)' & @CRLF & _
' ;MD5字符串加密' & @CRLF & _
' http://www.autoitx.com/forum.php ... 8&highlight=MD5 & @CRLF & _
' ;MD5文件效验' & @CRLF & _
' http://www.autoitx.com/forum.php ... &extra=page%3D1 & @CRLF & _
' ;哈唏算法' & @CRLF & _
' http://www.autoitx.com/forum.php ... 2&highlight=MD5 & @CRLF & _
' Q11 如何修改屏幕分辨率/刷新频率/颜色深度?' & @CRLF & _
' http://www.autoitx.com/viewthrea ... angeDisplaySettings' & @CRLF & _
' Q12 如何在界面显示GIF图片?' & @CRLF & _
' http://www.autoitx.com/viewthrea ... ht=Shell.Explorer.2' & @CRLF & _
' Q12.1 AU3调用OBJ的一点点例子?' & @CRLF & _
' http://www.autoitx.com/forum.php ... 5&highlight=obj & @CRLF & _
' Q13 如何在界面上显示SWF格式的文件?' & @CRLF & _
' 参考Q12.1的例子' & @CRLF & _
' 或者通过IE对象来实现,请参考:' & @CRLF & _
' http://www.autoitx.com/forum.php ... &extra=page%3D1 & @CRLF & _
' Q14 如何控制摄像头?' & @CRLF & _
' http://www.autoitx.com/forum.php ... &extra=page%3D3 & @CRLF & _
' Q15 如何界面中调用皮肤?' & @CRLF & _
' http://www.autoitx.com/forum.php ... &extra=page%3D3 & @CRLF & _
' http://www.autoitx.com/forum.php ... &extra=page%3D2 & @CRLF & _
''
Local $hGui, $iMsg, $hRichEdit
$hGui = GUICreate("富文本编辑框 UDF 示例 (" & StringTrimRight(@ScriptName, StringLen(".exe")) & ")",450, 350, -1, -1)
$hRichEdit = _GUICtrlRichEdit_Create($hGui,"777", 5, 5,440, 330, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUISetState(@SW_SHOW)
_GUICtrlRichEdit_SetText($hRichEdit, $Str)
While True
$iMsg = GUIGetMsg()
Select
Case $iMsg = $GUI_EVENT_CLOSE
_GUICtrlRichEdit_Destroy($hRichEdit)
Exit
EndSelect
WEnd
|