PH_EMENU_SHOW_LEFTRIGHT,
                        PH_ALIGN_LEFT | PH_ALIGN_BOTTOM,
                        rect.left,
                        rect.top
                        );

                    if (selectedItem && selectedItem->Id)
                    {
                        if (selectedItem->Id == 1)
                        {
                            context->HideUserPages =!context->HideUserPages;
                        }
                        else if (selectedItem->Id == 2)
                        {
                            context->HideSystemPages =!context->HideSystemPages;
                        }
                        else if (selectedItem->Id == 3)
                        {
                            context->HideInlineFrames =!context->HideInlineFrames;
                        }
                        else if (selectedItem->Id == 4)
                        {
                            context->HighlightUserPages =!context->HighlightUserPages;
                            PhSetIntegerSetting(L"UseColorUserThreadStack", context->HighlightUserPages);
                        }
                        else if (selectedItem->Id == 5)
                        {
                            context->HighlightSystemPages =!context->HighlightSystemPages;
                            PhSetIntegerSetting(L"UseColorSystemThreadStack", context->HighlightSystemPages);
                        }
                        else if (selectedItem->Id == 6)
                        {
                            context->HighlightInlineFrames =!context->HighlightInlineFrames;
                            PhSetIntegerSetting(L"UseColorInlineThreadStack", context->HighlightInlineFrames);
                        }

                        PhApplyTreeNewFilters(&context->TreeFilterSupport);
                    }

                    PhDestroyEMenu(menu);
                }
                break;
            }
        }
        break;
    case WM_SIZE:
        {
            PhLayoutManagerLayout(&context->LayoutManager);
        }
        break;
    case WM_SIZING:
        {
            PhResizingMinimumSize((PRECT)lParam, wParam, MinimumSize.right, MinimumSize.bottom);
        }
        break;
    }

    return FALSE;
}

VOID PhpFreeThreadStackItem(
    _In_ PTHREAD_STACK_ITEM StackItem
    )
{
    if (StackItem->Symbol) PhDereferenceObject(StackItem->Symbol);
    if (StackItem->FileName) PhDereferenceObject(StackItem->FileName);
    if (StackItem->LineText) PhDereferenceObject(StackItem->LineText);

    PhFree(StackItem);
}

