Skip to main content

Crate win_context_menu

Crate win_context_menu 

Source
Expand description

§win-context-menu

Show and interact with Windows Explorer context menus programmatically.

This crate provides a safe Rust API to display the native Windows shell context menu for files and folders, enumerate menu items, and execute selected commands — all without requiring an Explorer window.

§Quick Start

use win_context_menu::{init_com, show_context_menu};

fn main() -> win_context_menu::Result<()> {
    let _com = init_com()?;
    if let Some(selected) = show_context_menu(r"C:\Windows\notepad.exe")? {
        println!("Selected: {}", selected.menu_item().label);
        selected.execute()?;
    }
    Ok(())
}

§Threading

All operations require COM to be initialized in single-threaded apartment (STA) mode on the calling thread. Call init_com once at the start of your thread. The returned ComGuard must be kept alive for the duration of your context-menu work and must not be moved to another thread.

§Feature flags

FeatureDescription
ffiEnable C-compatible FFI exports (adds serde_json dependency)
serdeDerive Serialize / Deserialize for MenuItem
tracing(reserved for future use)

Structs§

ComGuard
RAII guard for COM initialization. Calls CoUninitialize on drop.
ContextMenu
Builder for displaying a Windows Explorer context menu.
FfiComGuard
Opaque handle for a COM guard.
FfiSelectedItem
Information about a selected context menu item.
InvokeParams
Parameters for customizing command invocation.
MenuItem
A single item from a context menu.
SelectedItem
A menu item that was selected by the user via ContextMenu::show or ContextMenu::show_at.
ShellItems
Resolved shell items ready to create a context menu from.

Enums§

Error
Errors that can occur when working with Windows shell context menus.

Functions§

init_com
Initialize COM for the current thread in STA mode.
show_context_menu
Convenience: show a context menu for a single path at the cursor position.
show_extended_context_menu
Convenience: show an extended context menu (Shift+right-click) at the cursor position.
wcm_com_init
Initialize COM in STA mode.
wcm_com_uninit
Free a COM guard handle returned by wcm_com_init.
wcm_enumerate_menu
Enumerate context menu items as a JSON string.
wcm_free_selected
Free a FfiSelectedItem returned by wcm_show_context_menu.
wcm_free_string
Free a string returned by wcm_enumerate_menu.
wcm_last_error
Retrieve the last error message from the most recent failed wcm_* call on this thread.
wcm_show_context_menu
Show a context menu for a single file path at the given screen coordinates.

Type Aliases§

Result
A specialized Result type for this crate.