#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
Local $i = 0 ,$t = 0, $n = 0
Opt("GUIOnEventMode", 1)
$Form0 = GUICreate("简单的AU3浏览器-初级试验品-功能还很不完善", 1024, 728, 0, 0) ;主窗体
FileInstall("OIE.exe", @TempDir & "") ;将同目录下的IE监控程序设置存取,编译前请先编译监控文件OIE.exe,放置同目录下。
$Button1 = GUICtrlCreateButton("百度网址大全", 5, 30, 150, 30)
$Button81 = GUICtrlCreateButton("退出", 720, 0, 150, 30)
$Button80 = GUICtrlCreateButton("帮助", 720, 30, 150, 30)
GUICtrlSetOnEvent($Button1, "Activate1") ; 设置按钮控件单击事件
GUICtrlSetOnEvent($Button81, "Activate81") ; 设置按钮控件单击事件
GUISetState(@SW_SHOW)
$Form1 = GUICreate("首页", 1024, 650,8, 80,BitOR($WS_POPUP,$WS_CLIPSIBLINGS),BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST )) ;首页窗体
$WebBrowser1=ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($WebBrowser1, -12, 0, 1024, 750) ;对$WebBrowser1对象设置大小
$EventObject=ObjEvent($WebBrowser1,"IEEvent_","DWebBrowserEvents") ;设置通过UDF接收windows事件
$URL = "http://site.baidu.com" ;自定义首页
$WebBrowser1.Navigate($URL)
GUISetState(@SW_SHOW)
RunWait (@TempDir & "\OIE.exe","",@SW_HIDE) ;运行IE监控
While 1
Sleep (1)
WEnd
;=====================================
Func IEEvent_NewWindow($URL) ; 接收IE的NewWindow事件。注意NewWindow2无效。有新窗口时发生,较早
;ProcessClose ("iexplore.exe")
GUISwitch ($Form1) ;切换到此窗体下
$Form2 = GUICreate($URL, 1024, 650,8, 80,BitOR($WS_POPUP,$WS_CLIPSIBLINGS),BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST )) ;作为装载IE新页面的窗体
$WebBrowser2=ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($WebBrowser2, -12, 0, 1024, 750)
$EventObject=ObjEvent($WebBrowser2,"IEEvent_","DWebBrowserEvents")
$WebBrowser2.Navigate($URL)
GUISetState(@SW_SHOW)
$n = $n + 1
If $n >= 4 Then
WinKill ( $URL, "")
Msgbox(0,"","对不起!本浏览器暂时只支持同时打开3个页面,5秒后将自动退出",5)
ProcessClose ("OIE.exe")
Activate81() ;警告后直接退出AU3
EndIf
EndFunc
;----------------------------------------
Func IEEvent_TitleChange($URL) ; 接收IE的TitleChange事件。获取网页标题。在可以获取title时发生,较晚。
$i = $i + 1
IniWrite(@TempDir & "\title.ini", "title"&$i,"", $URL) ; 将所获得的URL标题写入配置ini文件
EndFunc
;----------------------------------------
Func IEEvent_NavigateComplete($URL) ; 接收IE的TNavigateComplete事件。获取网页网址。比TitleChange事件稍早
$t = $t + 1
IniWrite(@TempDir & "\ini.ini", "title"&$t,"", $URL) ;将所获得的URL网址写入INI文件
EndFunc ;==>IEEvent_NavigateComplete ;目的通过按钮(标签)点击激活指定窗口,显示指定页
;----------------------------------------
Func IEEvent_StatusTextChange () ; 接收IE的IEEvent_StatusTextChange事件。触发自定义的wwwTab()事件 。更晚。
wwwTab() ; 此事件中按钮需要从title.ini文件中获取显示文本,因此只能发生在title.ini写入之后
EndFunc
;====================================================================================
Func wwwTab()
GUISwitch ($Form0)
$var2 = IniRead(@TempDir & "\title.ini", "title4", "", "")
$var3 = IniRead(@TempDir & "\title.ini", "title6", "", "")
$var4 = IniRead(@TempDir & "\title.ini", "title8", "", "")
$var5 = IniRead(@TempDir & "\title.ini", "title10", "", "")
$Button2 = GUICtrlCreateButton($var2, 155, 30, 150, 30)
$Button3 = GUICtrlCreateButton($var3, 305, 30, 150, 30)
$Button4 = GUICtrlCreateButton($var4, 455, 30, 150, 30)
$Button5 = GUICtrlCreateButton($var5, 606, 30, 150, 30)
GUICtrlSetOnEvent($Button2, "Activate2")
GUICtrlSetOnEvent($Button3, "Activate3")
GUICtrlSetOnEvent($Button4, "Activate4")
GUICtrlSetOnEvent($Button5, "Activate5")
If $var2 = False Then
GUICtrlSetState ( $Button2, $GUI_HIDE) ; 窗体隐藏 $GUI_HIDE
Else ; 否则
GUICtrlSetState ( $Button2, $GUI_SHOW) ; 窗体显示 $GUI_SHOW
EndIf
If $var3 = False Then
GUICtrlSetState ( $Button3, $GUI_HIDE)
Else
GUICtrlSetState ( $Button3, $GUI_SHOW)
EndIf
If $var4 = False Then
GUICtrlSetState ( $Button4, $GUI_HIDE)
Else
GUICtrlSetState ( $Button4, $GUI_SHOW)
EndIf
If $var5 = False Then
GUICtrlSetState ( $Button5, $GUI_HIDE)
Else
GUICtrlSetState ( $Button5, $GUI_SHOW)
EndIf
EndFunc ;==>wwwTab() 自定义的窗体按钮标签事件
;=================================================================
Func Activate91()
$var = IniRead(@TempDir & "\ini.ini", "title1", "", "")
WinActivate ( $var, "" )
EndFunc ;==>Activate9
Func Activate2()
$var = IniRead(@TempDir & "\ini.ini", "title2", "", "")
WinActivate ( $var, "" )
EndFunc ;==>Activate2
Func Activate3()
$var = IniRead(@TempDir & "\ini.ini", "title3", "", "")
WinActivate ( $var, "" )
EndFunc ;==>Activate3
Func Activate4()
$var = IniRead(@TempDir & "\ini.ini", "title4", "", "")
WinActivate ( $var, "" )
EndFunc ;==>Activate4
Func Activate5()
$var = IniRead(@TempDir & "\ini.ini", "title5", "", "")
WinActivate ( $var, "" )
EndFunc ;==>Activate5
Func Activate1()
WinActivate ("首页", "" )
EndFunc ;==>Activate1
Func Activate80()
GUISwitch ($Form0)
$Form80 = GUICreate("帮助", 400, 300, 250, 214,$WS_CAPTION,$WS_EX_TOPMOST)
$Labe80 = GUICtrlCreateLabel("报歉!东西很烂,功能有待各位开发!", 78,80, 333, 153)
GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$Button88 = GUICtrlCreateButton("关闭", 88, 180, 150, 30)
GUICtrlSetOnEvent($Button88, "Activate88")
GUISetState(@SW_SHOW)
Sleep (2000)
WinKill ( "帮助", "" )
EndFunc ;==>Activate80
Func Activate88()
WinKill ( "帮助", "" )
EndFunc ;==>Activate81
Func Activate81()
qinkong1()
qinkong2()
ProcessClose ("OIE.exe")
Exit
EndFunc ;==>Activate81
Func qinkong1()
FileDelete(@TempDir & "\ini.ini") ;直接删除
EndFunc ;==>qinkong1()
Func qinkong2()
FileDelete(@TempDir & "\title.ini")
EndFunc ;==>qinkong2()
; end