Click here to Skip to main content
15,888,521 members
Articles / Mobile Apps

HTML based dialog for the Pocket PC

Rate me:
Please Sign up or sign in to vote.
4.81/5 (14 votes)
26 Aug 2001CPOL2 min read 349.8K   1.1K   51   107
A library that provides an easy wrapper that encapsulates most of work done with the HtmlView control in CE

Screenshot

Introduction

It seems to be a good idea to use a HTML based dialog in Pocket PC applications. Much of the work you have to do will be done by HTML engine. Pocket PC provides htmlview.dll that contains the HtmlView control. But a lot of developers find it difficult to use. The STHtmlDialog library provides an easy way to use a wrapper that encapsulates most of work done with the HtmlView control.

Using HTML in dialogs your can display a text using different fonts, colors and styles, use different HTML controls, display images, use links and many other features provided by HTML.

Keep also in mind that HTML provided by HtmlView control does not support some of the features you might expect as JavaScript, frames, etc.

What You Need

Background

To create a HtmlView control without the STHtmlDialog library you should:

  1. Add htmlview.lib library to your project. Call Project Settings dialog (Alt+F7), then go to the Link tab page and add htmlview.lib string to Object/library modules field.
  2. Include Htmlctrl.h files. Add  #include <Htmlctrl.h>  line to your StdAfx.h file.
  3. Load the HTML Viewer DLL by calling the LoadLibrary function. Specify Htmlview.dll in the lpLibFileName parameter.
  4. Register the HTML Viewer control class by calling the InitHTMLControl function.
  5. Create a window for the HTML Viewer control by calling the CreateWindow function. Specify DISPLAYNAME in the lpClassName parameter
  6. Rewrite WindowProc function and handle WM_NOTIFY messages. Here you should give images and handle links (NM_HOTSPOT and NM_INLINE_IMAGE codes).

Using STHtmlDialog library

To create an HTML dialog using the STHtmlDialog library you should:

  1. Insert the STHtmlDialog.h and STHtmlDialog.cpp files into your project (use Project\Add To Project\Files menu item).
  2. Add the htmlview.lib library to your project. Call Project Settings dialog (Alt+F7), then go to the Link tab page and add htmlview.lib string to Object/library modules field.
  3. Change the super class of your dialog form CDialog to CSTHtmlDialog.
  4. In the OnInitDialog method of your dialog you should add a call to the SetHtml function that sets the HTML text.

Handling HTML events

Links

When a user clicks a link in HTML, the OnLink virtual function of your dialog is called. To handle links you should override this function. The strHref parameter contains the href attribute of the link that was clicked.

Images

To use images in HTML first register them. Call the RegisterHtmlImage function during initialization for each image you are going to use in HTML. When you register an image you should specify a string that can be used in the HTML src attribute of img tag.

Conclusion

It's easy to create an HTML based dialog using STHtmlDialog library. CSTHtmlDialog wraps functionality of HtmlView control including images and links.

License

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


Written By
Russian Federation Russian Federation
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Compilation Errors Pin
handdol7-Apr-03 21:00
handdol7-Apr-03 21:00 
GeneralRe: Compilation Errors Pin
JoongHoon Lee21-May-03 21:47
JoongHoon Lee21-May-03 21:47 
GeneralRe: Compilation Errors Pin
slomoman11-Oct-03 4:03
slomoman11-Oct-03 4:03 
QuestionHow to get the word selected on HTMLviewer Pin
biswa13-Dec-02 1:20
biswa13-Dec-02 1:20 
AnswerRe: How to get the word selected on HTMLviewer Pin
Anonymous16-Dec-02 1:33
Anonymous16-Dec-02 1:33 
GeneralRe: How to get the word selected on HTMLviewer Pin
DerTyp16-Dec-02 12:45
DerTyp16-Dec-02 12:45 
GeneralRe: How to get the word selected on HTMLviewer Pin
biswa5-Mar-03 19:21
biswa5-Mar-03 19:21 
GeneralRe: How to get the word selected on HTMLviewer Pin
ProudPrimate7-Mar-10 12:19
ProudPrimate7-Mar-10 12:19 
If only that were true!

My code has an HTML control embedded in a dialog, and that is the property of a TreeView of files. When I select a file from the treeview, and choose "HTML" on my menu, it executes the following code:

