...
Code Block |
---|
void AddMessageBarItem(LPCWSTR text, LPCWSTR link) { // First get the root of the MESSAGEBAR domain NAVSETITEM messageBarRootData; memset(&messageBarRootData, 0, sizeof(NAVSETITEM)); if( !NavGetItem(_T("MESSAGEBAR"), &messageBarRootData) ) { return; // Failed to find MESSAGEBAR root } NavHandle messageBarRoot = messageBarRootData.hItem; // Now add a simple message bar item NAVSETITEM newItem; memset(&newItem, 0, sizeof(newItem)); newItem.flags = NI_FLAG_MESSAGEBAR_ICONWARNING; // The icon we want to show. NI_FLAG_MESSAGEBAR_ICONINFO, NI_FLAG_MESSAGEBAR_ICONWARNING and NI_FLAG_MESSAGEBAR_ICONSHIELD newItem.EventMask = NI_EVENT_MOUSE_LCLICK; // Need click events to navigate somewhere when the link is clicked newItem.strLabel = L"This is a message bar message"; newItem.strDescriptionstrDestination = L"NAVIGATIONTREE\\ControlPanel\\Events"; // Override description field as the FQN or alias to navigate to when the link is clicked newItem.lParam = 0; // Custom context data newItem.pInterface = ¬ificationInterface; // Interface to handle messages from the message bar NavInsertItem(messageBarRoot, _T("MyComponentWarningEvents"), &newItem); } |
Items added in the manner shown above display the strLabel text as the message, followed by a link that says "Go There". If you click the link, the WMC navigates to the location specified in strDescriptionstrDestination. You can provide customised hyperlink text by providing your own XAML contenta custom formatted message and link by specifying the NI_FLAG_MESSAGEBAR_CUSTOMMESSAGE flag . See Custom link text.
The flags field of the NAVSETITEM structure dictates how the message bar item will be handled.
Flag | Description |
---|---|
NI_FLAG_MESSAGEBAR_ICONWARNING NI_FLAG_MESSAGEBAR_ICONINFO NI_FLAG_MESSAGEBAR_ICONSHIELD | The type of icon to show. Mutually exclusive. |
NI_FLAG_MESSAGEBAR_NOTIFY | Notify the item of the click as opposed to navigating to the location. Calls the NavItemNotify handler of the notification interface supplied in NavInsertItem, passing in the strDestination as the FQL. Without this flag the default behaviour is to go to a navigation location. |
NI_FLAG_MESSAGEBAR_USERXAMLCUSTOMMESSAGE | Specify to supply custom XAML for the itemmessage text with an embedded link with customised text. See below for details. |
Custom link text
Anchor | ||||
---|---|---|---|---|
|
The default link text is Go There but it can be customised by providing your own XAML when inserting the element. To use custom XAML you need to set the By default a message bar item contains user-supplied text followed by a hyperlink with the text Go There. You can supply a custom message that allows you to set the hyperlink text as well as place it anywhere within the message. To do so set the flag NI_FLAG_MESSAGEBAR_USERXAML CUSTOMMESSAGE in flags field of the NAVSETITEM structure . strLabel then becomes the custom XAML and the Hyperlink node's Tag attribute in the XAML specifies the location to navigate toand provide a message in strLabel, enclosing the hyperlink portion in <a></a> tags. e.g.
Code Block |
---|
void AddMessageBarItem(LPCWSTR text, LPCWSTR link) { // First get the root of the MESSAGEBAR domain NAVSETITEM messageBarRootData; memset(&messageBarRootData, 0, sizeof(NAVSETITEM)); if( !NavGetItem(_T("MESSAGEBAR"), &messageBarRootData) ) { return; // Failed to find MESSAGEBAR root } NavHandle messageBarRoot = messageBarRootData.hItem; NAVSETITEM newItem; memset(&newItem, 0, sizeof(newItem)); newItem.flags = NI_FLAG_MESSAGEBAR_USERXAMLCUSTOMMESSAGE; newItem.EventMask = NI_EVENT_MOUSE_LCLICK; std::wstring strLabel; FormatString(strLabel,newItem.strLabel = L"<Image Source='2400'/><TextBlock Padding='3, 0, 20, 0' VerticalAlignment='Center'>This This is the message:text <Hyperlink Tag='MESSAGEBAR\\MyComponent'>%s</Hyperlink></TextBlock>", CResString(IDS_LABEL_THEREISANOTIFICATION).GetBuffer(0), CResString(IDS_LABEL_GOTONOTIFICATIONS).GetBuffer(0)); ItemNew.strLabel = strLabel.c_str(); ItemNew.strDescription<a>with an embedded link</a> to navigate to"; newItem.strDestination = _T("{Notifications}"); // where to go to ItemNewnewItem.lParam = (LPARAM)this; ItemNewnewItem.pInterface = &gTaskInterfacenotificationInterface; NavInsertItem(hMessageBar, _T("NotificationWarning"), &ItemNewnewItem); hWarningNavHandle messageBarItem = ItemNewnewItem.hItem; } |
Hyperlink tag is always the item to find to process the event on (Notify or go to depending on THAT item's flags). This could be the item itself or someone else. If the item is inserted with USERXAML, then the tag is specified by the user. If it's not custom XAML,then the Hyperlink tag is made from the FQN of the item (The 2nd argument to NavInsertItem);
For the target item
If MESSAGEBAR_NOTIFY flag, then Hyperlink tag is the object to notify e.g. "MESSAGEBAR\NotificationWarning". So basically the target and notify items are the same. This is an item that's been inserted with NavINsertItem.
If not MESSAGEBAR NOTIFY then target item's description is the nav location to go to