Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 2 | * |
| 3 | * VIM - Vi IMproved gvimext by Tianmiao Hu |
| 4 | * |
| 5 | * Do ":help uganda" in Vim to read copying and usage conditions. |
| 6 | * Do ":help credits" in Vim to see a list of people who contributed. |
| 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * If you have any questions or any suggestions concerning gvimext, please |
| 11 | * contact Tianmiao Hu: tianmiao@acm.org. |
| 12 | */ |
| 13 | |
| 14 | #if !defined(AFX_STDAFX_H__3389658B_AD83_11D3_9C1E_0090278BBD99__INCLUDED_) |
| 15 | #define AFX_STDAFX_H__3389658B_AD83_11D3_9C1E_0090278BBD99__INCLUDED_ |
| 16 | |
Bram Moolenaar | 175aa24 | 2010-02-17 17:24:27 +0100 | [diff] [blame] | 17 | #if defined(_MSC_VER) && _MSC_VER > 1000 |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 18 | #pragma once |
Bram Moolenaar | 175aa24 | 2010-02-17 17:24:27 +0100 | [diff] [blame] | 19 | #endif |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 20 | |
| 21 | // Insert your headers here |
| 22 | // #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers |
| 23 | |
| 24 | //-------------------------------------------------------------- |
| 25 | // common user interface routines |
| 26 | // |
| 27 | // |
| 28 | //-------------------------------------------------------------- |
| 29 | |
| 30 | #ifndef STRICT |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 31 | # define STRICT |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
Bram Moolenaar | 4f97475 | 2019-02-17 17:44:42 +0100 | [diff] [blame] | 34 | #define INC_OLE2 // MS-Windows, get ole2 from windows.h |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 35 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 36 | /* Visual Studio 2005 has 'deprecated' many of the standard CRT functions */ |
Bram Moolenaar | 175aa24 | 2010-02-17 17:24:27 +0100 | [diff] [blame] | 37 | #if defined(_MSC_VER) && _MSC_VER >= 1400 |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 38 | # define _CRT_SECURE_NO_DEPRECATE |
| 39 | # define _CRT_NONSTDC_NO_DEPRECATE |
| 40 | #endif |
| 41 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 42 | #include <windows.h> |
| 43 | #include <windowsx.h> |
| 44 | #include <shlobj.h> |
Bram Moolenaar | 271273c | 2016-02-21 20:30:22 +0100 | [diff] [blame] | 45 | #include <wchar.h> |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 46 | |
| 47 | #define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i))) |
| 48 | |
| 49 | // Initialize GUIDs (should be done only and at-least once per DLL/EXE) |
| 50 | // |
| 51 | #pragma data_seg(".text") |
| 52 | #define INITGUID |
| 53 | #include <initguid.h> |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 54 | |
| 55 | // |
| 56 | // The class ID of this Shell extension class. |
| 57 | // |
| 58 | // class id: {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 59 | // |
| 60 | // |
| 61 | // NOTE!!! If you use this shell extension as a starting point, |
| 62 | // you MUST change the GUID below. Simply run UUIDGEN.EXE |
| 63 | // to generate a new GUID. |
| 64 | // |
| 65 | |
| 66 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 67 | // static const GUID <<name>> = |
| 68 | // { 0x51eee242, 0xad87, 0x11d3, { 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99 } }; |
| 69 | // |
| 70 | // |
| 71 | |
| 72 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 73 | // IMPLEMENT_OLECREATE(<<class>>, <<external_name>>, |
| 74 | // 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99); |
| 75 | // |
| 76 | |
| 77 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} -- this is the registry format |
| 78 | DEFINE_GUID(CLSID_ShellExtension, 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99); |
| 79 | |
| 80 | // this class factory object creates context menu handlers for windows 32 shell |
| 81 | class CShellExtClassFactory : public IClassFactory |
| 82 | { |
| 83 | protected: |
K.Takata | 1271572 | 2023-05-25 16:43:27 +0100 | [diff] [blame] | 84 | ULONG m_cRef; |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 85 | |
| 86 | public: |
K.Takata | 1271572 | 2023-05-25 16:43:27 +0100 | [diff] [blame] | 87 | CShellExtClassFactory(); |
| 88 | ~CShellExtClassFactory(); |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 89 | |
K.Takata | 1271572 | 2023-05-25 16:43:27 +0100 | [diff] [blame] | 90 | //IUnknown members |
| 91 | STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); |
| 92 | STDMETHODIMP_(ULONG) AddRef(); |
| 93 | STDMETHODIMP_(ULONG) Release(); |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 94 | |
K.Takata | 1271572 | 2023-05-25 16:43:27 +0100 | [diff] [blame] | 95 | //IClassFactory members |
| 96 | STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *); |
| 97 | STDMETHODIMP LockServer(BOOL); |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 98 | }; |
| 99 | typedef CShellExtClassFactory *LPCSHELLEXTCLASSFACTORY; |
| 100 | #define MAX_HWND 100 |
| 101 | |
| 102 | // this is the actual OLE Shell context menu handler |
| 103 | class CShellExt : public IContextMenu, |
| 104 | IShellExtInit |
| 105 | { |
Bram Moolenaar | 7bc25ae | 2015-05-04 18:27:36 +0200 | [diff] [blame] | 106 | private: |
| 107 | BOOL LoadMenuIcon(); |
| 108 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 109 | protected: |
| 110 | ULONG m_cRef; |
| 111 | LPDATAOBJECT m_pDataObj; |
| 112 | UINT m_edit_existing_off; |
Bram Moolenaar | 7bc25ae | 2015-05-04 18:27:36 +0200 | [diff] [blame] | 113 | HBITMAP m_hVimIconBitmap; |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 114 | |
| 115 | // For some reason, this callback must be static |
| 116 | static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); |
| 117 | |
| 118 | STDMETHODIMP PushToWindow(HWND hParent, |
| 119 | LPCSTR pszWorkingDir, |
| 120 | LPCSTR pszCmd, |
| 121 | LPCSTR pszParam, |
| 122 | int iShowCmd, |
| 123 | int idHWnd); |
| 124 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 125 | STDMETHODIMP InvokeSingleGvim(HWND hParent, |
Nir Lichtman | 1aeccdb | 2021-12-22 15:21:15 +0000 | [diff] [blame] | 126 | LPCWSTR workingDir, |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 127 | LPCSTR pszCmd, |
| 128 | LPCSTR pszParam, |
| 129 | int iShowCmd, |
msoyka-of-wharton | 83cd015 | 2021-07-29 19:18:33 +0200 | [diff] [blame] | 130 | int gvimExtraOptions); |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 131 | |
| 132 | public: |
| 133 | int m_cntOfHWnd; |
| 134 | HWND m_hWnd[MAX_HWND]; |
| 135 | CShellExt(); |
| 136 | ~CShellExt(); |
| 137 | |
| 138 | //IUnknown members |
| 139 | STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); |
| 140 | STDMETHODIMP_(ULONG) AddRef(); |
| 141 | STDMETHODIMP_(ULONG) Release(); |
| 142 | |
| 143 | //IShell members |
| 144 | STDMETHODIMP QueryContextMenu(HMENU hMenu, |
| 145 | UINT indexMenu, |
| 146 | UINT idCmdFirst, |
| 147 | UINT idCmdLast, |
| 148 | UINT uFlags); |
| 149 | |
| 150 | STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); |
| 151 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 152 | STDMETHODIMP GetCommandString(UINT_PTR idCmd, |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 153 | UINT uFlags, |
| 154 | UINT FAR *reserved, |
| 155 | LPSTR pszName, |
| 156 | UINT cchMax); |
| 157 | |
| 158 | //IShellExtInit methods |
| 159 | STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, |
| 160 | LPDATAOBJECT pDataObj, |
| 161 | HKEY hKeyID); |
| 162 | }; |
| 163 | |
| 164 | typedef CShellExt *LPCSHELLEXT; |
| 165 | #pragma data_seg() |
| 166 | |
| 167 | #endif |