Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

CHM Reader for Pocket PC 2003

, 29 Feb 2004
Allows the reading of CHM files on a Pocket PC2003.
chmreaderexe.zip
chmreadersource.zip
PocketPC
CHM Reader
CHMLib
AUTHORS
ChmLib.dsp
ChmLib.dsw
COPYING
enumdir_chmLib.dsp
enum_chmLib.dsp
extract_chmLib.dsp
INSTALL
Makefile
NEWS
README
test_chmLib.dsp
res
CHM Reader.ico
Cmdbar.bmp
icon1.ico
CHM Reader.vcl
CHM Reader.ico
CHM Reader.vcp
CHM Reader.vcw
CHM Reader.vcb
CHM Reader.vcc
CHM Reader.vco
chm_readerexe-pc2002.zip
ARMRel
CHM Reader.exe
// STHtmlDialog.cpp : implementation file
//
#include "stdafx.h"
#include "resource.h"
#include "STHtmlDialog.h"
#include <Htmlctrl.h>
#include "VOImage.h"
#include "CHMFile.h"

#define LPINLINEIMAGEINFO (INLINEIMAGEINFO*)

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSTHtmlDialog dialog

HINSTANCE CSTHtmlDialog::m_HtmlViewInstance = 0;

CSTHtmlDialog::CSTHtmlDialog(UINT nIDTemplate, CWnd* pParentWnd)
	: CDialog(nIDTemplate, pParentWnd)
{
	//{{AFX_DATA_INIT(CSTHtmlDialog)
	//}}AFX_DATA_INIT
	m_pCHMFile=NULL;
}


BEGIN_MESSAGE_MAP(CSTHtmlDialog, CDialog)
	//{{AFX_MSG_MAP(CSTHtmlDialog)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSTHtmlDialog message handlers


void CSTHtmlDialog::SetCHMFile(CCHMFile *pCHMFile)
{
	m_pCHMFile=pCHMFile;
}

BOOL CSTHtmlDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CreateHtmlWindow();
	
	return TRUE;
}

void CSTHtmlDialog::CreateHtmlWindow()
{
	CWaitCursor Wait;
	if (m_HtmlViewInstance == 0) {
		m_HtmlViewInstance = ::LoadLibrary(L"htmlview.dll");
	}

	VERIFY(InitHTMLControl(AfxGetInstanceHandle()));
	
	DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;

	RECT rect;
	GetClientRect(&rect);	
	rect.top+=17;
	rect.bottom-=17;
	m_hwndHtml = ::CreateWindow (DISPLAYCLASS, 
                                 NULL,
                                 dwStyle,
                                 rect.left, 
                                 rect.top, 
                                 rect.right, 
                                 rect.bottom,
                                 m_hWnd, 
                                 0, 
                                 m_HtmlViewInstance, 
                                 NULL);

	::SetWindowLong(m_hwndHtml, GWL_ID, 12321);
	::SetFocus (m_hwndHtml);
	::SendMessage(m_hwndHtml, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)_T("")); 
}

void CSTHtmlDialog::SetHtml(const CString &strHtml)
{
	CWaitCursor Wait;
	::SendMessage(m_hwndHtml, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)_T(""));
	::SendMessage(m_hwndHtml, DTM_ADDTEXTW, FALSE, (LPARAM)(LPCTSTR)strHtml);
	::SendMessage(m_hwndHtml, DTM_ENDOFSOURCE, 0, 0);
}

