Skip to content

Commit

Permalink
Added icon to Resize pictures context menu entry (dev/imageResizer) (#…
Browse files Browse the repository at this point in the history
…1113)

* Updated vcxproj file with common project references and cpp version flags

* Added module template code to dllmain and updated headers for successful build

* Removed unnecessary include

* Added dll to runner and add fixes to show up in PT Settings

* Added settings file

* Added support for enabling/disabling based on PowerRename codebase

* Fixed solution file configurations

* Removed Any CPU from ImageResizer csprojs

* Renamed registry writing and removed build time registry addition

* Added ImageResizer installation details to msi

* Shifted to MII, TODO: Fix position

* Incorporated ImageResizer Icon in context menu entry

* Fixed typo

* Merged with dev/imageResizer
  • Loading branch information
arjunbalgovind authored Jan 21, 2020
1 parent 2485b5b commit 8ab10b5
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 10 deletions.
44 changes: 35 additions & 9 deletions src/modules/imageresizer/ShellExtensions/ContextMenuHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "ContextMenuHandler.h"
#include "HDropIterator.h"
#include "Settings.h"
#include "common/icon_helpers.h"

extern HINSTANCE g_hInst_imageResizer;

CContextMenuHandler::CContextMenuHandler()
{
Expand Down Expand Up @@ -66,36 +69,59 @@ HRESULT CContextMenuHandler::QueryContextMenu(_In_ HMENU hmenu, UINT indexMenu,
LPTSTR pszPath = i.CurrentItem();
LPTSTR pszExt = PathFindExtension(pszPath);

// TODO: Instead, detech whether there's a WIC codec installd that can handle this file (issue #7)
// TODO: Instead, detect whether there's a WIC codec installed that can handle this file
AssocGetPerceivedType(pszExt, &type, &flag, NULL);

free(pszPath);

// If selected file is an image...
if (type == PERCEIVED_TYPE_IMAGE)
{
CString strResizePictures;

HRESULT hr = E_UNEXPECTED;
wchar_t strResizePictures[64] = { 0 };
// If handling drag-and-drop...
if (m_pidlFolder)
{
// Suppressing C6031 warning since return value is not required.
#pragma warning(suppress : 6031)
// Load 'Resize pictures here' string
strResizePictures.LoadString(IDS_RESIZE_PICTURES_HERE);
LoadString(g_hInst_imageResizer, IDS_RESIZE_PICTURES_HERE, strResizePictures, ARRAYSIZE(strResizePictures));
}
else
{
// Suppressing C6031 warning since return value is not required.
#pragma warning(suppress : 6031)
// Load 'Resize pictures' string
strResizePictures.LoadString(IDS_RESIZE_PICTURES);
LoadString(g_hInst_imageResizer, IDS_RESIZE_PICTURES, strResizePictures, ARRAYSIZE(strResizePictures));
}

// Add menu item
InsertMenu(hmenu, indexMenu, MF_BYPOSITION, idCmdFirst + ID_RESIZE_PICTURES, strResizePictures);

return MAKE_HRESULT(SEVERITY_SUCCESS, 0, ID_RESIZE_PICTURES + 1);
MENUITEMINFO mii;
mii.cbSize = sizeof(MENUITEMINFO);
mii.fMask = MIIM_STRING | MIIM_FTYPE | MIIM_ID | MIIM_STATE;
mii.wID = idCmdFirst + ID_RESIZE_PICTURES;
mii.fType = MFT_STRING;
mii.dwTypeData = (PWSTR)strResizePictures;
mii.fState = MFS_ENABLED;
HICON hIcon = (HICON)LoadImage(g_hInst_imageResizer, MAKEINTRESOURCE(IDI_RESIZE_PICTURES), 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))
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
else
{
hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 1);
}
return hr;
}

return S_OK;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ATL_NO_VTABLE CContextMenuHandler :
HRESULT ResizePictures(CMINVOKECOMMANDINFO* pici);
PCIDLIST_ABSOLUTE m_pidlFolder;
IDataObject* m_pdtobj;
HBITMAP m_hbmpIcon = nullptr;
};

OBJECT_ENTRY_AUTO(__uuidof(ContextMenuHandler), CContextMenuHandler)
OBJECT_ENTRY_AUTO(__uuidof(ContextMenuHandler), CContextMenuHandler)
Binary file modified src/modules/imageresizer/ShellExtensions/ShellExtensions.rc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@
<Project>{74485049-c722-400f-abe5-86ac52d929b3}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Image Include="..\ImageResizer\Resources\ImageResizer.ico" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@
<Filter>Source Files</Filter>
</Midl>
</ItemGroup>
<ItemGroup>
<Image Include="..\ImageResizer\Resources\ImageResizer.ico">
<Filter>Resource Files</Filter>
</Image>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/modules/imageresizer/ShellExtensions/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
#include "Settings.h"

CShellExtensionsModule _AtlModule;
HINSTANCE g_hInst_imageResizer = 0;

extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
switch (dwReason)
{
case DLL_PROCESS_ATTACH:
g_hInst_imageResizer = hInstance;
}
return _AtlModule.DllMain(dwReason, lpReserved);
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/imageresizer/ShellExtensions/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define IDS_RESIZE_PICTURES_HERE 101
#define IDR_SHELLEXTENSIONS 101
#define IDR_CONTEXTMENUHANDLER 102
#define IDI_RESIZE_PICTURES 103

// Next default values for new objects
//
Expand Down

0 comments on commit 8ab10b5

Please sign in to comment.