#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <IE.au3>
Opt("GUIResizeMode", 1)
Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)
Global $Title = "Explorer"
Global $IEPage = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main", "Start Page")
_IEErrorHandlerRegister()
$oIE = _IECreateEmbedded()
$GUIMain = GUICreate($Title, 800, 600, -1, -1, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX, _
$WS_THICKFRAME, $WS_SYSMENU, $WS_CAPTION, $WS_OVERLAPPEDWINDOW, $WS_TILEDWINDOW, $WS_POPUP, $WS_POPUPWINDOW, _
$WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$hStatus = _GUICtrlStatusBar_Create($GUIMain)
GUICtrlSetResizing($hStatus, $GUI_DOCKLEFT + $GUI_DOCKRIGHT + $GUI_DOCKTOP + $GUI_DOCKHEIGHT)
$BackButton = GUICtrlCreateButton("后退", 1, 2, 30, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$ForwardButton = GUICtrlCreateButton("前进", 31, 2, 30, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$PageButton = GUICtrlCreateButton("主页", 62, 2, 30, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlCreateGraphic(95, 2, 2, 23, BitOR($SS_NOTIFY, $SS_SUNKEN))
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
GUICtrlCreateLabel("地址:", 102, 7, 31, 17)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT)
$IEAdd = GUICtrlCreateCombo($IEPage, 134, 2, 400, 21)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)
$OpenIE = GUICtrlCreateButton("刷新", 538, 2, 30, 21)
GUICtrlSetResizing($OpenIE, $GUI_DOCKWIDTH + $GUI_DOCKHEIGHT + $GUI_DOCKHCENTER)
GUICtrlCreateObj($oIE, 0, 25, 800, 556)
GUICtrlSetResizing(-1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM)
$EventObject = ObjEvent($oIE, "IEEvent_", "DWebBrowserEvents")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "gui")
GUICtrlSetOnEvent($BackButton, "gui")
GUICtrlSetOnEvent($ForwardButton, "gui")
GUICtrlSetOnEvent($PageButton, "gui")
GUICtrlSetOnEvent($OpenIE, "gui")
GUISetState()
TraySetToolTip($Title)
$item_0 = TrayCreateItem("隐藏窗口")
TrayCreateItem("")
$item_1 = TrayCreateItem("清理内存")
TrayCreateItem("")
$item_2 = TrayCreateItem("退 出")
TraySetClick(8)
TraySetOnEvent(-13, "TrayEvent")
TrayItemSetOnEvent($item_2, "ExitScript")
TrayItemSetOnEvent($item_0, "TrayEvent")
TrayItemSetOnEvent($item_1, "TrayEvent")
GUISetState(@SW_SHOW)
_IENavigate($oIE, $IEPage)
While 1
_ReduceMemory()
Sleep(100)
WEnd
Func gui()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE, $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE)
TrayItemSetText($item_0, "显示窗口")
Case $BackButton
_IEAction($oIE, "back")
Case $ForwardButton
_IEAction($oIE, "forward")
Case $PageButton
_IENavigate($oIE, $IEPage)
Case $OpenIE
_IENavigate($oIE, GUICtrlRead($IEAdd))
EndSwitch
EndFunc ;==>gui
Func TrayEvent()
Switch @TRAY_ID
Case -13, $item_0
If TrayItemGetText($item_0) = "隐藏窗口" Then
GUISetState(@SW_HIDE)
TrayItemSetText($item_0, "显示窗口")
Else
GUISetState(@SW_SHOW)
GUISetState(@SW_RESTORE)
TrayItemSetText($item_0, "隐藏窗口")
EndIf
Case $item_1
$list = ProcessList()
For $i = 1 To $list[0][0]
_ReduceMemory($list[$i][1])
Next
EndSwitch
EndFunc ;==>TrayEvent
Func IEEvent_StatusTextChange($Text)
If $Text <> '' And StringLeft($Text, 4) = "http" Then $Text2 = $Text
_GUICtrlStatusBar_SetText($hStatus, $Text)
EndFunc ;==>IEEvent_StatusTextChange
Func IEEvent_TitleChange()
If _IEPropertyGet($oIE, "title") = "" Then
WinSetTitle($GUIMain, "", _IEPropertyGet($oIE, "locationurl") & " - " & $Title)
Else
WinSetTitle($GUIMain, "", _IEPropertyGet($oIE, "title") & " - " & $Title)
EndIf
EndFunc
Func IEEvent_CommandStateChange()
GUICtrlSetData($IEAdd, _IEPropertyGet($oIE, "locationurl"))
EndFunc ;==>IEEvent_DownloadComplete
Func ExitScript()
$EventObject.Stop ; 不再接收事件
$EventObject = 0 ; 关闭Event Object
$oIE = 0 ; 清除内存
GUIDelete()
Exit
EndFunc ;==>ExitScript
Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
_GUICtrlStatusBar_Resize($hStatus)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE
Func _ReduceMemory($i_PID = @AutoItPID)
If $i_PID <> -1 Then
Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $i_PID)
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
Else
Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', -1)
EndIf
Return $ai_Return[0]
EndFunc ;==>_ReduceMemory
这是我用来挂网页游戏的,如何用 CommandStateChange 事件 实现 “前进”“后退”变灰色,下面是找到的 CommandStateChange 事件是介绍 ,CommandStateChange
CommandStateChange 是当Internet Explorer 想通知一个应用程序WebBrowser 命令状态已经改变时激发.当检测到Forward和Back 菜单项和按钮禁止或者使能时激发此事件.
CommandStateChange 事件有2个参数, Command 和 Enable。Command 输入参数将要改变状态的按钮的表示符,可以取值—CSC_NAVIGATEFORWARD 和 CSC_NAVIGATEBACK分别表示是Forward按钮项和Back项,每次导航发生, CommandStateChange 事件发生并告诉你Forward 或者 Back 菜单项以及按钮将使能或禁止. 举例来说, 如果没有Web页在当前导航后发生, Command 的值应该为 CSC_NAVIGATEFORWARD, 并且Enable 参数将等于VARIANT_FALSE.
第二个参数, Enable,如果命令可用(使能) 则为VARIANT_TRUE,如果禁止则值为VARIANT_FALSE.
为说明问题,我们看看代码。一下代码为定义事件接收的宏声明:
重要的一点是要通过WebBrowser控件的Create 方法来创建. ON_EVENT的第二个参数为你宿主的WebBrowser控件的IID.之前的例子中是NULL. 你必须为webbrowser控件声明一个ID 且用此 ID 创建实例.如果不这么做,事件将不会正确工作.
你可以在工程的任何文件定义此ID. (推荐在资源头文件resource.h.) 因为 最大的资源Id是32,779, 所以你可以如下定义WebBrowser 控件的ID:
#define IDC_WEBBROWSER 35000
此数高于resource.h中的任何资源ID, 因此可以确信ID 数字不会同采用ClassWizard添加的ID冲突.现在可以采用使用ID的 Create 方法来创建WebBrowser控件:
if (!m_webBrowser.Create(NULL, WS_CHILD|WS_VISIBLE,
CRect(), this, IDC_WEBBROWSER))
{
return -1;
}
下一步声明OnCommandStateChange 方法,该方法将在WebBrowser控件激发CommandStateChange 事件时被调用.可声明 如下:
void OnCommandStateChange(long lCommand, BOOL bEnable);
在 OnCommandStateChange 方法的是现代码中, 设定表示Go Forward 或者 Go Back 想得导航菜单项的数据成员为使能或者禁止. 该书据成员将被UPDATE_COMMAND_UI 句柄使用。以下为OnCommandStateChange 方法实现:
声明m_fForwardEnabled 和 m_fBackEnabled 数据变量为保护成员,类型为BOOL.同样在构造函数中谁的些数据成员为TRUE。.
现在当Go Forward和Go Back的菜单 UPDATE_COMMAND_UI被处理, 你可以直接进行设置. 下为示例代码:
|