Robs Programming Junk
Welcome to my programming blog!With some luck you will find some tasty nuggets of information here. If you do find something please post a comment on where or how you used it. I like to see what sort of impact my work has on others.
Friday, December 29, 2006
The Easter Egg
Recently I had a little fun in an application I was developing. I really like the concept of Easter Eggs in software. The one below is interesting in that it pulls the unofficial Dilbert feed and displays it in a picture box. The form that this is on resizes the controls however there is a section of "dead space" where you couldn't reasonably resize a control. I decided to use this space to place a picture box. If you double click the picture box 5 times, it will go to the web and pull the image.
A few notes:
A few notes:
- Don't do this if you're going to get your butt chewed.
- Don't blame me if you do.
- Make sure you encapsulate your code in try blocks and throw out exceptions. Then you don't have to worry about someone inadvertently finding your Easter Egg and pointing out the bug.
- I used the #region preprocessor to hide the code. I used something like EE and then hid it in an obscure place in the code. It's unlikely another developer is going to find it at a later date unless they notice it. Generally if they do they'll leave it there anyhow after laughing at it.
If someone does use this code, I'd REALLY like to know. I had a few laughs putting this in place.
#Region "EE"
' Thanks Duncan! - http://www.duncanmackenzie.net/blog/Reading-An-Image-from-the-web/
Function GetImageFromURL(ByVal url As String) As Byte()
Dim wr As HttpWebRequest = _
DirectCast(WebRequest.Create(url), HttpWebRequest)
Dim wresponse As HttpWebResponse = _
DirectCast(wr.GetResponse, HttpWebResponse)
Dim responseStream As Stream = wresponse.GetResponseStream
Dim br As BinaryReader = New BinaryReader(responseStream)
Dim bytesize As Long = wresponse.ContentLength
Return br.ReadBytes(bytesize)
End Function
Private Sub pbEE_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbEE.DoubleClick
Try
If pbEE.Tag Is Nothing Then
pbEE.Tag = 0
End If
pbEE.Tag += 1
If pbEE.Tag < 5 Then
Exit Sub
End If
If pbEE.Image Is Nothing Then
Dim enc As System.Text.UTF7Encoding
Dim xmlDil As New Xml.XmlDocument
Dim xmlNode As Xml.XmlNode
Dim s As String = System.Text.Encoding.ASCII.GetString(GetImageFromURL("http://feeds.feedburner.com/tapestrydilbert.xml"))
xmlDil.LoadXml(s)
xmlNode = xmlDil.SelectSingleNode("/rss/channel/item/enclosure")
Debug.WriteLine(xmlNode.Attributes.GetNamedItem("url").InnerText)
pbEE.Image = New Bitmap(New IO.MemoryStream(GetImageFromURL(xmlNode.Attributes.GetNamedItem("url").InnerText)))
Else
pbEE.Image = Nothing
pbEE.Refresh()
Dim canvas As Graphics = pbEE.CreateGraphics
canvas.Clear(pbEE.BackColor)
canvas.DrawString("Congratulations, you found the easter egg!", _
New Font("Arial", 12, FontStyle.Bold, GraphicsUnit.Point), _
New SolidBrush(Color.DarkRed), 1, 1)
canvas.DrawString("Software Developers for this application:",_
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.DarkBlue), 1, 40)
canvas.DrawString("Robert Mech, Others...", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.DarkBlue), 1, 53)
canvas.DrawString("Double-Click to get dilbert back.", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.Black), 1, 74)
canvas.DrawString("Move the mouse out of the window to clear this screen.", _
New Font("Microsoft Sans Serif", 8.25, FontStyle.Regular, _
GraphicsUnit.Point), New SolidBrush(Color.Black), 1, 86)
canvas.Dispose()
End If
Catch ex As Exception
Debug.WriteLine(ex)
End Try
End Sub
Private Sub pbEE_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles pbEE.MouseLeave
Try
pbEE.Image = Nothing
Catch ex As Exception
End Try
End Sub
#End Region
View my portfolio at iFreelance.com
Hire MechSoftware for Quality Assurance (QA), Database Programming, and Security Design/Programming
Find QA Freelance Jobs at iFreelance.com
Hire MechSoftware for Quality Assurance (QA), Database Programming, and Security Design/Programming
Find QA Freelance Jobs at iFreelance.com
Recent Posts
Version Checking Class for PAD files.
Quick Test Case
PhotoCopy
Blinky
HARDWARE: Creating My own PVR for HDTV (ATSC) on a...
VFP: User interface not allowed at this time
VFP: Inserting Nodes with XML Object
Linux: Dell Latitude LM, XWindows, Neomagic Magicg...
CIO Blogs - Could "Found Code" Cripple Your Compan...
Links for .NET security info
Archives
01/01/2005 - 02/01/200502/01/2006 - 03/01/2006
03/01/2006 - 04/01/2006
04/01/2006 - 05/01/2006
05/01/2006 - 06/01/2006
09/01/2006 - 10/01/2006
10/01/2006 - 11/01/2006
11/01/2006 - 12/01/2006
12/01/2006 - 01/01/2007
04/01/2007 - 05/01/2007
05/01/2007 - 06/01/2007
01/01/2008 - 02/01/2008
02/01/2008 - 03/01/2008
05/01/2008 - 06/01/2008
06/01/2008 - 07/01/2008
08/01/2008 - 09/01/2008
09/01/2008 - 10/01/2008
11/01/2008 - 12/01/2008
12/01/2008 - 01/01/2009
01/01/2009 - 02/01/2009
02/01/2009 - 03/01/2009
04/01/2009 - 05/01/2009
05/01/2009 - 06/01/2009
07/01/2009 - 08/01/2009
01/01/2010 - 02/01/2010
My Software
Blinky - GBPVR PluginPhotoCopy - GBPVR Plugin
QTC - Quick Test Case
rBoop - Rob's Timers
Programming Links
C# FormatterNSIS
Other Links
Damn Small LinuxSites I Manage
Do it yourself SEO. Cheap.Pet Supplies
Dog toy of the month club
SqueakerZ pet Deals
Geocaching Community
Hitch hiker Tracking