Skip to content

Planet-Source-Code/thomas-swift-vb6-embedded-resource-templates-for-dummies__1-70508

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

VB6 Embedded Resource Templates For Dummies

Description

An explanation of windows resource templates.

More Info

Submitted On 2008-05-09 22:52:38
By Thomas Swift
Level Intermediate
User Rating 5.0 (15 globes from 3 users)
Compatibility VB 6.0
Category String Manipulation
World Visual Basic
Archive File VB6_Embedd2112375102008.zip

Source Code

VB6 Embedded Resource Templates For Dummies

Ever look at Microsoft's Picture and Fax viewer control and wonder just how they pulled it off ?
Well then your reading the right document !


First off their are a lot of ways you can pull off a image presentation from the depths of source code. The hardest way is to do it programicly considering how hard it is to binary decode files. Especially gif's. When you look at a directory thru windows file explorer all your doing is viewing it thru a template driven and scripted web browser control. In fact even your desktop is a heavily scripted web browser control believe it or not. If you don't believe me just point eather the VB web browser control or a sub classed copy of internet explorer at a file directory and you will find out what I mean. Even the explorer right click menu comes into view on right click and you can have iconic view.

A closer look at the file that houses the Microsoft Picture viewer using Resource Hacker and behold what do you find but a HTML template with insert code here variables all over the place. They pulled the same thing off in their Web Photo Album Generator on the Windows 98 CD. In fact if you look closely at a lot of the Windows operating system you will find embedded templates being used all over the place. Some like the Web Photo Album Generator even use embedded cascading style sheets or CSS for short.

Well I promised to teach you just how they are pulling this off. Well in the VB6 GUI you have the VB Resource Editor on your toolbar. In the resource editor you have 5 types of resources you can add to an embedded resource file. The one furthest to the right is Custom. Using the custom resource type you can add literally anything to your project. Once you have chosen and added your particular resource it assigns each one an index number. Numbers 101, 102, 103 on to infinity. This is how you store your HTML templates in your final program.

Now that you know how to store a template you need to know how to get it out and view it. Well lets look at some simple code to extract a custom string resource and view it.

<textarea rows="24" cols="78" name="Code">Input: LoadQuickFeed 101, "http://www.sfgate.com/rss/feeds/bondage.xml" Public Function LoadQuickFeed(DataIndex As Integer, FeedURL As String) Dim myArray As String Dim TheFile As Integer WebBrowser1.Visible = True myArray = ByteArrayToString(LoadResData(DataIndex, "CUSTOM")) myArray = Replace(myArray, "<<--URL-HERE-->>", FeedURL) TheFile = FreeFile() Open App.Path & "\temp.htm" For Output As #TheFile Print #TheFile, myArray Close #TheFile WebBrowser1.Navigate2 App.Path & "\temp.htm" End Function Private Function ByteArrayToString(bytArray() As Byte) As String Dim sAns As String Dim iPos As String sAns = StrConv(bytArray, vbUnicode) iPos = InStr(sAns, Chr(0)) If iPos > 0 Then sAns = Left(sAns, iPos - 1) ByteArrayToString = sAns End Function </textarea>

In the code above I have a previously coded template embedded in my project as resource 101 written in Java Script AJAX to display the RSS feed URL passed in the FeedURL variable. The template has the <<--URL-HERE-->> written in the place of the feed URL in it. I did that by editing the HTML file with a text editor like Note Tab Pro after creating it in Front Page and the Windows Scripting Editor.
The code simply replaces the <<--URL-HERE-->> with what ever feed URL I want to view when its loaded. Presto I have a totally versatile way of loading RSS feeds.

Well now that you know the secret the variables are should we say the sky is the limit ! Have fun expanding on this basic shell concept created by Microsoft eons ago ! Enjoy !!!

The accompanying download contains same tutorial, but includes the HTML template source example as well.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published