Click here to Skip to main content
6,291,522 members and growing! (16,594 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » Applications     Intermediate

CHMReader.Net

By Peter Tewkesbury

This is a new '.NET' version of my CHMReader program, with more features.
C#, Windows, .NET CF, .NET, MobileVS.NET2003, Dev
Posted:23 May 2004
Updated:15 Aug 2004
Views:161,987
Bookmarked:64 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
33 votes for this article.
Popularity: 5.81 Rating: 3.83 out of 5
6 votes, 18.2%
1
1 vote, 3.0%
2
2 votes, 6.1%
3
8 votes, 24.2%
4
16 votes, 48.5%
5

Sample Image - chmreader007.jpg

Introduction

In my first article for �The Code Project� I developed a program to view CHM files on a Pocket PC 2003 (Using embedded Visual C++) using the open source CHMLib. This version had a number of issues, so I decided to write a C# version, and here it is.

Sample screenshot

Features

  • Contents Tree
  • Index List with Also See jumping.
  • Search
  • Uses Regular expressions to patch the HTML code extracted from the CHM
  • Handles CHM files which point to other CHM Files (CHM Book Shelf. E.g. MCSD NetCore.chm)Handles navigation to Anchor points
  • Full C# Source included

Sample screenshot

The New Code

The new version of the CHMReader.Net uses the following libraries

A Big thank you to these guys for releasing there code so we can all benefit from it. Thanks.

There are a number of points to make here concerning the porting of the CHMLib. Firstly, when porting LZW decompression code, I had to first compile the code in �C� and get the pre-processor to export the source sent to the compiler. This is because the original code used a lot of macros which made it very difficult to see how to port come sections of the code. Once I had this source I could port the code to C#. I had to convert all the buffer accesses to use .Net Streams, along with the code which read buffers. This included creating special classes with hold the data from the internal structures of the CHM File Stream, and manually reading the data from the CHM file into the data members of the class. (Using BinaryReader.ReadUInt16 etc).

Once I had a version which compiled in C#, I then had to test that the code worked. This was a case of running both versions of the library side by side in 2 instances of Visual Studio 2003 and extracting files from the same CHM file, making source that the output was the same.

Once done, I replaced the base stream handling used by the HTML Help library with the ported library, and then had a working CHM Reader which could extract files, extract help indexes & perform searches using the HTML Help library.

Sample screenshot

The CHMReader

Now that I had the basics working, I then when on to develop the Reader it�s self. Once you have the filename of the page you want to display (From the Index, Contents or search) you can then extract that file from the CHM file. This file then as to be scanned, and the images, frame pages & Style Sheets used by the HTML page need to be extracted, and the HTML patched so that they point to the new location of the files. In this case a temp directory in the filing system. Also at this point I remove XML and Script tags as they are not supported. Once this is done I can then save the file, and use the OpenNetCF library�s HTML Viewer control to view the page as intended.

There is more to it that what I have described, so look that the code. The code is not optimized as yet. This is some that may or may not get done depending on time.

If you can not read a CHM File, please debug the code and post any changes, If you really can not get the CHM file to view, then please email me with the CHM file.

I hope you enjoy this version.

History

V2.0.0 Initial Release
V2.0.1 - 27 May 2004
  • Bug Fixes to LZW Decompression
  • Added icon to file
  • Added Command line parameter
  • Added File Association with CHM files (After first run)
  • Created installer
V2.0.3 - 12 July 2004
  • Minor bug fixes.
  • New File Open Dialog to allow browsing of complete file system
V2.0.5 - 14 July 2004
  • HTML Help Library updates included (Orignal code by Klaus Weisser � See //www.codeproject.com/csharp/HtmlHelp.asp)

  • CHMLib 0.35 updates ported to my C# version (Original C++ library, CHMLib, by Jed Wing.)

  • Added a option to allow user to save CHB files - A CHB file is a file which contains the internal data structures which are created when a CHM file is loaded. This option allows this data to be saved to a CHB file. This file can then be loaded next time the same CHM file loaded, and a lot of processing can be avoided. This functionally is thanks to Klaus Weisser. You can also use Klaus Weisser's HtmlHelp viewer to create the CHB files(They need to be renamed from <chmfile.chm.bin> to <chmfile>.CHB and stored in the same directory as the CHM file on the Pocket PC.

  • Minor UI enhancements.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Peter Tewkesbury


Member
Hi, I am a developer working in Cheshire, England. I started programming on a Vic-20 back in the 80's with only 5K of ram), and I have not looked back since. I currently develop in Visual C/C++, C#/.NET, MFC, ATL & ASP.NET, SQL Server, Crystal Reports, DevX, WinForms.
Occupation: Software Developer
Location: United Kingdom United Kingdom

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 163 (Total in Forum: 163) (Refresh)FirstPrevNext
GeneralPorted to Windows Mobile Smartphone Edition Pinmemberbuaa_aladdin4:36 8 Jun '08  
NewsI can run it! PinmemberJackey_shao17:00 10 Aug '07  
QuestionHow abtain CHMLib lib? PinmemberJackey_shao1:30 9 Aug '07  
QuestionRe: How abtain CHMLib lib? PinmemberJackey_shao15:28 9 Aug '07  
GeneralPublish just the custom open file dialog Pinmemberrudiman7:44 19 Oct '06  
GeneralRe: Publish just the custom open file dialog PinmemberPeter Tewkesbury22:30 19 Oct '06  
GeneralRe: Publish just the custom open file dialog PinmemberJackey_shao22:48 8 Aug '07  
GeneralRe: Publish just the custom open file dialog PinmemberPeter Tewkesbury0:33 9 Aug '07  
GeneralRe: Publish just the custom open file dialog PinmemberJackey_shao0:48 9 Aug '07  
GeneralRe: Publish just the custom open file dialog PinmemberPeter Tewkesbury4:22 9 Aug '07  
GeneralRe: Publish just the custom open file dialog PinmemberJackey_shao15:47 9 Aug '07  
QuestionDirectoryNotFoundException PinmemberKorayem.NET0:42 5 Sep '06  
AnswerRe: DirectoryNotFoundException PinmemberKorayem.NET21:35 6 Sep '06  
GeneralNotSupportedException PinmemberSri harini18:11 15 Aug '06  
AnswerRe: NotSupportedException PinmemberPedro Simao6:34 23 Aug '06  
GeneralUnexpected error has occurred in chmreader.net.exe PinmemberGodlyDevil18:19 13 Feb '06  
QuestionRe: Unexpected error has occurred in chmreader.net.exe Pinmemberlsantillo4:06 18 Feb '06  
AnswerRe: Unexpected error has occurred in chmreader.net.exe PinmemberGrugnorr2:59 3 Apr '06  
AnswerRe: Unexpected error has occurred in chmreader.net.exe PinmemberAlexNek8:48 25 Jan '07  
QuestionRe: Unexpected error has occurred in chmreader.net.exe Pinmembersnoopy999:15 31 Jul '07  
GeneralRe: Unexpected error has occurred in chmreader.net.exe PinmemberJackey_shao16:17 9 Aug '07  
Generalfonts PinmembertheGrim10:41 12 Jan '06  
GeneralRe: fonts PinmemberPeter Tewkesbury23:41 13 Jan '06  
GeneralAbout chinese help file Pinmemberydongydong22:45 25 Dec '05  
GeneralRe: About chinese help file PinmemberPeter Tewkesbury23:11 28 Dec '05  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Aug 2004
Editor: Nishant Sivakumar
Copyright 2004 by Peter Tewkesbury
Everything else Copyright © CodeProject, 1999-2009
Web13 | Advertise on the Code Project