// 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*/);
};