Click to return to the Essentials home page    
Web Workshop  |  Essentials

A Contest of Sorts


Rafael M. Muñoz
Tom Moran
Microsoft Corporation

May 3, 1999

The following article was originally published in the Site Builder Magazine (now known as MSDN Online Voices) "Web Men Talking" column.

Contents
A contest of sorts
You will take notes - Preventing someone from printing your Web page
Where there's a will, there's a display - Displaying hidden DHTML over windowed controls
Are you asking us for a date? - Changing and storing your dates.

Spring is the time when everyone's fancy turns to poetry. Join the Web Men as they discuss printer controls, windowed controls, and the rigors of literary form.

A contest of sorts

Every writer wants to contribute something to the literary annals. Sure, this tech stuff is great, but to command the eloquent prose of an Elliott, Parker, or Browning -- that would be a true achievement. So we struggled to reach deep within our souls, to find our innermost thoughts and feelings, to somehow express the depth of our emotion and communicate our true humanity to you, the readers.

And we came up with the following computer haikus Non-MS link:


Tom and Raf do love

Learning Web technology

Their pathetic lives

Waiting patiently

The Microsoft announcement

A timely release?

Tangled sentences

Becoming easily read

Our editor rocks

MSDN is

Developer Xanadu

A font of knowledge

If you can do better (and, really, we can't possibly imagine it would be difficult), send them our way. We'll share a few of the best, and maybe even send out a T-shirt or two -- or some of that infamous free Mountain Dew -- for the best entries. Remember, a haiku is generally considered to be 5-7-5 syllables, but that isn't a strict rule. Now, let's answer your questions.

TopBack to top

You will take notes!

Dear Web Men:

I work for a small community college and am currently developing a Web site for one of the professors here. The pages are slick and look great, thanks largely to your tips and advice that I read here. Here, however, is my problem. He wants his students to be able to see the pages, obviously, but he does not want them to be able to print them in order to encourage note-taking in class. Is there a tag or script that would perform this task -- can I somehow turn off the browser's printing function?

Bryan Brayton

The Web Men reply:

This simply isn't the way of the Web -- turning things off in the client just isn't done. So as far as we know, there is no way to temporarily turn off printing in a client's browser. However, there are several techniques you can use to discourage people from printing something. We'll quickly outline a few that may meet your needs, depending on how badly you want to do this.

One potentially clever way to do it (assuming that you are comfortable with handling DHTML events, you are using Internet Explorer 4.0 or later, and your document is laid out correctly on the Web) is to handle the onbeforeprint and onafterprint events. The basic idea is to handle the onbeforeprint() event, collapse everything so that it is hidden, and then handle the onafterprint() event to expand it all so it is readable again. The intention of the event is really to give the Web author the ability to make things visible (such as expanding an online book chapter, for example) before it gets printed. But with a little imagination and some work, there is no reason it can't be used for the opposite purpose -- to hide something before printing.

If you have complete control of the client browser used, you can potentially build your own browser using Visual Basic and the WebBrowser control. A couple pointers to do this are How To: Use the WebBrowser Control from Visual Basic 5.0 Non-MSDN Online link and Reusing Internet Explorer and the WebBrowser Control: An Array of Options. Then you can pretty much do anything you want.

However, all that said, the easiest way we found to accomplish what you want to do is to use Adobe Acrobat 4.0. You can convert a file to PDF using Adobe Acrobat, and turn off the ability of the reader to print. This is about as close as you can get in a public environment and would prevent most people from printing a usable copy of your information.

There is really no convenient way to prevent someone from simply using Alt-PrintScreen to get a bitmap, unless you have the ability to remove all the printers from the room. But even then, somebody could probably send mail to another account, and still get around it. Locking somebody out from printing is a difficult proposition at best, unless you have a completely secure environment.

And finally, Mead and Company Non-MS link has a control called ScriptX, which is available for free from their Web site. It does some interesting things with printing, including modification of print settings, and is definitely worth a look if you are going to be working much with printing.

TopBack to top

Where there's a will, there's a display

Dear Web Men:

I use pop-up menus on my site. The problem is that whenever there is a list box or combo box located where the pop-up menu is shown, the pop-up menu is behind the box. Changing the z-order does not help me. Is there something obvious I am missing here?

Joseph E. Shook

The Web Men reply:

Joseph, it's not often that we re-visit a question unless we've made a mistake, and that only happened once (though it turned out we were mistaken). But where there is a will, there is a display!

Are you missing something obvious? No. As we pointed out last December in They just don't mix, when you are playing with windowed controls such as the list box, the zOrder property cannot be used. For more information on this topic, see the Microsoft Knowledge Base article Q177378, PRB: zOrder Property Cannot Be Set On Windowed Controls Non-MSDN Online link.

But hey, the keen eye is always on the lookout. A few months ago when the Microsoft home page Non-MSDN Online link was redesigned, we noticed something. In the upper left-hand corner there is a drop-down list box -- and just above it, you'll see the "Home" and "Events & Training" drop-down menu items. If you watch closely, you'll notice that through the marvels of DHTML, both the control and menu items live in harmony.

Not exactly at the same time, but that's where the trick comes in.

Hide it! If that windowed control is bothering you, just hide it at the same time you display the drop-down menu. Below, we have put together a small test that you can run and see exactly what we are talking about.


<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>Drop Down Menu Test</TITLE>
</HEAD>
<script language=javascript>
function menu_mouseover()
{

   submenu1.style.visibility="";
   /* uncomment the following line to hide the control
   */
//   select1.style.visibility="hidden";
}
function menu_mouseout()
{
submenu1.style.visibility="hidden";
/* uncomment the following line to display the control
 */
//   select1.style.visibility="";
}
</script>
<BODY>
<DIV id=menu1 
style="BACKGROUND-COLOR: 
blue; COLOR: white; WIDTH: 90px" onmouseover=menu_mouseover() onmouseout=menu_mouseout()>
Menu Item 1</DIV>
<P>
<SELECT id=select1 name=select1>
<OPTION selected>select 1</OPTION>        
<OPTION>select 2</OPTION>        
<OPTION>select 3</OPTION>
</SELECT>
</P>
<DIV id=submenu1
   style="BACKGROUND-COLOR: blue; COLOR: white; LEFT: 10px; POSITION: absolute; TOP: 34px; VISIBILITY: hidden; WIDTH: 90px">
This is where we display the submenu associated with this menu item.</DIV>
</BODY>
</HTML>

What we have is a simple sample that displays what could be a drop-down menu and a control beneath it. The current sample shows what you are seeing, Joseph, when you mouse over the menu item: The drop down is displayed behind the control. Now, simply uncomment the lines specified in the script section. These two lines use the visibility property to create the magic. Each time we display the drop-down menu, we change the visibility to hide the control; when we hide the drop-down menu, we in turn re-display the control. Enjoy.

TopBack to top

Are you asking us for a date?

Dear Web Men:

I have a date on a form that is entered in MM/DD/YY format. I would like to know how to change that to a 4-digit year.

Jerry Thompson

The Web Men reply:

This is not as simple as it might appear, especially since you didn't provide a lot of background on what you are really trying to do. At first, we had written a nice little sample to show you how to convert your date, validate it, and present it for user verification. However, to quote the Genie in Disney's Aladdin - "There are a few, uh, provisos, ah, a couple a quid pro quos..." This is dangerous Y2K territory, and you need to show due diligence in understanding how to work with dates by visiting (and reading!) the links we give you below. Making a few assumptions about what you want to accomplish, the basic flow of what you need to do is this:

As we pointed out above, this can get fairly complex -- in fact, there are hundreds of pages written on the subject on Microsoft's Y2K Web siteNon-MSDN Online link. If this were an easy problem to solve, we wouldn't have bought that compound in Eastern Washington. Note, however, that we also purchased a solar collector, so that even in the face of the collapse of civilization, Web Men Talking will still be here to answer your questions. Anyway, if you all check out the following articles, maybe we won't have to move:

The Automation Libraries and the Year 2000 Non-MSDN Online link

Building Year-2000 Compliant Applications with Visual Studio and Windows DNA Non-MSDN Online link

Microsoft Script Engines and the Year 2000

TopBack to top

Shorts:

Q. Richard Glasberg is having problems with the following line of code not producing a node in his TreeView Control:

   Set nodX = TreeView1.Nodes.Add("R", tvwChild,"C1","Child 1")

A. The constant value of twvChild for a TreeView Control is 4, but if you didn't define this constant in your VBScript its value will be 0, which represents the "First Sibling". Refer to the TreeView Control Constants for more information.

Q. Crash wants to know how to programmatically set Internet Explorer to full-screen mode.

A. Look in the Reusing Browser Technology of the Web Workshop, and pay special attention when you see the put_FullScreen method.

Q. Micky McQuade is having trouble setting page breaks in a document.

A. Assuming you have a couple heading lines, the following script should work.

<STYLE>
H3 { page-break-after: always }
</STYLE>

For more information, check out the Style Sheets and Printing section of the Web Workshop.

Q. Penny Benson is wondering if she'll have to manually create accounts for all of her students.

A. Not anymore. Refer to the User Wizard for Windows NT Non-MSDN Online link, the School Web Non-MSDN Online link, and Jeff Sandquist's recent articles on Creating a Virtual Directory.

Q. Andrew Johnson is experiencing some printing problems with his Java applets.

A. Various printing problems existed with old versions of the Microsoft Virtual Machine; try upgrading to the latest version.

Q. Shawn Palmer would like to know what the benefits are of using a DSN-less connection.

A. They are easy and portable in case you change servers and are customizable within your script. The only drawbacks are that you'll incur a small performance penalty, and that changing the database requires changing the connection. If you are using a control, you'll have to recompile and distribute.

Q. Thomas Gallagher wants to know how to run an HTML Application in full screen mode.

A. Note that HTML Applications are new to Internet Explorer 5 only; refer to the WINDOWSTATE attribute of the HTA:APPLLICATION element for information on creating a full screen application.

Q. Henrik Niemann is trying to place the DateTimePicker Control directly on a Web page, but the control doesn't display on some machines.

A. The DateTimePicker Control is a licensed control and requires a license package file. Refer to the Microsoft Knowledge Base article Q159923, HOWTO: Using Licensed ActiveX Controls in Internet Explorer Non-MSDN Online link.

TopBack to top

Rafael M. Muñoz, when not playing or coaching his favorite pastime (volleyball), provides technical assistance as a full-time developer support engineer for Microsoft Developer Support.

Thomas Moran, when not struggling to maintain some semblance of sanity (working with Rafael certainly doesn't help), toils with a prodigious team that creates articles and other content from Microsoft's Developer Support.



Back to topBack to top

Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.