#include <ButtonConstants.au3>
#include "GUIConstantsEx.au3"
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <IE.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
Local $r = 1,$i = 0 ,$t = 0, $n = 0,$b = 0,$Text,$Text2="",$URL = "http://site.baidu.com"
Local $Form80,$Form[5],$Form2,$Button2,$Button3,$Button4,$Button5
$dll = DllOpen("user32.dll")
$WebBrowser2=ObjCreate("Shell.Explorer.2")
$Form0 = GUICreate("AU3简单多标签浏览器", 623, 449, 192, 114,$WS_OVERLAPPEDWINDOW) ;主窗体
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;GUIOnEventMode 模式下添加窗口关闭
$Graphic1 = GUICtrlCreateGraphic(0, 0, @DesktopWidth, 0) ;(左 顶 宽 高) 添加绘图控件
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 0, 30) ; 移位 绘图控件坐标0原点,移动起点到新坐标,下移30
GUICtrlSetGraphic(-1, $GUI_GR_LINE, @DesktopWidth, 30) ; 横线 从新起点画一横线
;GUICtrlSetGraphic(-1, $GUI_GR_PENSIZE, 5) ; 定义此点画线粗细
$Button1 = GUICtrlCreateButton("首页", 0, 36, 110, 25)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button75 = GUICtrlCreateButton("停止", 0, 0, 40, 30) ;定义主窗口基本功能按钮
GUICtrlSetResizing (-1, $GUI_DOCKALL) ;锁定控件位置
$Button76 = GUICtrlCreateButton("前进", 45, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button77 = GUICtrlCreateButton("后退", 90, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button78 = GUICtrlCreateButton("刷新", 135, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button79 = GUICtrlCreateButton("主页", 180, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button81 = GUICtrlCreateButton("退出", 225, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button80 = GUICtrlCreateButton("帮助", 270, 0, 40, 30)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$Button82 = GUICtrlCreateButton("确定", 800, 5, 40, 20)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$address_bar_label = GUICtrlCreateLabel("地址: ", 335, 8, 40, 20)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
Global $ini = "autoit.ini"
$iniread = IniRead($ini, "URL", "LAST URL", " ")
Global $read_homepage = IniRead($ini, "Settings", "Homepage", "")
Global $read_starthomepage = IniRead($ini, "Settings", "StartHomepage", "")
If $read_starthomepage = "0" Then $read_homepage = $iniread
$address_bar_input = GUICtrlCreateInput($read_homepage, 390, 5, 400, -1) ;设置输入框(Input)控件,作为网址输入及显示
GUICtrlSetResizing (-1, $GUI_DOCKALL)
GUICtrlSetOnEvent($Button1, "Activate1")
GUICtrlSetOnEvent($Button75, "Activate75")
GUICtrlSetOnEvent($Button76, "Activate76")
GUICtrlSetOnEvent($Button77, "Activate77")
GUICtrlSetOnEvent($Button78, "Activate78")
GUICtrlSetOnEvent($Button79, "Activate79")
GUICtrlSetOnEvent($Button80, "Activate80")
GUICtrlSetOnEvent($Button81, "Activate81") ; 设置按钮控件单击事件
GUICtrlSetOnEvent($Button82, "address_bar_input")
$status_bar = GUICtrlCreateLabel("载入: " & $read_homepage & "...", 0, 584, "", "", BitOR(11, 0x1000))
GUISetState(@SW_SHOW)
;------------------------------------------------
$Form1 = GUICreate("首窗", 1024, 650, 0, 60,$WS_POPUP) ;设置初载的首页窗体Form1
DllCall("user32.dll","hwnd","SetParent","hwnd",$Form1,"hwnd",$Form0) ;设置Form1yl为Form0的子窗口.
;_WinAPI_SetParent与DllCall-"SetParent"等效。对比学习两者的关系。
;_WinAPI_SetParent($Form1,$Form0)
$WebBrowser1=ObjCreate("Shell.Explorer.2") ;等效 _IECreateEmbedded()
GUICtrlCreateObj($WebBrowser1,0, 0, 1024, 750) ;设置WebBrowser1对象大小
$EventObject=ObjEvent($WebBrowser1,"IEEvent_","DWebBrowserEvents") ;设置接收windows事件
if @error then exit Msgbox(0,"错误!","不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & hex(@error,8))
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword") ;设置Timer控件
$TimerDLL = DllCall($dll, "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10, "ptr", DllCallbackGetPtr($Timer))
;函数SetTimer,用WM_TIMER来设置定时器。每隔10毫秒自动执行一次DllCallbackRegister,创建自定义回调函数Timer
;参看后面的Timer()事件
$WebBrowser1.Navigate( $URL) ;自定义首页
GUISetState(@SW_SHOW)
GUISwitch ($Form0) ;切换当前窗口到主窗口
;-------------------------------------------------------------
While 1
Sleep (1)
$cursor = _WinAPI_GetCursorInfo() ;获取鼠标状态
If $cursor[2]=65581 And _IsPressed("1", $dll) Then
WinSetOnTop($Form1,"",1)
MsgBox(0,"IE内嵌不新建IE窗口", "0",1,WinGetHandle("Program Manager"))
WinSetOnTop($Form1,"",0)
If $Text2<>"" Then
WebBrowser1_Navigate() ;自定义打开新页事件
EndIf
EndIf
$msg = GUIGetMsg()
Wend
;-------------------------------------------------------------
Func WebBrowser1_Navigate()
GUISwitch($Form0)
$r = $r + 1
$Form[$r] = GUICreate($Text2, 1024, 650, 0, 60,$WS_POPUP) ;设置$Form[$r]作为装载IE新页面的窗体
_WinAPI_SetParent($Form[$r],$Form0) ;设置Form[$r]为Form0的子窗口.
$WebBrowser2=ObjCreate("Shell.Explorer.2")
GUICtrlCreateObj($WebBrowser2, -12, 0, 1024, 750)
$EventObject=ObjEvent($WebBrowser2,"IEEvent_","DWebBrowserEvents")
if @error then exit Msgbox(0,"错误!","不可使用COM接口 'DWebBrowserEvents'. 错误代码: " & hex(@error,8))
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall($dll, "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10, "ptr", DllCallbackGetPtr($Timer))
$WebBrowser2.Navigate( $Text2 )
GUISetState(@SW_SHOW)
EndFunc
;--------------------------------------------
Func IEEvent_TitleChange($URL) ; 接收IE的TitleChange事件。获取网页标题。在可以获取title时发生,较晚。
$WR = IniRead ("web.ini","Button","Refresh","1")
$WF = IniRead ("web.ini","Button","Forward","1")
$WG = IniRead ("web.ini","Button","GoBack","1")
If $WR =1 And StringCompare ($URL,$WebBrowser2.LocationName) <> 0 And StringInStr($URL, "_") ="_" And StringLeft($URL,4)<>"http" Then
; 将$URL标题中不合条件的标题剔除
$i = $i + 1
IniWrite("title.ini", "www","title"&$i, $URL) ; 将所获得的URL标题写入配置ini文件
EndIf
wwwTab()
IniDelete ("web.ini","Button", "Refresh")
IniDelete ("web.ini","Button", "Forward")
IniDelete ("web.ini","Button", "GoBack")
EndFunc
;----------------------------------------
Func IEEvent_StatusTextChange ($Text) ; 接收IE的IEEvent_StatusTextChange事件。
If $Text<>'' And StringLeft($Text,4)="http" Then $Text2=$Text
EndFunc
;====================================================================================
Func wwwTab()
GUISwitch ($Form0)
$var2 = IniRead("title.ini", "www", "title2", "no")
$var3 = IniRead("title.ini", "www", "title3", "no")
$var4 = IniRead("title.ini", "www", "title4", "no")
$var5 = IniRead("title.ini", "www", "title5", "no")
$Button2 = GUICtrlCreateButton($var2, 110, 36, 110, 25)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$contextmenu2 = GUICtrlCreateContextMenu ($Button2) ; 创建右键菜单
$FormCLOSE2 = GUICtrlCreateMenuitem ("关闭",$contextmenu2) ; 关闭此窗口
GUICtrlSetOnEvent($FormCLOSE2, "FormCLOSE2")
$Button3 = GUICtrlCreateButton($var3, 220, 36, 110, 25)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$contextmenu3 = GUICtrlCreateContextMenu ($Button3) ; 创建右键菜单
$FormCLOSE3 = GUICtrlCreateMenuitem ("关闭",$contextmenu3) ; 关闭此窗口
GUICtrlSetOnEvent($FormCLOSE3, "FormCLOSE3")
$Button4 = GUICtrlCreateButton($var4, 330, 36, 110, 25)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$contextmenu4 = GUICtrlCreateContextMenu ($Button4) ; 创建右键菜单
$FormCLOSE4 = GUICtrlCreateMenuitem ("关闭",$contextmenu4) ; 关闭此窗口
GUICtrlSetOnEvent($FormCLOSE4, "FormCLOSE4")
$Button5 = GUICtrlCreateButton($var5, 440, 36, 110, 25)
GUICtrlSetResizing (-1, $GUI_DOCKALL)
$contextmenu5 = GUICtrlCreateContextMenu ($Button5) ; 创建右键菜单
$FormCLOSE5 = GUICtrlCreateMenuitem ("关闭",$contextmenu5) ; 关闭此窗口
GUICtrlSetOnEvent($FormCLOSE5, "FormCLOSE5")
GUICtrlSetOnEvent($Button2, "Activate2")
GUICtrlSetOnEvent($Button3, "Activate3")
GUICtrlSetOnEvent($Button4, "Activate4")
GUICtrlSetOnEvent($Button5, "Activate5")
If $var2 = "no" Then
GUICtrlSetState ( $Button2, $GUI_HIDE) ; 控件隐藏 $GUI_HIDE
Else ; 否则
GUICtrlSetState ( $Button2, $GUI_SHOW) ; 控件显示 $GUI_SHOW
EndIf
If $var3 = "no" Then
GUICtrlSetState ( $Button3, $GUI_HIDE)
Else
GUICtrlSetState ( $Button3, $GUI_SHOW)
EndIf
If $var4 = "no" Then
GUICtrlSetState ( $Button4, $GUI_HIDE)
Else
GUICtrlSetState ( $Button4, $GUI_SHOW)
EndIf
If $var5 = "no" Then
GUICtrlSetState ( $Button5, $GUI_HIDE)
Else
GUICtrlSetState ( $Button5, $GUI_SHOW)
EndIf
EndFunc ;==>wwwTab() 自定义的窗体按钮标签事件
;=================================================================
Func Activate1()
_WinAPI_SetParent($Form1,$Form0) ;用重设子窗口的方式来激活指定窗口。在SetParent之后,WinActivate,PostMessage都失效。
EndFunc ;==>Activate1
Func Activate2()
_WinAPI_SetParent($Form[2],$Form0)
EndFunc ;==>Activate2
Func Activate3()
_WinAPI_SetParent($Form[3],$Form0)
EndFunc ;==>Activate3
Func Activate4()
_WinAPI_SetParent($Form[4],$Form0)
EndFunc ;==>Activate4
Func Activate5()
_WinAPI_SetParent($Form[5],$Form0)
EndFunc ;==>Activate5
;----------------------------------------------------------------
Func Activate75()
_IEErrorHandlerRegister ("MyErrFunc_Stop")
$WebBrowser2.Stop
EndFunc ;==>Activate75
Func Activate76()
_IEErrorHandlerRegister ("MyErrFunc_Forward") ;设定错误处理事件.
$WebBrowser2.GoForward
IniWrite ("web.ini", "Button", "Forward", "et" )
EndFunc ;==>Activate76
Func Activate77()
_IEErrorHandlerRegister ("MyErrFunc_GoBack")
$WebBrowser2.GoBack
IniWrite ("web.ini", "Button", "GoBack", "et" )
EndFunc ;==>Activate77
Func Activate78()
_IEErrorHandlerRegister ("MyErrFunc_Refresh")
$WebBrowser2.Refresh
IniWrite ("web.ini", "Button", "Refresh", "et" )
EndFunc ;==>Activate78
Func Activate79()
_IEErrorHandlerRegister ("MyErrFunc_Navigate")
$WebBrowser2.Navigate
EndFunc ;==>Activate79
Func Activate80()
GUISwitch ($Form0)
$Form80 = GUICreate("帮助", 400, 300, 250, 214)
$Button801 = GUICtrlCreateButton("关闭", 88, 180, 150, 30)
GUICtrlSetOnEvent($Button801, "CLOSEActivate80")
GUISetState(@SW_SHOW)
EndFunc ;==>Activate80
Func CLOSEActivate80()
_WinAPI_SetParent($Form80,$Form0)
_WinAPI_MoveWindow($Form80, 0, 0, 0, 0, True)
EndFunc ;==>Activate81
Func FormCLOSE2()
_WinAPI_MoveWindow($Form[2], 0, 0, 0, 0, True)
GUICtrlSetState ($Button2, $GUI_HIDE)
IniDelete ("title.ini", "www", "title2")
EndFunc
Func FormCLOSE3()
_WinAPI_MoveWindow($Form[3], 0, 0, 0, 0, True)
GUICtrlSetState ($Button3, $GUI_HIDE)
IniDelete ("title.ini", "www", "title3")
EndFunc
Func FormCLOSE4()
_WinAPI_MoveWindow($Form[4], 0, 0, 0, 0, True)
GUICtrlSetState ($Button4, $GUI_HIDE)
IniDelete ("title.ini", "www", "title4")
EndFunc
Func FormCLOSE5()
_WinAPI_MoveWindow($Form[5], 0, 0, 0, 0, True)
GUICtrlSetState ($Button5, $GUI_HIDE)
IniDelete ("title.ini", "www", "title5")
EndFunc
;----------------------------------------------------------------
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
If WinExists("IE内嵌不新建IE窗口") Then
WinMove("IE内嵌不新建IE窗口","",@DesktopWidth,@DesktopHeight,0,0,1)
Send("{Enter}")
EndIf
EndFunc
;-----------------------------------------------------------------
Func MyErrFunc_Stop()
$ErrorOutput = ""
$ErrorOutput &= "停止打开!"
MsgBox(0,"COM Error", $ErrorOutput)
SetError(1)
Return
EndFunc ;==>MyErrFunc_Stop
Func MyErrFunc_Forward()
$ErrorOutput = ""
$ErrorOutput &= "无法前进!"
MsgBox(0,"COM Error", $ErrorOutput)
SetError(1)
Return
EndFunc ;==>MyErrFunc_Forward
Func MyErrFunc_GoBack()
$ErrorOutput = ""
$ErrorOutput &= "无法后退!"
MsgBox(0,"COM Error", $ErrorOutput)
SetError(1)
Return
EndFunc ;==>MyErrFunc_GoBack
Func MyErrFunc_Refresh()
$ErrorOutput = ""
$ErrorOutput &= "无法刷新!"
MsgBox(0,"COM Error", $ErrorOutput)
SetError(1)
Return
EndFunc ;==>MyErrFunc_Refresh
Func MyErrFunc_Navigate()
$ErrorOutput = ""
$ErrorOutput &= "没有主页!"
MsgBox(0,"COM Error", $ErrorOutput)
SetError(1)
Return
EndFunc ;==>MyErrFunc_Navigate
;----------------------------------------------------------------
Func address_bar_input()
$addy = GUICtrlRead($address_bar_input)
_StatusChange("Loading: " & $addy & "...")
WebBrowser1_Navigate()
$WebBrowser2.Navigate( $addy)
_StatusChange("Done.")
EndFunc
Func _StatusChange($message)
GUICtrlSetData($status_bar, $message)
EndFunc ;==>_StatusChange
;----------------------------------------------------------------
Func CLOSE()
$EventObject.Stop ; 不再接收事件
$EventObject=0 ; 关闭Event Object
$WebBrowser1=0 ; 清除内存
GUIDelete ()
DllCall($dll, "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL)
DllCallbackFree($Timer)
DllClose($dll)
FileDelete("ini.ini") ;直接删除
FileDelete("title.ini")
FileDelete("url.ini")
;MsgBox(0, "谢谢", "报歉!学做的东西!...",3)
Exit
EndFunc
Func Activate81()
CLOSE()
EndFunc ;==>Activate81
Func CLOSEClicked()
CLOSE()
EndFunc