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
| Feature | Description |
|---|---|
ffi | Enable C-compatible FFI exports (adds serde_json dependency) |
serde | Derive Serialize / Deserialize for MenuItem |
tracing | (reserved for future use) |
Structs§
- ComGuard
- RAII guard for COM initialization. Calls
CoUninitializeon drop. - Context
Menu - Builder for displaying a Windows Explorer context menu.
- FfiCom
Guard - Opaque handle for a COM guard.
- FfiSelected
Item - Information about a selected context menu item.
- Invoke
Params - Parameters for customizing command invocation.
- Menu
Item - A single item from a context menu.
- Selected
Item - A menu item that was selected by the user via
ContextMenu::showorContextMenu::show_at. - Shell
Items - 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
FfiSelectedItemreturned bywcm_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
Resulttype for this crate.