Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Tasks are grouped clickable text items that sit in the Tasks panel in the WMC. They are placed into groups and have a lifetime that's controllable by the component that created themYour component should use tasks to provide a uniform method of configuration adjustment.

Adding tasks

Tasks stay visible until they are removed with NavDeleteItem therefore you typically  so you can create permanent task items (Like the Submit feedback task above) by not deleting the task and its group. Typically however, you want to add them when your panel becomes active and delete them when the panel is deactivated. See Tree items and panels for information of on handling (de)activation events.

 

To add a task, first insert a task group under the TASKLIST root domain with NavInsertItem.

Code Block
// Error handling omitted for brevity
NAVSETITEM taskRootData;
NavGetItem(L"TASKLIST", &taskRootData);					// Get the task root to put our group under
NavHandle taskRoot = taskRootData.hItem;

NAVSETITEM taskGroupData;
memset(&taskGroupData, 0, sizeof(taskGroupData));
taskGroupData.flags = NI_FLAG_CONTAINER;				// Signals it's a group that will hold tasks
taskGroupData.strLabel = L"Ad Blocker";
taskGroupData.strDescription = L"Tasks for the Ad Blocker component";
NavInsertItem(taskRootData.hItemtaskRoot, L"AdBlockerTaskGroup", &taskGroupData);			// Error handling removed for brevity
NavHandle taskGroup = taskGroupData.hItem;

As with all navigation items, the label passed to NavInsertItem is a free form text field that has to be unique within amongst its parentsiblings.

 

Once the group is inserted, add tasks beneath it in a similar manner.

...

Info

The NavItemHelpers code in sdk\helpers has more convenient ways to manage tasks

Removing tasks

To remove a task simply call NavDeleteItem with the FQN or alias of the task you wish to delete.

Changing tasks

If you wish to change a task item's properties (label, description etc) you can do so with NavSetItem or NavSetItemEx

Code Block
NAVSETITEM newItemProperties;
newItemProperties.mask = NI_MASK_LABEL | NI_MASK_DESCRIPTION;
newItemProperties.strLabel = L"New Label";
newItemProperties.strDescription = L"New Description";
NavSetItem(aliasOrFQNOfTaskToChange, &newItemProperties);

 

Responding to task activation

In order to respond to user task selection you need to create the task with the NI_EVENT_MOUSE_LCLICK mask bit set in the EventMask field and you need to provide a NavigationItemUIInterface pointer that has a NavItemNotify function. When a user clicks a task then the framework calls your NavItemNotify function with the message value NI_EVENT_MOUSE_LCLICK. 

...

Code Block
LPCWSTR settingsTaskFQN = L"TASKLIST\\AdBlockerTaskGroup\\SettingsTask";
LPCWSTR deleteTaskAlias = L"{MyComponentDeleteTask}";
static const unsigned int addItemTaskId = 1;


// The registered handledhandler for the notify messages for your navigation items. This example assumes that only task items use this function
UINT NavItemNotify(NAVITEMNOTIFY* notifyMessage)
{
	if ( notifyMessage->nMsg != NI_EVENT_MOUSE_LCLICK)					// Not a click event so weno areneed outto ofcontinue
here
	{
		return 0;
	}
 
	if ( (unsigned int)notifyMessage->pContext == addItemTaskId )		// addItemTaskId was set as the lParam field when registering that task
	{
		DoAddItem();
		return 0;
	}
 
	if ( _wcsicmp(notifyMessage->strAlias, deleteTaskAlias) )			// We set strAlias when we registered the task
	{
		DoDelete();
		return 0;
	}

	if ( _wcsicmp(notifyMessage->strFQN, settingsTaskFQN) )				// Compare the raw FQN
	{
		DoSettings();
		return 0;
	}
 
	return 0;
}