| ||||||||
CMudCtrl Class
The
To use CMudCtrl in your Visual Studio MFC project, just add MudCtrl.cpp and MudCtrl.h. Put a CMudCtrl member variable in a parent window class such as a dialog or view and create it with its Call the MUDMLThe markup used in the content of the CMudCtrl class is called MUDML (MarkUp Draw Markup Language). It is designed to be so simple as to need little explanation. First of all, whitespace and newline characters are significant; there are no paragraph tags or break tags like HTML. But it supports the following tags much like HTML:
To combine formatting tags, make sure they are properly nested. In other words, if the U start tag is after the B start tag, then the U end tag must come before the B end tag. BoldUnderline It also supports about 250 common HTML character entities like © © and Ñ Ñ. A central feature of MUDML is the ability to specify any attributes in a hyperlink because all of the attributes are passed to the event handler for the hyperlink. For example: <A href="http://example.com" handling="zoom" option="6">Example</A>
It does not even need an Event HandlerIn your parent window class, set up an ON_MESSAGE(CMudCtrl::m_WM_MUDNOTIFY, OnMudNotify) The following example is adapted from the News Reader. Here is an example hyperlink in the MUDML source, and in the example event handler below you can see how the special attributes are used. <A feedid="4" type="ViewAll" newcount="2">News from firstobject.com</A>
The wParam contains the windows handle of the LRESULT CNewsDlg::OnMudNotify( WPARAM wParam, LPARAM lParam )
{
// Get child window handle and hyperlink details from params
HWND hWnd = HWND(wParam);
CMudCtrl::CMudNMHDR* pNMHDR = (CMudCtrl::CMudNMHDR*)lParam;
CMarkup xml( pNMHDR->csElement );
xml.FindElem();
// Perform action code
if ( pNMHDR->code == NM_RCLICK )
{
// Determine details straight from MUDML hyperlink XML subdocument
CString csType = xml.GetAttrib( "type" );
int nNewCount = atoi(xml.GetAttrib( "newcount" ) );
int nUnviewed = atoi(xml.GetAttrib( "unviewed" ) );
BOOL bNew = (csType=="NewOnly")?TRUE:FALSE;
m_xmlNotify.SetDoc( pNMHDR->csElement ); // keep for command handling
// Build and run menu
CMenu menu;
menu.CreatePopupMenu();
UINT nGray = (nUnviewed||nNewCount||bNew)?0:MF_GRAYED;
menu.AppendMenu( MF_STRING|nGray, ID_FEED_MARK_AS_READ, "Mark As Read" );
menu.AppendMenu( MF_SEPARATOR, NULL, "" );
menu.AppendMenu( MF_STRING, ID_FEED_VIEW, "&View" );
menu.AppendMenu( MF_STRING, ID_FEED_VIEW_BRIEF, "View &Brief" );
menu.AppendMenu( MF_STRING, ID_FEED_UPDATE, "&Update Now" );
menu.AppendMenu( MF_STRING, ID_FEED_MODIFY, "&Modify" );
menu.AppendMenu( MF_STRING, ID_FEED_DELETE, "&Delete" );
menu.AppendMenu( MF_SEPARATOR, NULL, "" );
nGray = (nNewCount||bNew)?0:MF_GRAYED;
menu.AppendMenu( MF_STRING|nGray, ID_FEED_VIEW_NEW, "&View New" );
menu.AppendMenu( MF_STRING|nGray, ID_FEED_VIEW_BRNEW, "View Brief New" );
menu.SetDefaultItem( bNew?ID_FEED_VIEW_NEW:ID_FEED_VIEW );
CPoint pt;
GetCursorPos( &pt );
menu.TrackPopupMenu( TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this );
}
else if ( pNMHDR->code == NM_CLICK )
{
// Show feed in viewer or launch browser if href given
CString csHREF = xml.GetAttrib( "href" );
if ( csHREF.IsEmpty() )
ShowViewer( xml );
else
LaunchBrowser( csHREF );
}
return 0;
}
|
|
Posted November 18, 2005. Question or comment about this article? ©Copyright 2008 First Objective Software, Inc. All rights reserved. |