RSS Feed Reader (*Special thanks to Fox for giving me the idea to do this.)
**********************************************************
Difficulty (3/5 involves a lot of things outside of just copying and pasting code)An RSS Feed reader allows players to look at the news that gets updated on your website without having to open up the browser, and can be pointed at any feed you wish. A lot of games, such as Guild Wars and World of Warcraft, have implemented a feed reader into the main menu of the clients while waiting for things to load.
Be warned though, this Feature requires that you have a few things set up. first you need a website, and then you need some sort of feed generator on your website. Most CRM's (such as Joomla, Mambo, phpnuke, wordpress, etc.) have built in feed readers or can have a reader installed via a module or component. Any custom designed html site likewise can use a php, java, or ajax script to create an rss feed, though I know a little less about these.
Once you have an RSS feed you obviously need the news posts to generate content for the feed. Once you have all that, the feed will create an RSS friendly xml page that can be read by a feed reader. This xml page is the reason you can't just put a web control on your game and point it to the RSS feed. It will come back very strange looking, as a web rendering engine doesn't normally handle xml. so you need some code that will
parse the xml into an html readable page.
With that said this tutorial will have you create a couple files along with the code. first you need an rss.htm, a default.css (this is a cascading stylesheet to make it easier to format your feed to make it fit your game), and an rss.xsl. I will provide the code and a download of the files to make it easier for everyone.
The rss.htm is created dynamically every time the code launches, so just make a blank file and that will be good.
Code for default.cssCode:
body {
font-family: Arial,sans-serif,verdana;
margin:10px 0 10px 0;
background-color: #FFFFFF;
}
h1{font-size:14px;}
.tubuh{margin:5px;}
p,span,.deskripsi,.properti{font-weight:normal,}
p,span,.deskripsi,div{font-size:12px;text-align:justify;}
.properti{font-size:10px;color:#ffffff;}
Code for rss.xslCode:
<?xml version="1.0" ?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:atom="http://purl.org/atom/ns#"
exclude-result-prefixes="atom" >
<xsl:output indent="yes" method="xml" encoding="UTF-8" />
<xsl:template match="//atom:feed">
<rss version="2.0">
<channel>
<title><xsl:value-of select="atom:title"/></title>
<link><xsl:value-of select="atom:link[@rel='alternate']/@href"/></link>
<description><xsl:value-of select="atom:tagline"/></description>
<generator><xsl:value-of select="atom:generator"/> <xsl:value-of select="atom:generator/@version" /></generator>
</channel>
<xsl:call-template name="items"/>
</rss>
</xsl:template>
<xsl:template name="items">
<xsl:for-each select="atom:entry">
<item>
<title><xsl:value-of select="atom:title"/></title>
<link><xsl:value-of select="atom:link"/><xsl:value-of select="atom:link[@rel='alternate']/@href"/></link>
<description><xsl:value-of select="atom:description"/><xsl:value-of select="atom:summary" /><xsl:value-of select="atom:content"/></description>
<pubDate><xsl:value-of select="atom:pubDate"/><xsl:value-of select="atom:issued"/></pubDate>
</item>
</xsl:for-each>
</xsl:template>
<xsl:template match="/rss/channel">
<rss version="2.0">
<channel>
<title><xsl:value-of select="title"/></title>
<link><xsl:value-of select="link"/></link>
<description><xsl:value-of select="description"/></description>
<generator><xsl:value-of select="generator"/></generator>
</channel>
<xsl:call-template name="itemsc"/>
</rss>
</xsl:template>
<xsl:template name="itemsc">
<xsl:for-each select="item">
<item>
<title><xsl:value-of select="title"/></title>
<link><xsl:value-of select="link"/></link>
<description><xsl:value-of select="description"/></description>
<pubDate><xsl:value-of select="pubDate"/></pubDate>
</item>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Once you have these three files you can open up your code and open up the form where you wish to place the RSS feed. I opted to place it in frmMainMenu, but you can put it anywhere. Now you need to add a component for the web browser.
For this you have a few choices. If you choose to use IE7 you need to browse to the C:\WINDOWS\system32\ folder and find shdocvw.dll which will replace ieframe.dll for Microsoft Internet Controls. If you use IE6 you just use ieframe.dll. If you wish to use the gecko rendering engine (what Firefox uses) then head over to
http://www.iol.ie/~locka/mozilla/mozilla.htm and download the latest activeX object. it will function exactly as MIC will, only with a different rendering engine.
A note on the Mozilla control however, I saw that it caused VB6 to error out when attempting to click a link from the feed, so I ended up using MIC. if anyone can find the problem, let me know.
Create a web browser box using the control you just enabled and name it wb. Disable any toolbars you don't want showing up. Once you have that all done go to
Private Sub Form_Load() and paste the following:
Code:
Dim strurl As String, NamaFile As String, DataRss As String, strChannelTitle As String
Dim strChannelDescription As String, strChannelLink As String, strChannelImageTitle As String
Dim strChannelImageUrl As String, strChannelImageLink As String, strChannelImageWidth As String
Dim strChannelImageHeight As String, strItemTitle As String, strItemLink As String
Dim strItemDescription As String, strItemcontent As String, strItempubDate As String
Dim arrItemTitle() As String, arrItemLink() As String, arrItemDescription() As String
Dim A As Integer
Dim Title As String
strurl = "http://yourgame.com"
Dim objXML, objXSL, objOutputXMLDoc, channelNodes, entry, images, itemNodes, Item
NamaFile = App.Path & "\rss.htm"
Open NamaFile For Output As #1
Print #1, "<html>"
Print #1, "<head>"
Print #1, "<title>Extreme RSS</title>"
Print #1, "<link rel=""stylesheet"" href=""default.css"" type=""Text/css"" />"
Print #1, "</style></head>"
Print #1, "<body>"
Print #1, "<div class=""tubuh"">"
If strurl <> "" Then
If Left(strurl, 7) = "http://" Then strurl = Right(strurl, Len(strurl) - 7)
strurl = "http://" & strurl
Set objXML = CreateObject("MSXML2.DOMDocument")
Set objXSL = CreateObject("MSXML2.DOMDocument")
objXML.async = False
objXSL.async = False
objXML.SetProperty "ServerHTTPRequest", True
If objXML.Load(strurl) Then
objXSL.Load App.Path & ("\rss.xsl")
DataRss = objXML.transformNode(objXSL)
Else
Print #1, " Error: " & objXML.parseError.reason & "<br />"
End If
Set objXML = Nothing
Set objXSL = Nothing
Set objOutputXMLDoc = CreateObject("MSXML2.DOMDocument")
objOutputXMLDoc.loadXML DataRss
If (objOutputXMLDoc.parseError.errorCode <> 0) Then
Print #1, " XML error: " & objOutputXMLDoc.parseError.reason
Else
Set channelNodes = objOutputXMLDoc.selectNodes("//channel/*")
For Each entry In channelNodes
If entry.tagName = "title" Then
strChannelTitle = entry.Text
ElseIf entry.tagName = "description" Then
strChannelDescription = entry.Text
ElseIf entry.tagName = "link" Then
strChannelLink = entry.Text
End If
Next
Set channelNodes = objOutputXMLDoc.selectNodes("//image/*")
For Each images In channelNodes
If images.tagName = "title" Then
strChannelImageTitle = images.Text
ElseIf images.tagName = "url" Then
strChannelImageUrl = images.Text
ElseIf images.tagName = "link" Then
strChannelImageLink = images.Text
ElseIf images.tagName = "width" Then
strChannelImageWidth = images.Text
ElseIf images.tagName = "height" Then
strChannelImageHeight = images.Text
End If
Next
Print #1, "<h1>" & strChannelTitle & "</h1>"
If strChannelImageUrl <> "" Then
Print #1, "<img align=""left"" vspace=""10"" hspace=""10"" title="" & strChannelImageTitle & "" src="" & strChannelImageUrl & "" width="" & strChannelImageWidth & "" height="" & strChannelImageHeigh & "" alt="" & strChannelImageTitlee & "" />"
End If
Print #1, "<span>" & strChannelDescription; 7; "</span><br />"
Print #1, "<span class=""properti""><a href="" & strChannelLink & "">" & strChannelTitle & "</a></span>"
Print #1, "<hr>"
Set itemNodes = objOutputXMLDoc.selectNodes("//item/*")
For Each Item In itemNodes
If Item.tagName = "title" Then
strItemTitle = strItemTitle & Item.Text & "#%#"
ElseIf Item.tagName = "link" Then
strItemLink = strItemLink & Item.Text & "#%#"
ElseIf Item.tagName = "description" Then
strItemDescription = strItemDescription & Item.Text & "#%#"
ElseIf Item.tagName = "content" Then
strItemcontent = strItemcontent & Item.Text & "#%#"
ElseIf Item.tagName = "pubDate" Then
strItempubDate = strItempubDate & Item.Text & "#%#"
End If
Next
arrItemTitle = Split(strItemTitle, "#%#")
arrItemLink = Split(strItemLink, "#%#")
arrItemDescription = Split(strItemDescription, "#%#")
If UBound(arrItemTitle) = UBound(arrItemLink) And UBound(arrItemLink) = UBound(arrItemDescription) Then
For A = 0 To UBound(arrItemTitle) - 1
strItemLink = arrItemLink(A)
strItemTitle = arrItemTitle(A)
strItemDescription = arrItemDescription(A)
If strItemLink <> "" Then
Title = "<a target=""_blank"" title= """ & strItemTitle & """ href=""" & strItemLink & """ >" & strItemTitle & "</a><br>" & vbCrLf
Else
Title = strItemTitle & "<br>" & vbCrLf
End If
Print #1, "<h1>" & Title & "</h1>"
Print #1, "<div class=""deskripsi"">" & strItemDescription & "</div><br />"
Print #1, "<span class=""properti"">" & Left(Replace(strItemLink, "http://", "", 1, -1, 1), 25) & "</span><br />"
Next
End If
End If
Else
Print #1, "<h1>Your game name here</h1>"
End If
Print #1, "</div>"
Print #1, "</body>"
Print #1, "</html>"
Close #1
wb.Navigate NamaFile
This is the code that will parse the xml into the rss.htm and then point the browser control at it. Be sure to replace the contents of strurl with your own for your rss feed.
This will give you a basic white background black lettering RSS feed, and you can change this very simply by changing the default.css file. Now the only thing you have to do is learn a little CSS

P.S. I downloaded the xml parsing code from Bowo Ekowidodo at pscode.com. It was in pretty rough shape, he didn't use Option Explicit so I had to change a whole crap ton of it to get it to work in standard VB6 language. But I thought I should include my sources.