Ticket #2746: IE6Example.htm

File IE6Example.htm, 21.2 KB (added by mLipok, 10 years ago)
Line 
1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2<html xmlns="http://www.w3.org/1999/xhtml">
3<head>
4<title>Sample_Ie6.au3</title>
5<meta name="Generator" content="SciTE - www.Scintilla.org" />
6<style type="text/css">
7.S0 {
8        color: #000000;
9        font-size: 10pt;
10}
11.S1 {
12        font-style: italic;
13        color: #008000;
14        font-size: 10pt;
15}
16.S3 {
17        color: #0000FF;
18        font-size: 10pt;
19}
20.S4 {
21        color: #000090;
22        font-size: 10pt;
23}
24.S5 {
25        color: #0000FF;
26        font-size: 10pt;
27}
28.S6 {
29        color: #808000;
30        font-size: 10pt;
31}
32.S7 {
33        color: #FF0000;
34        font-size: 10pt;
35}
36.S8 {
37        color: #FF8000;
38        font-size: 10pt;
39}
40.S9 {
41        color: #5A5A5A;
42        font-size: 10pt;
43}
44.S11 {
45        color: #808000;
46        font-size: 10pt;
47}
48.S14 {
49        color: #993399;
50        font-size: 10pt;
51}
52span {
53        font-family: 'Courier New';
54        color: #000000;
55        font-size: 10pt;
56}
57</style>
58</head>
59<body bgcolor="#F0F4F9">
60<span><span class="S1">; Example script, showing the usage of COM Event functions.</span><br />
61<span class="S1">; Requires at least AutoIt beta version 3.1.1.104 !</span><br />
62<span class="S1">;</span><br />
63<span class="S1">; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp</span><br />
64<br />
65<span class="S1">; We use a very simple GUI to show the results of our Events.</span><br />
66<br />
67<span class="S11">#include</span><span class="S0"> </span><span class="S7">"GUIConstantsEx.au3"</span><br />
68<br />
69<span class="S5">Global</span><span class="S0"> </span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$hGUIProg</span><br />
70<br />
71<span class="S0">Example</span><span class="S8">()</span><br />
72<span class="S5">Exit</span><span class="S0"> </span><span class="S1">; End of our Demo.</span><br />
73<br />
74<span class="S5">Func</span><span class="S0"> Example</span><span class="S8">()</span><br />
75<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$hGUIMain</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">GUICreate</span><span class="S8">(</span><span class="S7">"Event Test"</span><span class="S8">,</span><span class="S0"> </span><span class="S3">600</span><span class="S8">,</span><span class="S0"> </span><span class="S3">500</span><span class="S8">)</span><br />
76<span class="S0">&nbsp; &nbsp; </span><span class="S9">$hGUIEdit</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">GUICtrlCreateEdit</span><span class="S8">(</span><span class="S7">"Test Log:"</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S3">10</span><span class="S8">,</span><span class="S0"> </span><span class="S3">20</span><span class="S8">,</span><span class="S0"> </span><span class="S3">580</span><span class="S8">,</span><span class="S0"> </span><span class="S3">400</span><span class="S8">)</span><br />
77<span class="S0">&nbsp; &nbsp; </span><span class="S9">$hGUIProg</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">GUICtrlCreateProgress</span><span class="S8">(</span><span class="S3">10</span><span class="S8">,</span><span class="S0"> </span><span class="S3">5</span><span class="S8">,</span><span class="S0"> </span><span class="S3">580</span><span class="S8">,</span><span class="S0"> </span><span class="S3">10</span><span class="S8">)</span><br />
78<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$hGUIExit</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">GUICtrlCreateButton</span><span class="S8">(</span><span class="S7">" Close "</span><span class="S8">,</span><span class="S0"> </span><span class="S3">250</span><span class="S8">,</span><span class="S0"> </span><span class="S3">450</span><span class="S8">,</span><span class="S0"> </span><span class="S3">80</span><span class="S8">,</span><span class="S0"> </span><span class="S3">30</span><span class="S8">)</span><br />
79<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUISetState</span><span class="S8">()</span><span class="S0"> </span><span class="S1">;Show GUI</span><br />
80<br />
81<span class="S0">&nbsp; &nbsp; </span><span class="S1">; We prepare the Internet Explorer as our test subject</span><br />
82<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$oIE</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">ObjCreate</span><span class="S8">(</span><span class="S7">"InternetExplorer.Application.1"</span><span class="S8">)</span><br />
83<span class="S0">&nbsp; &nbsp; </span><span class="S5">With</span><span class="S0"> </span><span class="S9">$oIE</span><br />
84<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S8">.</span><span class="S14">Visible</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">1</span><br />
85<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S8">.</span><span class="S14">Top</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S8">(</span><span class="S6">@DesktopHeight</span><span class="S0"> </span><span class="S8">-</span><span class="S0"> </span><span class="S3">400</span><span class="S8">)</span><span class="S0"> </span><span class="S8">/</span><span class="S0"> </span><span class="S3">2</span><br />
86<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S8">.</span><span class="S14">Height</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">400</span><span class="S0"> </span><span class="S1">; Make it a bit smaller than our GUI.</span><br />
87<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S8">.</span><span class="S14">Width</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">600</span><br />
88<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S8">.</span><span class="S14">Silent</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">1</span><span class="S0"> </span><span class="S1">; Don't show IE's dialog boxes</span><br />
89<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$hIEWnd</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">HWnd</span><span class="S8">(.</span><span class="S14">hWnd</span><span class="S8">)</span><span class="S0"> </span><span class="S1">; Remember the Window, in case user decides to close it</span><br />
90<span class="S0">&nbsp; &nbsp; </span><span class="S5">EndWith</span><br />
91<br />
92<span class="S0">&nbsp; &nbsp; </span><span class="S1">; We choose for a specific Internet Explorer interface 'DWebBrowserEvents' because the IE is subject</span><br />
93<span class="S0">&nbsp; &nbsp; </span><span class="S1">; to modifications by e.g. Visual Studio and Adobe Acrobat Reader. If you have IE-plugins installed,</span><br />
94<span class="S0">&nbsp; &nbsp; </span><span class="S1">; AutoIt might not be able to find the correct interface automatically.</span><br />
95<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$oEventObject</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">ObjEvent</span><span class="S8">(</span><span class="S9">$oIE</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"IEEvent_"</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"DWebBrowserEvents"</span><span class="S8">)</span><br />
96<span class="S0">&nbsp; &nbsp; </span><span class="S5">If</span><span class="S0"> </span><span class="S6">@error</span><span class="S0"> </span><span class="S5">Then</span><br />
97<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S4">MsgBox</span><span class="S8">(</span><span class="S3">0</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"AutoIt COM Test"</span><span class="S8">,</span><span class="S0"> </span><span class="S8">_</span><br />
98<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S7">"ObjEvent: Can't use event interface 'DWebBrowserEvents'. Error code: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S4">Hex</span><span class="S8">(</span><span class="S6">@error</span><span class="S8">,</span><span class="S0"> </span><span class="S3">8</span><span class="S8">))</span><br />
99<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">Exit</span><br />
100<span class="S0">&nbsp; &nbsp; </span><span class="S5">EndIf</span><br />
101<br />
102<span class="S0">&nbsp; &nbsp; </span><span class="S1">; Now starting to load an example Web page.</span><br />
103<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$sURL</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S7">"http://www.AutoItScript.com/"</span><br />
104<span class="S0">&nbsp; &nbsp; </span><span class="S9">$oIE</span><span class="S8">.</span><span class="S14">Navigate</span><span class="S8">(</span><span class="S9">$sURL</span><span class="S8">)</span><br />
105<span class="S0">&nbsp; &nbsp; </span><span class="S4">Sleep</span><span class="S8">(</span><span class="S3">1000</span><span class="S8">)</span><span class="S0"> </span><span class="S1">; Give it some time to load the web page</span><br />
106<br />
107<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUISwitch</span><span class="S8">(</span><span class="S9">$hGUIMain</span><span class="S8">)</span><span class="S0"> </span><span class="S1">; Switch back to our GUI in case IE stole the focus</span><br />
108<br />
109<span class="S0">&nbsp; &nbsp; </span><span class="S1">; Waiting for user to close the GUI.</span><br />
110<span class="S0">&nbsp; &nbsp; </span><span class="S5">Local</span><span class="S0"> </span><span class="S9">$msg</span><br />
111<span class="S0">&nbsp; &nbsp; </span><span class="S5">While</span><span class="S0"> </span><span class="S3">1</span><br />
112<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S9">$msg</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S4">GUIGetMsg</span><span class="S8">()</span><br />
113<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">If</span><span class="S0"> </span><span class="S9">$msg</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S9">$GUI_EVENT_CLOSE</span><span class="S0"> </span><span class="S5">Or</span><span class="S0"> </span><span class="S9">$msg</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S9">$hGUIExit</span><span class="S0"> </span><span class="S5">Then</span><span class="S0"> </span><span class="S5">ExitLoop</span><br />
114<span class="S0">&nbsp; &nbsp; </span><span class="S5">WEnd</span><br />
115<br />
116<span class="S0">&nbsp; &nbsp; </span><span class="S9">$oEventObject</span><span class="S8">.</span><span class="S14">Stop</span><span class="S0"> </span><span class="S1">; Tell IE we don't want to receive events.</span><br />
117<span class="S0">&nbsp; &nbsp; </span><span class="S9">$oEventObject</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">0</span><span class="S0"> </span><span class="S1">; Kill the Event Object</span><br />
118<span class="S0">&nbsp; &nbsp; </span><span class="S5">If</span><span class="S0"> </span><span class="S4">WinExists</span><span class="S8">(</span><span class="S9">$hIEWnd</span><span class="S8">)</span><span class="S0"> </span><span class="S5">Then</span><span class="S0"> </span><span class="S9">$oIE</span><span class="S8">.</span><span class="S14">Quit</span><span class="S0"> </span><span class="S1">; Close IE Window</span><br />
119<span class="S0">&nbsp; &nbsp; </span><span class="S9">$oIE</span><span class="S0"> </span><span class="S8">=</span><span class="S0"> </span><span class="S3">0</span><span class="S0"> </span><span class="S1">; Remove IE from memory (not really necessary).</span><br />
120<br />
121<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUIDelete</span><span class="S8">()</span><span class="S0"> </span><span class="S1">; Remove GUI</span><br />
122<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;Example</span><br />
123<br />
124<span class="S1">; A few Internet Explorer Event Functions</span><br />
125<span class="S1">; See also: http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/webbrowser.asp</span><br />
126<span class="S5">Func</span><span class="S0"> IEEvent_BeforeNavigate</span><span class="S8">(</span><span class="S9">$sURL</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$Flags</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$TargetFrameName</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$PostData</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$Headers</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$Cancel</span><span class="S8">)</span><br />
127<span class="S0">&nbsp; &nbsp; </span><span class="S1">; &nbsp;&nbsp;Note: the declaration is different from the one on MSDN.</span><br />
128<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"BeforeNavigate: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$sURL</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S7">" Flags: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$Flags</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S7">" tgframe: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$TargetFrameName</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S7">" Postdat: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$PostData</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S7">" Hdrs: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$Headers</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S7">" canc: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$Cancel</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
129<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_BeforeNavigate</span><br />
130<br />
131<span class="S5">Func</span><span class="S0"> IEEvent_ProgressChange</span><span class="S8">(</span><span class="S9">$Progress</span><span class="S8">,</span><span class="S0"> </span><span class="S9">$ProgressMax</span><span class="S8">)</span><br />
132<span class="S0">&nbsp; &nbsp; </span><span class="S5">If</span><span class="S0"> </span><span class="S9">$ProgressMax</span><span class="S0"> </span><span class="S8">&gt;</span><span class="S0"> </span><span class="S3">0</span><span class="S0"> </span><span class="S5">Then</span><br />
133<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIProg</span><span class="S8">,</span><span class="S0"> </span><span class="S8">(</span><span class="S9">$Progress</span><span class="S0"> </span><span class="S8">*</span><span class="S0"> </span><span class="S3">100</span><span class="S8">)</span><span class="S0"> </span><span class="S8">/</span><span class="S0"> </span><span class="S9">$ProgressMax</span><span class="S8">)</span><br />
134<span class="S0">&nbsp; &nbsp; </span><span class="S5">EndIf</span><br />
135<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_ProgressChange</span><br />
136<br />
137<span class="S5">Func</span><span class="S0"> IEEvent_StatusTextChange</span><span class="S8">(</span><span class="S9">$sText</span><span class="S8">)</span><br />
138<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"IE Status text changed to: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$sText</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
139<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_StatusTextChange</span><br />
140<br />
141<span class="S5">Func</span><span class="S0"> IEEvent_PropertyChange</span><span class="S8">(</span><span class="S9">$szProperty</span><span class="S8">)</span><br />
142<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"IE Changed the value of the property: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$szProperty</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
143<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_PropertyChange</span><br />
144<br />
145<span class="S5">Func</span><span class="S0"> IEEvent_DownloadComplete</span><span class="S8">()</span><br />
146<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"IE has finished a navigation operation"</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
147<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_DownloadComplete</span><br />
148<br />
149<span class="S5">Func</span><span class="S0"> IEEvent_NavigateComplete</span><span class="S8">(</span><span class="S9">$sURL</span><span class="S8">)</span><br />
150<span class="S0">&nbsp; &nbsp; </span><span class="S1">; &nbsp;&nbsp;Note: the declaration is different from the one on MSDN.</span><br />
151<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"IE has finished loading URL: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$sURL</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
152<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_NavigateComplete</span><br />
153<br />
154<span class="S5">Func</span><span class="S0"> IEEvent_</span><span class="S8">(</span><span class="S9">$EventName</span><span class="S8">)</span><br />
155<span class="S0">&nbsp; &nbsp; </span><span class="S1">; This is an optional event function to catch non-defined events.</span><br />
156<span class="S0">&nbsp; &nbsp; </span><span class="S1">; The parameter contains the name of the event being called.</span><br />
157<span class="S0">&nbsp; &nbsp; </span><span class="S4">GUICtrlSetData</span><span class="S8">(</span><span class="S9">$hGUIEdit</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"Uncatched event: "</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S9">$EventName</span><span class="S0"> </span><span class="S8">&amp;</span><span class="S0"> </span><span class="S6">@CRLF</span><span class="S8">,</span><span class="S0"> </span><span class="S7">"append"</span><span class="S8">)</span><br />
158<span class="S5">EndFunc</span><span class="S0"> &nbsp;&nbsp;</span><span class="S1">;==&gt;IEEvent_</span><br />
159<span class="S0"></span></span>
160</body>
161</html>