Download demo project - 59 Kb
Introduction
In my wanderings I have seen a lot of code to get HTML dialogs, html pages
and the like into a C++ project but I haven't heard any mention about processing
forms. That is about to end now, the included project demonstrates (very
basic) processing of information submitted by a HTML form (which loaded from the
application's resources).
The project also demonstrates the use of linked HTML pages within the
application's resources. While I did not specifically demonstrate it's
use, JavaScript and/or VBScript can be used as well. The possibility of
using Java class files has also come to mind, but that is beyond the scope of
this article.
The project overrides CHtmlView::OnBeforeNavigate2
to catch the form data. The only way to get this navigation message from the CHtmlView
is to simply place an action property in the <FORM>
tag like this:
<FORM action="" method="POST" name="Test">
The overridden code is as follows:
void CTestHTMLView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags,
LPCTSTR lpszTargetFrameName, CByteArray& baPostedData,
LPCTSTR lpszHeaders, BOOL* pbCancel)
{
if( m_bProcessNavigate )
{
CString strMessage, strBytes;
strMessage = _T("");
strMessage.Format(
_T("Browse To:\n%s\n\nFlags: %d\nTarget Frame:\n%s\n\nHeaders:\n%s\n"),
lpszURL, nFlags, lpszTargetFrameName, lpszHeaders);
strBytes = _T("\n\nPosted Bytes :\n\n");
if (baPostedData.GetSize())
{
for(int i = 0;i < baPostedData.GetSize();i++)
{
strBytes += (char)baPostedData[i];
}
strBytes.Replace("&","\n");
}
AfxMessageBox((strMessage + strBytes),MB_OK);
}
CHtmlView::OnBeforeNavigate2(lpszURL, nFlags,
lpszTargetFrameName, baPostedData,
lpszHeaders, pbCancel);
}
Try the program, have a good look at the source for both the C++ and HTML, I
have tried to make sure everything I did is fully documented.
Enjoy!