Tasks are grouped items that sit in the tasks panel in the WMC and appear as text commands that can be clicked.
...
As with all navigation items, the label passed to NavInsertItem is a free form text field that has to be unique within its parent.
Once the group is inserted, add tasks beneath it in a similar manner.
Code Block |
---|
NAVSETITEM settingsTaskData; memset(&settingsTaskData, 0, sizeof(settingsTaskData)); settingsTaskData.flags = 0; settingsTaskData.EventMask = NI_EVENT_MOUSE_LCLICK; // We want to know when it's clicked settingsTaskData.strLabel = L"Settings"; settingsTaskData.strDescription = "Configure the Ad Blocker component"; settingsTaskData.strAlias = L"{MyCompanyAdBlockerSettingsTask}"; // Our custom alias. Optional. Aliases are global so need to be unique settingsTaskData.lParam = 0; // Any context data you wish to pass to the notification interface when clicked settingsTaskData.pInterface = ¬ificationInterface; NavInsertItem(taskGroup, L"SettingsTask", &settingsTaskData); NavHandle settingsTask = settingsTaskData.hItem; |
Info |
---|
The NavItemHelpers code in sdk\helpers has more convenient ways to manage navigation items. |
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.
If you have used the same NavigationItemUIInterface for all of your tasks items, you will need to distinguish them from each other. You can do this by the context data that was supplied when the item was inserted, the Navigation Path that the item was added with, or its alias. For example:
Code Block |
---|
LPCWSTR settingsTaskFQN = L"TASKLIST\\MyComponent\\Settings";
LPCWSTR deleteTaskAlias = L"{MyComponentDeleteTask}";
static const unsigned int addItemTaskId = 1;
// The registered handled 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 we are out of here
{
return 0;
}
if ( (UINT)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;
}
|