BOOLEAN NTAPI PhpWalkThreadStackCallback(
    _In_ PPH_THREAD_STACK_FRAME StackFrame,
    _In_opt_ PVOID Context
    )
{
    PPH_THREAD_STACK_CONTEXT threadStackContext = (PPH_THREAD_STACK_CONTEXT)Context;
    PPH_STRING symbol;
    PPH_STRING fileName = NULL;
    PPH_STRING lineText = NULL;
    PTHREAD_STACK_ITEM item;
    ULONG64 baseAddress = 0;
    BOOLEAN enableStackFrameInlineInfo;
    BOOLEAN enableStackFrameLineInfo;

    if (!threadStackContext)
        return FALSE;
    if (threadStackContext->StopWalk)
        return FALSE;

    enableStackFrameInlineInfo =!!PhGetIntegerSetting(L"EnableThreadStackInlineSymbols");
    enableStackFrameLineInfo =!!PhGetIntegerSetting(L"EnableThreadStackLineInformation");

    PhAcquireQueuedLockExclusive(&threadStackContext->StatusLock);
    {
        if (threadStackContext->NewList->Count)
        {
            PH_FORMAT format[3];

            PhInitFormatS(&format[0], L"Processing stack frame ");
            PhInitFormatU(&format[1], threadStackContext->NewList->Count);
            PhInitFormatS(&format[2], L"...");

            PhMoveReference(&threadStackContext->StatusMessage, PhFormat(format, RTL_NUMBER_OF(format), 0));
        }
        else
        {
            PhMoveReference(&threadStackContext->StatusMessage, PhCreateString(L"Processing stack frames..."));
        }
    }
    PhReleaseQueuedLockExclusive(&threadStackContext->StatusLock);

    if (enableStackFrameInlineInfo && PhSymbolProviderInlineContextSupported())
    {
        symbol = PhGetSymbolFromInlineContext(
            threadStackContext->SymbolProvider,
            StackFrame,
            NULL,
            &fileName,
            NULL,
            NULL,
            &baseAddress
            );

        if (symbol &&
            (StackFrame->Flags & PH_THREAD_STACK_FRAME_I386) &&
           !(StackFrame->Flags & PH_THREAD_STACK_FRAME_FPO_DATA_PRESENT))
        {
            PhMoveReference(&symbol, PhConcatStringRefZ(&symbol->sr, L" (No unwind info)"));
        }

        if (PhPluginsEnabled)
        {
            PH_PLUGIN_THREAD_STACK_CONTROL control;

            control.Type = PluginThreadStackResolveSymbol;
            control.UniqueKey = threadStackContext;
            control.u.ResolveSymbol.StackFrame = StackFrame;
            control.u.ResolveSymbol.Symbol = symbol;
            control.u.ResolveSymbol.FileName = fileName;

            PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackThreadStackControl), &control);

            symbol = control.u.ResolveSymbol.Symbol;
            fileName = control.u.ResolveSymbol.FileName;
        }

        if (enableStackFrameLineInfo)
        {
            PPH_STRING lineFileName;
            PH_SYMBOL_LINE_INFORMATION lineInfo;

            if (PhGetLineFromInlineContext(
                threadStackContext->SymbolProvider,
                StackFrame,
                baseAddress,
                &lineFileName,
                NULL,
                &lineInfo
                ))
            {
                PH_FORMAT format[3];

                PhInitFormatSR(&format[0], lineFileName->sr);
                PhInitFormatS(&format[1], L" @ ");
                PhInitFormatU(&format[2], lineInfo.LineNumber);

                lineText = PhFormat(format, RTL_NUMBER_OF(format), 0);
                PhDereferenceObject(lineFileName);
            }
        }

        if (symbol && PhIsStackFrameTypeInline(StackFrame->InlineFrameContext))
        {
            PhMoveReference(&symbol, PhConcatStringRefZ(&symbol->sr, L" (Inline function)"));
        }
    }
    else
    {
        symbol = PhGetSymbolFromAddress(
            threadStackContext->SymbolProvider,
            (ULONG64)StackFrame->PcAddress,
            NULL,
            &fileName,
            NULL,
            NULL
            );

        if (symbol &&
            (StackFrame->Flags & PH_THREAD_STACK_FRAME_I386) &&
           !(StackFrame->Flags & PH_THREAD_STACK_FRAME_FPO_DATA_PRESENT))
        {
            PhMoveReference(&symbol, PhConcatStringRefZ(&symbol->sr, L" (No unwind info)"));
        }

        if (PhPluginsEnabled)
        {
            PH_PLUGIN_THREAD_STACK_CONTROL control;

            control.Type = PluginThreadStackResolveSymbol;
            control.UniqueKey = threadStackContext;
            control.u.ResolveSymbol.StackFrame = StackFrame;
            control.u.ResolveSymbol.Symbol = symbol;
            control.u.ResolveSymbol.FileName = fileName;

            PhInvokeCallback(PhGetGeneralCallback(GeneralCallbackThreadStackControl), &control);

            symbol = control.u.ResolveSymbol.Symbol;
            fileName = control.u.ResolveSymbol.FileName;
        }

        if (enableStackFrameLineInfo)
        {
            PPH_STRING lineFileName;
            PH_SYMBOL_LINE_INFORMATION lineInfo;

            if (PhGetLineFromAddress(
                threadStackContext->SymbolProvider,
                (ULONG64)StackFrame->PcAddress,
                &lineFileName,
                NULL,
                &lineInfo
                ))
            {
                PH_FORMAT format[3];

                PhInitFormatSR(&format[0], lineFileName->sr);
                PhInitFormatS(&format[1], L" @ ");
                PhInitFormatU(&format[2], lineInfo.LineNumber);

                lineText = PhFormat(format, RTL_NUMBER_OF(format), 0);
                PhDereferenceObject(lineFileName);
            }
        }
    }

    item = PhAllocateZero(sizeof(THREAD_STACK_ITEM));
    item->StackFrame = *StackFrame;
    item->Index = threadStackContext->NewList