-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellExt.h
More file actions
74 lines (59 loc) · 2.36 KB
/
Copy pathShellExt.h
File metadata and controls
74 lines (59 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/////////////////////////////////////////////////////////////////////////////
// ShellExt.h
// Windows Shell Extension for File Organization
// Copyright (c) 2024. Licensed under MIT License.
/////////////////////////////////////////////////////////////////////////////
#pragma once
#include <windows.h>
#include <shlobj.h>
#include <string>
// {B743F9C1-0B24-4C9F-8EE1-C21F3C9A7747}
// Unique GUID for the shell extension
DEFINE_GUID(CLSID_FileOrganizerExt,
0xb743f9c1, 0x0b24, 0x4c9f, 0x8e, 0xe1, 0xc2, 0x1f, 0x3c, 0x9a, 0x77, 0x47);
class CShellExt : public IShellExtInit, public IContextMenu {
public:
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// IShellExtInit methods
STDMETHODIMP Initialize(LPCITEMIDLIST pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID);
// IContextMenu methods
STDMETHODIMP QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst,
UINT idCmdLast, UINT uFlags);
STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO pici);
STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pReserved,
LPSTR pszName, UINT cchMax);
CShellExt();
~CShellExt();
private:
// Helper methods
bool CreateFolderAndMoveFile();
std::wstring GetFileNameWithoutExtension(const std::wstring& filePath);
bool TriggerFolderRename(const std::wstring& folderPath);
// Member variables
long m_cRef; // Reference count
std::wstring m_szSelectedFile; // Path to the selected file
bool m_bIsFile; // Flag indicating if selection is a file
// Constants
static const UINT IDM_ORGANIZE = 0; // Command ID for the context menu
};
// Class factory for creating shell extension instances
class CShellExtClassFactory : public IClassFactory {
public:
// IUnknown methods
STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
STDMETHODIMP_(ULONG) AddRef();
STDMETHODIMP_(ULONG) Release();
// IClassFactory methods
STDMETHODIMP CreateInstance(IUnknown* pUnkOuter, REFIID riid, void** ppv);
STDMETHODIMP LockServer(BOOL fLock);
CShellExtClassFactory();
~CShellExtClassFactory();
private:
long m_cRef;
};
// Declare external variables
extern HINSTANCE g_hInst;
extern long g_cDllRef;