LRESULT CSTHtmlDialog::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
{
	switch(message)
	{	
	case WM_NOTIFY:
			NM_HTMLVIEW * pnmHTML = (NM_HTMLVIEW *) lParam;
			LPNMHDR pnmh = (LPNMHDR) &(pnmHTML->hdr);
			CString strReg = _T("register");

			switch(pnmh->code)
      
			{
			case NM_HOTSPOT:
				OnLink(pnmHTML->szTarget);
				return 1;
				break;

			case NM_INLINE_IMAGE:
				{
					CWaitCursor Wait;					
					CVOImage imgToLoad;
					CDC* pDC = GetDC();
					CStringEx FN(pnmHTML->szTarget);					
					CCHMFile ExternalCHM;

					BYTE *pImage=NULL;									
					CCHMFile *pCHMFile=m_pCHMFile;
					
					CCHMFileInfo *pInfo=m_pCHMFile->CheckFileExists(FN);
					DWORD ImageSize=0;
					if (pInfo==NULL)
					{
						CSplitPath Split(m_CHMFileName,_T('/'));
						CString Name;						
						Name=Split.GetPath()+FN;						
						pInfo=m_pCHMFile->CheckFileExists(Name);
					}
					if ((pInfo==NULL) && (FN.FindNoCase(_T("MS-ITS:"))==0))
					{
						CString ExternalCHMName;				
						int idx=FN.Find(_T("::"));
						ExternalCHMName=FN.Mid(7,idx-7);

						CStringEx Text;			
						int idx2=FN.ReverseFind(_T('/'));
						Text=FN.Right(FN.GetLength()-idx2-1);

						// Get file from external source.						
						if (ExternalCHM.Open(m_pCHMFile->GetSplit().GetPath()+ExternalCHMName))
						{	
							pInfo=ExternalCHM.CheckFileExists(Text);
							pCHMFile=&ExternalCHM;
						}		
					}

					if (pInfo==NULL)
						return 0;
					pImage=pCHMFile->GetFile(pInfo);
					ImageSize=pInfo->m_Length;

					if(imgToLoad.Load(pDC->GetSafeHdc(), pImage, ImageSize))
					{
						INLINEIMAGEINFO	imgInfo;
						imgInfo.dwCookie = pnmHTML->dwCookie;
						imgInfo.iOrigHeight = imgToLoad.GetHeight();
						imgInfo.iOrigWidth = imgToLoad.GetWidth();
						imgInfo.hbm = (HBITMAP)imgToLoad;
						imgInfo.bOwnBitmap = true;
						::SendMessage(m_hwndHtml, DTM_SETIMAGE, 0, (LPARAM)&imgInfo);						
					}
					else
					{
						TRACE(_T("Failed to load %s \n"),FN);
						::SendMessage(m_hwndHtml, DTM_IMAGEFAIL, 0, pnmHTML->dwCookie);
					}

					if (pImage) delete pImage; pImage=NULL;
					return 1;
				}
				break;
			}
	}
	
	return CDialog::WindowProc(message, wParam, lParam);
}

void CSTHtmlDialog::RegisterHtmlImage(int nResourceId, const CString &strHtmlImageName)
{
	CBitmap* pBitmap = new CBitmap();
	pBitmap->LoadBitmap(nResourceId);
	m_imagesCache.SetAt(strHtmlImageName, (CObject*)pBitmap);
}

void CSTHtmlDialog::RegisterHtmlImage(CBitmap *pBitmap, const CString &strHtmlImageName)
{
	m_imagesCache.SetAt(strHtmlImageName, (CObject*)pBitmap);
}

void CSTHtmlDialog::DeleteHtmlImages()
{
	CWaitCursor Wait;
	POSITION pos = m_imagesCache.GetStartPosition();
	CString key;
	CBitmap* bmp;
	while (pos != NULL) 
	{
		m_imagesCache.GetNextAssoc(pos, key, (CObject*&)bmp);
		delete bmp;
		m_imagesCache.RemoveKey(key);
	}
}


void CSTHtmlDialog::SetCHMFileName(CString CHMFileName)
{
	m_CHMFileName=CHMFileName;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Peter Tewkesbury
Software Developer (Senior)
United Kingdom United Kingdom
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 have developed software using Visual C/C++, C#/.NET, MFC, ATL & ASP.NET, SQL Server, Crystal Reports, DevExpress .NET Components, WinForms, SQL Server client side reporting.
 
My favourite language is C# on .NET V3.5 and I am always trying to learn new stuff like LINQ.

| Advertise | Privacy | Mobile
Web04 | 2.8.140718.1 | Last Updated 1 Mar 2004
Article Copyright 2004 by Peter Tewkesbury
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid