This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.


MIND


GEEK

Robert Hess

GEEK I've discovered a very perplexing problem. Certain Web-safe colors (for example, #CC9966) dither only when viewed in "thousands" (not sure if it's 15 or 16-bit at this point) of colors. The problem occurs under both PCs and Macs as well as Microsoft Internet Explorer and Netscape Navigator.
      I understand that there is some kind of a math problem concerning rounding with colors under 16-bit. Do you know anything about this issue?

GEEK The problem here is a little complex, and has to do with the granularity of a 5-bit intensity value as compared with an 8-bit intensity value. A 5-bit integer can range from 0 to 31. An 8-bit integer can range from 0 to 255. In both situations, 0% is the lowest possible value (0) and 100% is the highest possible value (31 or 255).
      So a non-dithering situation will arise when an 8-bit and 5-bit integer can both exactly describe the same percentage value. By definition, this will at least include 0% and 100%. The question is if it contains any other values between those ranges.
      For example, as an 8-bit value, the number 51 translates exactly to a 20% intensity. But in a 5-bit value, you can't represent 20% exactly— 6 is 19.35%, and 7 is 22.58%. Therefore, any 8-bit color value that uses 51 as one of the RGB components will dither when converted to 5-bit color. If you take the time to calculate all the values, you'll see that the two don't have any values other then 0% and 100% in common; therefore, the only colors that won't dither are the ones that use just #00 or #FF for all of their color components.
      This dithering will only happen in solid background colors (for example, <td bgcolor="#CC9966">). Use of the Safety Palette colors in images will give you the solid color closest to the one requested.

GEEK I'm using Internet Explorer 4.01 and IIS 4.0 (running Active Server Pages) with a Verisign Digital certificate. With unsecured (HTTP) pages, forward and backward navigation works fine, and pages are repopulated when you navigate back to them. My problem occurs with secured (HTTPS) pages. If I go to a page and enter information, navigate forward, and then back—the navigation back is the result of server-side validation—the information is not reloaded. According to Microsoft's Knowledge Base article http://support.microsoft.com/support/kb/articles/q174/5/50.asp, this behavior is by design. Is there a Microsoft-prescribed way to repopulate a form after it has been submitted like this, without using cookies?
GEEK At first, this might not seem like a security issue, but it is. HTTPS is meant for when you want to transmit secure data to a Web server. This usually means that the form is requesting information that the user really doesn't want anybody else to see.
      Suppose you fill out a form with your social security number, your credit card number, or some other piece of important information. You submit the form, and the Web site responds with a "submission complete" page. You get up from your desk, and walk down the hall to get a cup of coffee. Somebody comes into your office, and clicks the Back button on your browser window. What do you think they see? Maybe this isn't a big deal in your situation, but it is a potential security problem, and therefore needs to be dealt with in this matter.

GEEK I have several database connections running through ASPs for viewing them, updating them, and so on. Some tables include pictures, but I can't seem to get an ASP to show them. The pictures are .bmps and only show up as binary streams. Any suggestions?
GEEK You didn't mention what database you are using, or what datatype you're storing your images as, so I will just assume you are using Microsoft® Access. Microsoft Access provides a very handy OLE Object database type that you can use for storing images (or virtually anything) in your database, and making it visible via an application you write.
      Unfortunately, the OLE Object datatype presents some difficulties when you want to publish the information it contains on a Web site. The data that gets stored into this object is essentially a black box; Microsoft Access simply sees it as a mass of bits with an OLE header. When it wants to do something with this object, it passes it on to the OLE services running on the system. So even though the bits within this field might represent an image, they aren't really directly accessible at the same level you are accessing the data via your ASP code.
      What you are trying to do is both reasonable and achievable, and in fact one of the questions I'm asked fairly often. What you need is an OLE Image Decoder running on the same server as your ASP. When your ASP code retrieves an OLE Object field, it passes this data stream on to the OLE Image Decoder, which in turn takes the data and passes it on to the OLE services, along with an appropriate display context to be used for rendering the image. The OLE Image Decoder would then snapshot the display context, save it as a temporary GIF, JPEG, PNG (or whatever) file, and return to your ASP code either the name of this file or perhaps a MIME-encoded data stream that could be rendered straight to the response stream.
      Unfortunately, I am not aware of any existing OLE Image Decoders. But that's assuming you're using Microsoft Access. If you are using SQL Server, then the solution is actually a lot easier. SQL allows an image datatype, which is essentially a binary data blob of information. You can store graphic images into this.
      Let's assume you have a SQL database referenced within your global.asa via Image_DB_ConnectionString with a table named Images, an ID field named Image_ID, a field named ImageBlob of type image, and a field named mimeType that contains the MIME descriptor (for example, "image/JPEG"). Then you could use this line


 <html><body><img src="imageBlob.asp?id=1"></body></html>
to extract an image from that database. imageBlob.asp would look like Figure 1.

GEEK I can create text in an Internet Explorer 4.0 ListView control and work with it like a grid. I'd like to use images in it as well. In Visual C++®, when I call function the Add function, all five parameters are VARIANT. How can I use this parameter to describe a small or large icon?
GEEK One of the new extended styles for the ListView control is LVS_EX_SUBITEMIMAGE. As long as your ListView control is in LVS_REPORT mode, and you have an image list associated with the control, then you can use the ListView_ SetItem macro to specify the images to display, or you can send the LVM_SETITEM message directly to the control.

GEEK With Dynamic HTML (DHTML), I can catch when the user moves the mouse over any HTML tags. Can I determine when the mouse is down or up?
GEEK When capturing mouse up/down aspects within DHTML, a wide variety of events allow you to deal with mouse interaction on virtually any item of the page. onclick, ondblclick, ondragstart, onmousedown, onmousemove, onmouseout, onmouseover, onmouseup are events associated with various mouse interactions. You can also use event.button to find out the mouse button (if any) that was pressed to fire the event. This allows you to not only do something with the onmousedown event, but also to find out which button the user pressed.

GEEK Microsoft uses a pull-down menu interface at http://home.microsoft.com that is pretty slick. I've never done Java or JavaScript before, but I'm wondering if there is some control or sample code that I can use to mimic this on an internal company site.
GEEK The dropdown menus on the top of the http://home.microsoft.com page are coming from DHTML. When an onmouseover event is trapped, a previously hidden <span> is displayed, which has the menu items on it. While I don't have enough space to go into all the details on how this is done on this page, perhaps I can get you far enough along that you can experiment on your own.
      If you do a View Source on that page, you won't find the code for these menus. But since the menu bar appears at the very top of the page, looking for the <body> tag is a good start. Right under this, you will see:


 <script language="JavaScript" src="/global/dhtmlToolbar.INC"></script>
This includes an external source file that just contains script code. So if you had gone to http://msn.microsoft.com/global/dhtmlToolbar.INC, what you would have seen is the JScript™ code that displays the toolbar. This allows the same toolbar to be easily put onto the top of every page on this site. From there, the code is relatively simple. Each top-level menu option assigns a mouseover event to display a particular named menu. There are essentially three key functions. doMenu determines if a new menu should be displayed (in which case it will hide any current menu, and start displaying the new one); it also calculates where to display the menu. showMenu is an interval function started up by doMenu; it will progressively open up the menu until it is fully displayed. hideMenu hides the currently displayed menu. There are a few other things being done in this little source file, but you should be able to take it from here.


From the June 1998 issue of Microsoft Interactive Developer.