case ID_LAUNCH_HTML:
________if(hHTMLDlg)________// this is the HTML display window
________________DestroyWindow(hHTMLDlg);
________hHTMLDlg = CreateDialog(hInst,(LPCTSTR)IDD_HTMLVIEW, hwnd, (DLGPROC)HTMLDlgProc);
________SendMessage(hHTMLCtrl, WM_SETTEXT, 0, (LPARAM)(LPCTSTR)_T(""));
________SendMessage(hHTMLCtrl, DTM_ENABLESHRINK, 0, g_bMakeFit);
________if (!SHCreateMenuBar(&amp;mbiHTML))
________________MessageBox(hwnd, L"SHCreateMenuBar Failed", L"Error", MB_OK);
________hwndCB = mbiHTML.hwndMB;
________if(!bHTMLLoaded){
________________hFile = CreateFile(tPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
________________________FILE_ATTRIBUTE_NORMAL,NULL);
________________if(hFile==(void*)-1)
________________________ShowLastError();

________________dwHTMLFileSize = 2 + GetFileSize((HANDLE)hFile,NULL); // 2 bytes must be 0 to get 1 wide-char terminus
________________if(pHTMLSource)
________________________delete pHTMLSource;
________________pHTMLSource = new char[dwHTMLFileSize];
________________memset(pHTMLSource,0,dwHTMLFileSize);
________________ReadFile(hFile,pHTMLSource,dwHTMLFileSize,&amp;BytesRead,NULL);
________________// this is the sourcefile needed to fill the HTML dialog
________________CloseHandle(hFile); // pHTMLSource + (dwHTMLFileSize - 40)
________________}
________lRes = SendMessage(hHTMLCtrl,WM_SETTEXT,0,(LPARAM)(LPCTSTR)TEXT(""));
________SendMessage(hHTMLCtrl,DTM_CLEAR,0,0);
________SendMessage(hHTMLCtrl,DTM_ADDTEXT,false,(LPARAM)/*(LPCTSTR)*/pHTMLSource);
________SendMessage(hHTMLCtrl,DTM_ENDOFSOURCE,(WPARAM)0,(LPARAM)0);
________SendMessage(hHTMLCtrl,DTM_FITTOWINDOW, 0, (LPARAM)VARIANT_TRUE);
________bHTMLLoaded = true;
________ShowWindow(hHTMLDlg,SW_SHOWNORMAL);

________MoveWindow(hHTMLCtrl,0,0,240,268, true);
________ShowWindow(hHTMLCtrl,SW_SHOWNORMAL);
________MoveWindow(hHTMLDlg, 0, 0, 240, 294, true);
________ShowWindow(g_hwndTreeView,SW_HIDE);________________
________ShowWindow(g_hwndEdit,SW_HIDE);________________
________BringWindowToTop(hHTMLCtrl);
________hFocus = GetFocus();
________SetFocus(hHTMLCtrl);
________hFocus = GetFocus();
________break;</small>
As you can see, the handle for the htmlctrl is "hHTMLCtrl". I assure you that this code successfully puts the selected file into HTML display on this control.

But when I send it to a section of code that contains your suggestion

HWND hwnd = ::GetWindow(hHTMLCtrl, GW_CHILD);
::SendMessage(hwnd, WM_COMMAND, 0x139E, 0); //for pc2002

::SendMessage(hwnd, WM_COMMAND, 0x156BA, 0);//for pc2000

I find that (1), this handle has no child windows, and
(2) if I use the handle instead of the child you suggest, the clipboard is empty. I am using Pocket PC2002, but I have tried both the two different WParam values and neither does anything.

But you have done this much: you have provided a good basis for discussion.

(I have read this same solution in the past and tried and failed the same way, so this is well publicized code.

There must be something one can do, but it is also true that the version of IE (Pocket IE) also lacks the functions to copy selected text or any equivalent of the CTRL-F find of the desktop version.

Yet the text is there — somewhere. There's got to be a way to get my hands on it!
GeneralQ241750 BUG: CHtmlView Leaks Memory by Not Releasing BSTRs in Several Methods Pin
Codin' Carlos5-Oct-02 7:31
Codin' Carlos5-Oct-02 7:31 
QuestionLeaks in Example Code...? Pin
Codin' Carlos5-Oct-02 3:34
Codin' Carlos5-Oct-02 3:34 
GeneralHTML under WinCE .net 4.0 Pin
christiandubois12-Sep-02 2:42
christiandubois12-Sep-02 2:42 
GeneralRe: HTML under WinCE .net 4.0 Pin
Anonymous8-Sep-03 7:57
Anonymous8-Sep-03 7:57 
GeneralRe: HTML under WinCE .net 4.0 Pin
radul16-Jan-04 4:45
radul16-Jan-04 4:45 
Generalone error Pin
GOLDEN6-Jul-02 22:43
GOLDEN6-Jul-02 22:43 
Generalabout HtmlView Control Pin
GOLDEN6-Jul-02 20:54
GOLDEN6-Jul-02 20:54 
GeneralListview class thorugh html ctrl Pin
12-Mar-02 1:02
suss12-Mar-02 1:02 
QuestionAccess Violation on exit with ARM Debug? Pin
Heather Bowen14-Jan-02 9:39
Heather Bowen14-Jan-02 9:39 
AnswerRe: Access Violation on exit with ARM Debug? Pin
Codin' Carlos5-Oct-02 3:42
Codin' Carlos5-Oct-02 3:42 
GeneralRe: Access Violation on exit with ARM Debug? Pin
waterdigi10-Apr-03 11:39
waterdigi10-Apr-03 11:39 
QuestionHow I handle button event, combobox event.. ect...? Pin
9-Dec-01 21:46
suss9-Dec-01 21:46 
AnswerRe: How I handle button event, combobox event.. ect...? Pin
dlhson213-Dec-02 2:16
dlhson213-Dec-02 2:16 
Generalgoback, goforward , goHome Pin
7-Nov-01 21:58
suss7-Nov-01 21:58 
Generalload a html file Pin
18-Oct-01 2:33
suss18-Oct-01 2:33 
GeneralRe: load a html file Pin
18-Oct-01 2:57
suss18-Oct-01 2:57 
GeneralRe: load a html file Pin
18-Oct-01 17:34
suss18-Oct-01 17:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.