Code Monkey home page Code Monkey logo

openwithmenu's Introduction

OpenWithMenu

  • A Windows extension which is used to open applications quickly through context menu.

Environment

  • Visual Studio 2019 (msvc2019)
  • Windows 10 21H2 x64

Build and Register

  1. Use Visual Studio to build x64 OpenWithMenu.dll
  2. Open cmd as administrator and register
Register.bat
# or
regsvr32 x64\Release\OpenWithMenu.dll
  1. Setup registry for background's context menu
Register.reg

# [HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\OpenWithMenu]
# @="{33f3c901-789f-4e96-82d5-32b1cb204b40}"

Unregister

  1. Open cmd as administrator and unregister
Unregister.bat
# or
regsvr32 /u x64\Release\OpenWithMenu.dll
  1. Remove background's context menu through registry
Unregister.reg

# [-HKEY_CLASSES_ROOT\Directory\Background\shellex\ContextMenuHandlers\OpenWithMenu]

Configure

; Use DemoMenu.reg to add demo menu

[HKEY_CURRENT_USER\SOFTWARE\AoiHosizora\OpenWithMenu]
"Name"="Open folder with"
"SettingName"="Setting"

[HKEY_CURRENT_USER\SOFTWARE\AoiHosizora\OpenWithMenu\01 cmd]
@="Command prompt"
"File"="cmd.exe"
"Icon"="cmd.exe"

[HKEY_CURRENT_USER\SOFTWARE\AoiHosizora\OpenWithMenu\02 cmd admin]
@="Command prompt (Admin)"
"File"="cmd.exe"
"Icon"="cmd.exe"
"Operation"="runas"
"Parameter"="/s /k pushd \"%V\""

Root key

  • Name - Menu title, defaults to Open folder with
  • Icon - Menu icon, supports both exe and ico path
  • SettingName - Setting menu title, defaults to Setting

Sub key

  • Note that only those menu items which has non empty @ and File will be shown.
  • Some of theme arguments have the same meaning of ShellExecuteW, see ShellExecuteW function (shellapi.h).
  • key name - Menu ID, required, items will be sorted by this value
  • @ - Menu title, required
  • File - Executable file path, required
  • Icon - Menu icon, supports both exe and ico path
  • Operation - Execute operation, defaults to open, it can be set to runas to execute as administrator
    • Execute with open operation usually can detect the current path, but runas cannot, so it need to use Parameter: %V
    • Command prompt example: File: cmd.exe; Operation: runas; Parameter: /s /k pushd "%V"
    • Powershell example: File: powershell.exe; Operation: runas; Parameter: -noexit -command Set-Location -literalPath '%V'
  • Parameter - Execute parameter, optional, and note that %V means the current path
    • Example for executing ping command: File: cmd.exe; Parameter: /c ping www.google.co.jp
  • Directory - Working directory to execute file, defaults to %V
  • Style - Window style to execute file, defaults to SW_NORMAL, it can be set to SW_HIDE or 0 to hide window

Screenshots

screenshot1 screenshot2

References

openwithmenu's People

Contributors

aoi-hosizora avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

openwithmenu's Issues

Crash when use some icons

Here I use "D:\\Program Files\\DAEMON Tools Lite\\DTLauncher.exe" as my Icon key's value, and the explorer will crash when context menu shown.

static HICON GetSmallIcon(const std::wstring &path) {
HICON largeIcon, smallIcon;
int num = ExtractIconEx(path.c_str(), -1, nullptr, nullptr, 0);
if (num <= 0) {
return nullptr;
}
ExtractIconEx(path.c_str(), 0, &largeIcon, &smallIcon, num);
return smallIcon;
}

static HBITMAP GetBitmapFromIcon(HICON hicon) {
UINT uWidth = GetSystemMetrics(SM_CXSMICON);
UINT uHeight = GetSystemMetrics(SM_CYSMICON);
HBITMAP hbmp = CreateBitmapARGB(uWidth, uHeight);
HDC hdcMem = CreateCompatibleDC(nullptr);
auto hbmpPrev = (HBITMAP) SelectObject(hdcMem, hbmp);
DrawIconEx(hdcMem, 0, 0, hicon, uWidth, uHeight, 0, nullptr, DI_NORMAL);
SelectObject(hdcMem, hbmpPrev);
DeleteDC(hdcMem);
return hbmp;
}

image

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.