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 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 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.
...
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; } |