Listing 3: wdjtest.cpp Test program for SimpleHTMLDisplay
#include <windows.h> #include "simphtml.hpp" #include "resource.h" LPCTSTR lpszTestStr= "<b><u>WDJ SimpleHTML Test</u></b><br><br>" "<b>SimpleHTML</b> is a class that gives basic HTML handling " "capabilities to a RichEdit control. It supports <b>bold</b>, " "<i>italic</i> and <u>underline</u> styles, as well as <font " "color=\"#FF0000\">color</font> <font color=\"#00FF00\">" "changing</font>. It also supports hyperlinks " "(<a href=\"http://www.wdj.com\">like this one</a>!).<br>"; BOOL CALLBACK TestDlgProc(HWND,UINT,WPARAM,LPARAM); BOOL HandleURL(HWND,LPNMHDR); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int) { HINSTANCE hInstRich; // Initialise richedit library if (!(hInstRich=LoadLibrary("riched20.dll"))) return 0; // Show dialog DialogBoxParam(hInstance,MAKEINTRESOURCE(IDD_TESTDLG), HWND_DESKTOP,(DLGPROC)TestDlgProc,0); // Free library and exit FreeLibrary(hInstRich); return 0; } // Dialog procedure BOOL CALLBACK TestDlgProc(HWND hWnd,UINT msg,WPARAM w,LPARAM l) { if (msg==WM_INITDIALOG) { // Give HTML capabilities to the rich edit control new SimpleHTMLDisplay(GetDlgItem(hWnd,IDC_RICHEDIT)); // Print example text SetDlgItemText(hWnd,IDC_RICHEDIT,lpszTestStr); return TRUE; } if (msg==WM_CLOSE || (msg==WM_COMMAND && w==MAKEWPARAM(IDCANCEL,BN_CLICKED))) { EndDialog(hWnd,0); return TRUE; } // Handle URL notifications if (msg==WM_NOTIFY && w==IDC_RICHEDIT) { SetWindowLong(hWnd,DWL_MSGRESULT, HandleURL(hWnd,(LPNMHDR)l)); return TRUE; } return FALSE; } // Handle URL stuff BOOL HandleURL(HWND hWnd,LPNMHDR lphdr) { // Link event? if (lphdr->code==EN_LINK) { ENLINK *lpLink=(ENLINK *)lphdr; // Button down? if (lpLink->msg==WM_LBUTTONDOWN) { LPTSTR lpszURL; // Get URL from the control if (lpszURL=(LPTSTR)SendMessage(lphdr->hwndFrom, SHDMSG_GETURL,0,(LPARAM)lpLink)) { SendMessage(lphdr->hwndFrom,SHDMSG_HIGHLIGHTURL, TRUE,(LPARAM)lpLink); ShellExecute(NULL,"open",lpszURL,NULL,NULL,SW_SHOW); SendMessage(lphdr->hwndFrom,SHDMSG_HIGHLIGHTURL, FALSE,(LPARAM)lpLink); } return TRUE; } // Swallow other button events if (lpLink->msg==WM_LBUTTONDBLCLK || lpLink->msg==WM_LBUTTONUP) return TRUE; } // Event not handled return FALSE; } //End of File