Repository: microsoft/PowerToys
File: src/modules/NewPlus/NewShellExtensionContextMenu.win10/shell_context_menu_win10.cpp (C++)

Code before:
        if (template_icon_handle)
        {
            bitmap_handles.push_back(CreateBitmapFromIcon(template_icon_handle));
            DestroyIcon(template_icon_handle);
        }
    }
    if (bitmap_handles.size() > current_template_icon_index && bitmap_handles[current_template_icon_index])
    {
        newplus_menu_item_template.fMask |= MIIM_BITMAP;
        newplus_menu_item_template.hbmpItem = bitmap_handles[current_template_icon_index];
    }

    InsertMenuItem(sub_menu_of_templates, sub_menu_index, TRUE, &newplus_menu_item_template);
}

IFACEMETHODIMP shell_context_menu_win10::InvokeCommand(CMINVOKECOMMANDINFO* params)
{
    if (!params)
    {
        return E_FAIL;
    }

    if (HIWORD(params->lpVerb)!=0)
    {
        // Not a menu command. It's likely a string verb command from another menu.
        // The logic to interpret lpVerb is explained here: https://learn.microsoft.com/en-us/previous-versions//bb776881(v=vs.85)?redirectedfrom=MSDN#invokecommand-method
        return E_FAIL;
    }

    // Get selected menu item (a template or the "Open templates" item)
    const auto selected_menu_item_index = LOWORD(params->lpVerb) - 1;
    if (selected_menu_item_index < 0)
    {
        return E_FAIL;
    }

    const auto number_of_templates = templates->list_of_templates.size();
    const bool is_template_item = selected_menu_item_index < number_of_templates;

    // Save how many item templates we have so it can be sent later when we do something with New+.
    // It will be sent when the user does something, similar to Windows 11 context menu.
    newplus::utilities::set_saved_number_of_templates(static_cast<size_t>(number_of_templates));

    if (is_template_item)
    {
        // It's a template menu item
        const auto template_entry = templates->get_template_item(selected_menu_item_index);

        return newplus::utilities::copy_template(template_entry, site_of_folder);
    }
    else

Review comment (suggestion):
```suggestion
        // The logic to interpret lpVerb is explained here: https://learn.microsoft.com/en-us/previous-versions//bb776881(v=vs.85)#invokecommand-method
```

Code after:
        if (template_icon_handle)
        {
            bitmap_handles.push_back(CreateBitmapFromIcon(template_icon_handle));
            DestroyIcon(template_icon_handle);
        }
    }
    if (bitmap_handles.size() > current_template_icon_index && bitmap_handles[current_template_icon_index])
    {
        newplus_menu_item_template.fMask |= MIIM_BITMAP;
        newplus_menu_item_template.hbmpItem = bitmap_handles[current_template_icon_index];
    }

    InsertMenuItem(sub_menu_of_templates, sub_menu_index, TRUE, &newplus_menu_item_template);
}

IFACEMETHODIMP shell_context_menu_win10::InvokeCommand(CMINVOKECOMMANDINFO* params)
{
    if (!params)
    {
        return E_FAIL;
    }

    if (HIWORD(params->lpVerb)!=0)
    {
        // Not a menu command. It's likely a string verb command from another menu.
        // The logic to interpret lpVerb is explained here: https://learn.microsoft.com/en-us/previous-versions//bb776881(v=vs.85)#invokecommand-method
        return E_FAIL;
    }

    // Get selected menu item (a template or the "Open templates" item)
    const auto selected_menu_item_index = LOWORD(params->lpVerb) - 1;
    if (selected_menu_item_index < 0)
    {
        return E_FAIL;
    }

    const auto number_of_templates = templates->list_of_templates.size();
    const bool is_template_item = selected_menu_item_index < number_of_templates;

    // Save how many item templates we have so it can be sent later when we do something with New+.
    // It will be sent when the user does something, similar to Windows 11 context menu.
    newplus::utilities::set_saved_number_of_templates(static_cast<size_t>(number_of_templates));

    if (is_template_item)
    {
        // It's a template menu item
        const auto template_entry = templates->get_template_item(selected_menu_item_index);

        return newplus::utilities::copy_template(template_entry, site_of_folder);
    }
    else