You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/atl/putting-the-control-on-a-web-page-atl-tutorial-part-7.md
+62-58Lines changed: 62 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,63 +11,67 @@ ms.author: "mblome"
11
11
ms.workload: ["cplusplus"]
12
12
---
13
13
# Putting the Control on a Web Page (ATL Tutorial, Part 7)
14
-
Your control is now finished. To see your control work in a real-world situation, put it on a Web page. An HTML file that contains the control was created when you defined your control. Open the PolyCtl.htm file from **Solution Explorer**, and you can see your control on a Web page.
15
-
16
-
In this step, you will script the Web page to respond to events. You will also modify the control to let Internet Explorer know that the control is safe for scripting.
17
-
18
-
## Scripting the Web Page
19
-
The control does not do anything yet, so change the Web page to respond to the events that you send.
20
-
21
-
#### To script the Web page
22
-
23
-
1. Open PolyCtl.htm and select HTML view. Add the following lines to the HTML code. They should be added after `</OBJECT>` but before `</BODY>`.
24
-
25
-
```
26
-
27
-
<SCRIPT LANGUAGE="VBScript">
28
-
<!--
29
-
Sub PolyCtl_ClickIn(x, y)
30
-
PolyCtl.Sides = PolyCtl.Sides + 1
31
-
End Sub
32
-
Sub PolyCtl_ClickOut(x, y)
33
-
PolyCtl.Sides = PolyCtl.Sides - 1
34
-
End Sub
35
-
-->
36
-
</SCRIPT>
37
-
```
38
-
39
-
2. Save the HTM file.
40
-
41
-
You have added some VBScript code that gets the Sides property from the control and increases the number of sides by one if you click inside the control. If you click outside the control, you reduce the number of sides by one.
42
-
43
-
## Indicating that the Control Is Safe for Scripting
44
-
You can view the Web page with the control in Internet Explorer or, more conveniently, use the Web browser view built into Visual C++. To see your control in the Web browser view, right-click PolyCtl.htm, and click **View in Browser**.
45
-
46
-
Based on your current Internet Explorer security settings, you may receive a Security Alert dialog box stating that the control may not be safe to script and could potentially do damage. For example, if you had a control that displayed a file but also had a `Delete` method that deleted a file, it would be safe if you just viewed it on a page. It would be not safe to script, however, because someone could call the `Delete` method.
47
-
14
+
15
+
Your control is now finished. To see your control work in a real-world situation, put it on a Web page. An HTML file that contains the control was created when you defined your control. Open the PolyCtl.htm file from **Solution Explorer**, and you can see your control on a Web page.
16
+
17
+
In this step, you will script the Web page to respond to events. You will also modify the control to let Internet Explorer know that the control is safe for scripting.
18
+
19
+
## Scripting the Web Page
20
+
21
+
The control does not do anything yet, so change the Web page to respond to the events that you send.
22
+
23
+
#### To script the Web page
24
+
25
+
1. Open PolyCtl.htm and select HTML view. Add the following lines to the HTML code. They should be added after `</OBJECT>` but before `</BODY>`.
26
+
27
+
```html
28
+
<SCRIPTLANGUAGE="VBScript">
29
+
<!--
30
+
Sub PolyCtl_ClickIn(x, y)
31
+
PolyCtl.Sides=PolyCtl.Sides+1
32
+
End Sub
33
+
Sub PolyCtl_ClickOut(x, y)
34
+
PolyCtl.Sides=PolyCtl.Sides-1
35
+
End Sub
36
+
-->
37
+
</SCRIPT>
38
+
```
39
+
40
+
2. Save the HTM file.
41
+
42
+
You have added some VBScript code that gets the Sides property from the control and increases the number of sides by one if you click inside the control. If you click outside the control, you reduce the number of sides by one.
43
+
44
+
## Indicating that the Control Is Safe for Scripting
45
+
46
+
You can view the Web page with the control in Internet Explorer or, more conveniently, use the Web browser view built into Visual C++. To see your control in the Web browser view, right-click PolyCtl.htm, and click **View in Browser**.
47
+
48
+
Based on your current Internet Explorer security settings, you may receive a Security Alert dialog box stating that the control may not be safe to script and could potentially do damage. For example, if you had a control that displayed a file but also had a `Delete` method that deleted a file, it would be safe if you just viewed it on a page. It would be not safe to script, however, because someone could call the `Delete` method.
49
+
48
50
> [!IMPORTANT]
49
-
> For this tutorial, you can change your security settings in Internet Explorer to run ActiveX controls that are not marked as safe. In Control Panel, click **Internet Properties** and click **Security** to change the appropriate settings. When you have completed the tutorial, change your security settings back to their original state.
50
-
51
-
You can programmatically alert Internet Explorer that it does not need to display the Security Alert dialog box for this particular control. You can do this with the `IObjectSafety` interface, and ATL supplies an implementation of this interface in the class [IObjectSafetyImpl](../atl/reference/iobjectsafetyimpl-class.md). To add the interface to your control, add `IObjectSafetyImpl` to your list of inherited classes and add an entry for it in your COM map.
52
-
53
-
#### To add IObjectSafetyImpl to the control
54
-
55
-
1. Add the following line to the end of the list of inherited classes in PolyCtl.h and add a comma to the previous line:
Build the control. Once the build has finished, open PolyCtl.htm in browser view again. This time, the Web page should be displayed directly without the Safety Alert dialog box. Click inside the polygon; the number of sides increases by one. Click outside the polygon to reduce the number of sides. If you try to reduce the number of sides below three, you will see the error message that you set.
65
-
66
-
[Back to Step 6](../atl/adding-a-property-page-atl-tutorial-part-6.md)
67
-
68
-
## Next Steps
69
-
This concludes the ATL tutorial. For links to more information about ATL, see the [ATL start page](../atl/active-template-library-atl-concepts.md).
> For this tutorial, you can change your security settings in Internet Explorer to run ActiveX controls that are not marked as safe. In Control Panel, click **Internet Properties** and click **Security** to change the appropriate settings. When you have completed the tutorial, change your security settings back to their original state.
52
+
53
+
You can programmatically alert Internet Explorer that it does not need to display the Security Alert dialog box for this particular control. You can do this with the `IObjectSafety` interface, and ATL supplies an implementation of this interface in the class [IObjectSafetyImpl](../atl/reference/iobjectsafetyimpl-class.md). To add the interface to your control, add `IObjectSafetyImpl` to your list of inherited classes and add an entry for it in your COM map.
54
+
55
+
#### To add IObjectSafetyImpl to the control
56
+
57
+
1. Add the following line to the end of the list of inherited classes in PolyCtl.h and add a comma to the previous line:
Build the control. Once the build has finished, open PolyCtl.htm in browser view again. This time, the Web page should be displayed directly without the Safety Alert dialog box. Click inside the polygon; the number of sides increases by one. Click outside the polygon to reduce the number of sides. If you try to reduce the number of sides below three, you will see the error message that you set.
68
+
69
+
[Back to Step 6](../atl/adding-a-property-page-atl-tutorial-part-6.md)
70
+
71
+
## Next Steps
72
+
73
+
This concludes the ATL tutorial. For links to more information about ATL, see the [ATL start page](../atl/active-template-library-atl-concepts.md).
0 commit comments