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

Web Win32/WTL Hybrid

, 22 Dec 2005
How to implement a two-way communication path from IExplorer and WTL code
webwin32sample.zip
html
res
toolbar.bmp
WebWin32Sample.exe.manifest
WebWin32Sample.ico
WebWin32SampleDoc.ico
WebWin32EventHandler.rgs
WebWin32HTMLEventHandler.rgs
WebWin32Lib.rgs
WebWin32Sample.rgs
WebWin32Sampleps.def
WebWin32Sampleps.mk
webwin32samplevc6.zip
toolbar.bmp
WebWin32Sample.exe.manifest
WebWin32Sample.ico
WebWin32Sampledoc.ico
WebWin32Sampleps.def
WebWin32Sample.dsp
WebWin32Sample.dsw
WebWin32Sampleps.mk
WebWin32Sample.opt
WebWin32Sample.plg
QQQQ.rgs
WebWin32EventHandler.rgs
WebWin32HTMLEventHandler.rgs
WebWin32Lib.rgs
WebWin32Sample.rgs
WebWin32Sample.idl.seg
WebWin32Sample.tlb
// WebWin32SampleView.h : interface of the CWebWin32SampleView class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

#include "iExplorer.h"

#define BEGIN_HTML_DDX() void _HtmlDDXElements( CWTLIExplorer & pBrowser, BOOL VarToControl ) {
#define   BEGIN_FORM( X ) { _bstr_t formName( X );
#define     DDX_HTML_STRING(x,z) pBrowser.QueryHtmlElementValueTextBox( x,formName,z, VarToControl );
#define     DDX_HTML_CHECKBOX(x,z) pBrowser.QueryHtmlElementValueCheckBox( x,formName,z, VarToControl );
#define     DDX_HTML_LISTBOX(x,z) pBrowser.QueryHtmlElementValueListBox( x,formName,z, VarToControl );

#define   END_FORM() }
#define END_HTML_DDX() };
#define DDX_HTML_EXCHANGE( T , Z ) _HtmlDDXElements(T,Z);

#define ID_HTML_CLICK 1

#define SET_HTML_MESSAGE_MAP() _DefineHtmlMsgMap();
#define BEGIN_HTML_MSG_MAP(X,Y) 	void _DefineHtmlMsgMap()\
{\
CWTLIExplorer & __pBrowser = Y;\
DWORD pointer_part_1;\
DWORD pointer_part_2 = (DWORD) this;\
LRESULT (X::*pVar) ( BOOL & );

#define COMMAND_HTML_HANDLER(id,elementName,handler)		pVar = handler;\
memcpy( &pointer_part_1, ( char * )  &pVar, 4 );\
__pBrowser.SetObjectHandler( id, elementName, pointer_part_1, pointer_part_2 );

#define END_HTML_MSG_MAP() }


class CWebWin32SampleView : public CWindowImpl<CWebWin32SampleView,CAxWindow>
{
public:
	DECLARE_WND_SUPERCLASS(NULL, CAxWindow::GetWndClassName())

	// Our internet explorer
	CWTLIExplorer m_pBrowser;

	// Our vars to Exchange information with HTML page...
	CString		  m_FirstName;
	CString		  m_LastName;
	CString		  m_Address;
	CString		  m_Country;
	BOOL		  m_ILikeThisSample;

	 // html-hosted-page-form-based DDX
 	BEGIN_HTML_DDX()
	   BEGIN_FORM( "testForm" ) // Our Form Name ( at HTML page )
		  // Our exchange definitions...
		  DDX_HTML_STRING( m_FirstName ,"firstName" ) 
	      DDX_HTML_STRING( m_LastName  ,"lastName" )
	      DDX_HTML_STRING( m_Address,"address" )
	      DDX_HTML_LISTBOX( m_Country, "country" );
	      DDX_HTML_CHECKBOX( m_ILikeThisSample, "ILikeIt" )
	   END_FORM()
 	END_HTML_DDX()


	// HTML Handlers
	// Here we can define HTML handlers hooks related to element the 
	// page loaded
	BEGIN_HTML_MSG_MAP(CWebWin32SampleView,m_pBrowser)
		// Set an event handler on buttonSumbmit.onclick 
		COMMAND_HTML_HANDLER(ID_HTML_CLICK, "buttonSubmit", OnSubmit )
	END_HTML_MSG_MAP()

	LRESULT OnSubmit( BOOL & bHandled )
	{
		// Do Data Exchange with HTML page...
		DDX_HTML_EXCHANGE( m_pBrowser, false )

		// MessageBox text Composite 
		CString totalMessage = m_FirstName + CString(" - ") + m_LastName + CString(" - " ) + m_Address;

		if ( m_ILikeThisSample )
			 totalMessage += CString("\n\nYou have checked it." );
		else
			 totalMessage += CString("\n\nYou have not checked it." );

		totalMessage += CString("\n\nCountry Selected: ") + m_Country;

		// Show a message box
		MessageBox( totalMessage,"From CWebWin32SampleView::OnSubmit event handler.", MB_ICONINFORMATION );

		// set handled
		bHandled = true;
 
		return 0;
	}


	BOOL PreTranslateMessage(MSG* pMsg);

	BEGIN_MSG_MAP(CWebWin32SampleView)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_SIZE, OnSize)

		// We receive this message when the IExplorer is on a ready state
		// and we can Set handlers to the page...
		MESSAGE_HANDLER(WM_HTML_SETHANDLERS /* = WM_USER + 1 */ , OnHTMLSetHandlers )
	END_MSG_MAP()

	LRESULT OnHTMLSetHandlers(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/ )
	{
		// Activate event handlers map
		SET_HTML_MESSAGE_MAP();
		return 0;
	}

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
};

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 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

Share

About the Author

Jesus Salas
CEO wave-vs.net
Spain Spain
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 22 Dec 2005
Article Copyright 2002 by Jesus Salas
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid