跳到正文
DEV Community· Morphalo·· 13 小時前AI 評分41

Morphalo 如何構建一款在檔案總管運作的 WinUI 3 檔案轉換應用

Win + click to convert any file: building a WinUI 3 app that lives in Explorer

AI 導讀

開發者打造 Windows 11 工具 Morphalo,讓用戶在檔案總管按住 Windows 鍵並點擊檔案,再透過 Halo 選取合適的轉換或工具,原檔不會被修改。它以全域低階鈎子偵測操作,並在獨立 worker process 執行轉換。Morphalo 透過 Microsoft Store 以 MSIX 發佈,試用期為 7 天內可執行 10 次操作,其後一次性購買 €4.99。

正文

I build Morphalo, a Windows 11 utility with one idea: you shouldn't have to open a converter. Hold the Windows key, click a file in File Explorer, and a ring of actions (the Halo) opens around it with every conversion and tool that fits that file. Pick one. The original stays untouched; the new file waits beside it.

This post is about the parts that were interesting to build: catching a modifier-click globally without breaking the shell, an Explorer context-menu entry that can't crash Explorer, and keeping heavy native libraries out of the UI process.

1. Catching Win + click without owning the shell

The gesture needs a global hook: WH_KEYBOARD_LL to track the modifier chord and WH_MOUSE_LL to see the click. Both run on a dedicated thread with its own message loop, because low-level hooks are called on the installing thread and Windows silently removes a hook that is slow to return.

The rule I ended up enforcing in code review: hook callbacks do no allocations, no COM and no logging. They update a tiny chord state machine, and if the chord matches, they post a message to a separate probe thread and return immediately. When the chord click is ours, the mouse hook returns 1 to swallow it, so Explorer doesn't also select or open the file.

The state machine (which keys are down, left vs. right modifiers, what counts as a chord) has no Win32 calls in it, so it's unit-tested on any OS.

2. Which file did they click?

The hook gives you screen coordinates, not a file. The probe thread uses UI Automation (IUIAutomation) to resolve the element under the point and walk up to the Explorer item, then asks the shell for its path. It works for Explorer windows and the desktop, and it's the supported way to do this, rather than sampling pixels or guessing from window titles.

3. Copilot+ PCs already use Win + click

On Copilot+ PCs, Windows uses Win + click for Click to Do. Morphalo never writes Click to Do policy keys on its own. Instead, it asks on first start which click you'd like (Win + right-click, Win + Alt + click, or Ctrl + Alt + click), and the chord stays configurable.

4. A context-menu entry that can't crash Explorer

"Convert with Morphalo" appears in the Windows 11 right-click menu through the MSIX manifest (desktop4:FileExplorerContextMenus). The handler is a COM class hosted in a surrogate (dllhost), not loaded into explorer.exe. All it does is send the selected paths to the Morphalo host over a named pipe. If something goes wrong, Explorer doesn't go down with it.

5. Native engines live in a worker process

Conversions run in a separate worker process, talking to the host over StreamJsonRpc with MessagePack:

  • ImageMagick (Magick.NET) for pictures, including HEIC, JPEG XL and camera RAW
  • PDFium to render PDF pages, PDFsharp to create and edit PDFs
  • An unmodified LGPL FFmpeg build for audio and video (no GPL codecs; H.264/HEVC encode through hardware or Media Foundation)
  • Open XML SDK for Excel, SharpCompress for archives

LibreOffice, Pandoc and 7-Zip are optional: downloaded once from their publishers, only after you agree, checked against a pinned SHA-256, installed per user without admin rights, and run as separate programs.

Two rules made this safe to ship. External tools start only through ProcessStartInfo.ArgumentList, never a shell string. And only one component writes next to user files, always as temp file plus atomic rename, never overwriting and never touching the source.

6. Packaging and the Store

It ships as MSIX on the Microsoft Store (x64 for now), which handles updates and the trial: 10 actions within 7 days, then buy once (€4.99). No account, no uploads, no watermark. Here's the 60-second trailer: https://youtu.be/SpEEDp_Ei20

Try it / tell me what breaks

It's early (v0.2), and I'd love feedback from people who live in Explorer. What file chore do you still open a website for?

I'm the developer of Morphalo. This post was drafted with help from an AI assistant and checked by me.

來源:DEV Community · dev.to