[File Locksmith] Add context menu icon (#24986)

* Add FLS icon

* fix icon include

* fix

* final code fix
This commit is contained in:
Heiko
2023-03-24 10:51:03 +01:00
committed by GitHub
parent ac8c0324e2
commit 803476dcee
5 changed files with 32 additions and 28 deletions

View File

@@ -7,6 +7,9 @@
#include "Trace.h"
#include "Generated Files/resource.h"
#include <common/themes/icon_helpers.h>
#include <common/utils/process_path.h>
// Implementations of inherited IUnknown methods
IFACEMETHODIMP ExplorerCommand::QueryInterface(REFIID riid, void** ppv)
@@ -46,9 +49,10 @@ IFACEMETHODIMP ExplorerCommand::GetTitle(IShellItemArray* psiItemArray, LPWSTR*
IFACEMETHODIMP ExplorerCommand::GetIcon(IShellItemArray* psiItemArray, LPWSTR* ppszIcon)
{
// Path to the icon should be computed relative to the path of this module
ppszIcon = NULL;
return E_NOTIMPL;
std::wstring iconResourcePath = get_module_filename();
iconResourcePath += L",-";
iconResourcePath += std::to_wstring(IDI_FILELOCKSMITH);
return SHStrDup(iconResourcePath.c_str(), ppszIcon);
}
IFACEMETHODIMP ExplorerCommand::GetToolTip(IShellItemArray* psiItemArray, LPWSTR* ppszInfotip)
@@ -129,7 +133,18 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI
mii.fState = MFS_ENABLED;
// TODO icon from file
// icon from file
HICON hIcon = static_cast<HICON>(LoadImage(globals::instance, MAKEINTRESOURCE(IDI_FILELOCKSMITH), IMAGE_ICON, 16, 16, 0));
if (hIcon)
{
mii.fMask |= MIIM_BITMAP;
if (m_hbmpIcon == NULL)
{
m_hbmpIcon = CreateBitmapFromIcon(hIcon);
}
mii.hbmpItem = m_hbmpIcon;
DestroyIcon(hIcon);
}
if (!InsertMenuItem(hmenu, indexMenu, TRUE, &mii))
{
@@ -226,30 +241,6 @@ ExplorerCommand::~ExplorerCommand()
--globals::ref_count;
}
// Implementation taken from src/common/utils
// TODO reference that function
inline std::wstring get_module_folderpath(HMODULE mod = nullptr, const bool removeFilename = true)
{
wchar_t buffer[MAX_PATH + 1];
DWORD actual_length = GetModuleFileNameW(mod, buffer, MAX_PATH + 1);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
const DWORD long_path_length = 0xFFFF; // should be always enough
std::wstring long_filename(long_path_length, L'\0');
actual_length = GetModuleFileNameW(mod, long_filename.data(), long_path_length);
PathRemoveFileSpecW(long_filename.data());
long_filename.resize(std::wcslen(long_filename.data()));
long_filename.shrink_to_fit();
return long_filename;
}
if (removeFilename)
{
PathRemoveFileSpecW(buffer);
}
return { buffer, static_cast<UINT>(lstrlenW(buffer)) };
}
HRESULT ExplorerCommand::LaunchUI(CMINVOKECOMMANDINFO* pici, ipc::Writer* writer)
{
// Compute exe path

View File

@@ -42,6 +42,8 @@ public:
~ExplorerCommand();
private:
HBITMAP m_hbmpIcon = nullptr;
// Helpers
HRESULT LaunchUI(CMINVOKECOMMANDINFO* pici, ipc::Writer* writer);

View File

@@ -48,3 +48,10 @@ BEGIN
VALUE "Translation", 0x409, 1200
END
END
// Non-localizable
//////////////////////////////
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_FILELOCKSMITH ICON "..\\FileLocksmithUI\\Assets\\Icon.ico"

View File

@@ -280,6 +280,9 @@
<ProjectReference Include="..\..\..\common\SettingsAPI\SettingsAPI.vcxproj">
<Project>{6955446d-23f7-4023-9bb3-8657f904af99}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\common\Themes\Themes.vcxproj">
<Project>{98537082-0fdb-40de-abd8-0dc5a4269bab}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\common\version\version.vcxproj">
<Project>{cc6e41ac-8174-4e8a-8d22-85dd7f4851df}</Project>
</ProjectReference>

View File

@@ -8,6 +8,7 @@
#define FILE_DESCRIPTION "PowerToys File Locksmith Static Library"
#define INTERNAL_NAME "PowerToys.FileLocksmithLib.lib"
#define ORIGINAL_FILENAME "PowerToys.FileLocksmithLib.lib"
#define IDI_FILELOCKSMITH 1001
// Non-localizable
//////////////////////////////