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 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 47 | /* Accommodate old versions of VC that don't have a modern Platform SDK */ |
Bram Moolenaar | 167632f | 2010-05-26 21:42:54 +0200 | [diff] [blame] | 48 | #if (defined(_MSC_VER) && _MSC_VER < 1300) || !defined(MAXULONG_PTR) |
Bram Moolenaar | f9393ef | 2006-04-24 19:47:27 +0000 | [diff] [blame] | 49 | # undef UINT_PTR |
| 50 | # define UINT_PTR UINT |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 51 | #endif |
| 52 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 53 | #define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i))) |
| 54 | |
| 55 | // Initialize GUIDs (should be done only and at-least once per DLL/EXE) |
| 56 | // |
| 57 | #pragma data_seg(".text") |
| 58 | #define INITGUID |
| 59 | #include <initguid.h> |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 60 | |
| 61 | // |
| 62 | // The class ID of this Shell extension class. |
| 63 | // |
| 64 | // class id: {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 65 | // |
| 66 | // |
| 67 | // NOTE!!! If you use this shell extension as a starting point, |
| 68 | // you MUST change the GUID below. Simply run UUIDGEN.EXE |
| 69 | // to generate a new GUID. |
| 70 | // |
| 71 | |
| 72 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 73 | // static const GUID <<name>> = |
| 74 | // { 0x51eee242, 0xad87, 0x11d3, { 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99 } }; |
| 75 | // |
| 76 | // |
| 77 | |
| 78 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} |
| 79 | // IMPLEMENT_OLECREATE(<<class>>, <<external_name>>, |
| 80 | // 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99); |
| 81 | // |
| 82 | |
| 83 | // {51EEE242-AD87-11d3-9C1E-0090278BBD99} -- this is the registry format |
| 84 | DEFINE_GUID(CLSID_ShellExtension, 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99); |
| 85 | |
| 86 | // this class factory object creates context menu handlers for windows 32 shell |
| 87 | class CShellExtClassFactory : public IClassFactory |
| 88 | { |
| 89 | protected: |
| 90 | ULONG m_cRef; |
| 91 | |
| 92 | public: |
| 93 | CShellExtClassFactory(); |
| 94 | ~CShellExtClassFactory(); |
| 95 | |
| 96 | //IUnknown members |
| 97 | STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); |
| 98 | STDMETHODIMP_(ULONG) AddRef(); |
| 99 | STDMETHODIMP_(ULONG) Release(); |
| 100 | |
| 101 | //IClassFactory members |
| 102 | STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *); |
| 103 | STDMETHODIMP LockServer(BOOL); |
| 104 | |
| 105 | }; |
| 106 | typedef CShellExtClassFactory *LPCSHELLEXTCLASSFACTORY; |
| 107 | #define MAX_HWND 100 |
| 108 | |
| 109 | // this is the actual OLE Shell context menu handler |
| 110 | class CShellExt : public IContextMenu, |
| 111 | IShellExtInit |
| 112 | { |
Bram Moolenaar | 7bc25ae | 2015-05-04 18:27:36 +0200 | [diff] [blame] | 113 | private: |
| 114 | BOOL LoadMenuIcon(); |
| 115 | |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 116 | protected: |
| 117 | ULONG m_cRef; |
| 118 | LPDATAOBJECT m_pDataObj; |
| 119 | UINT m_edit_existing_off; |
Bram Moolenaar | 7bc25ae | 2015-05-04 18:27:36 +0200 | [diff] [blame] | 120 | HBITMAP m_hVimIconBitmap; |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 121 | |
| 122 | // For some reason, this callback must be static |
| 123 | static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam); |
| 124 | |
| 125 | STDMETHODIMP PushToWindow(HWND hParent, |
| 126 | LPCSTR pszWorkingDir, |
| 127 | LPCSTR pszCmd, |
| 128 | LPCSTR pszParam, |
| 129 | int iShowCmd, |
| 130 | int idHWnd); |
| 131 | |
| 132 | STDMETHODIMP InvokeGvim(HWND hParent, |
| 133 | LPCSTR pszWorkingDir, |
| 134 | LPCSTR pszCmd, |
| 135 | LPCSTR pszParam, |
| 136 | int iShowCmd); |
| 137 | |
| 138 | STDMETHODIMP InvokeSingleGvim(HWND hParent, |
| 139 | LPCSTR pszWorkingDir, |
| 140 | LPCSTR pszCmd, |
| 141 | LPCSTR pszParam, |
| 142 | int iShowCmd, |
| 143 | int useDiff); |
| 144 | |
| 145 | public: |
| 146 | int m_cntOfHWnd; |
| 147 | HWND m_hWnd[MAX_HWND]; |
| 148 | CShellExt(); |
| 149 | ~CShellExt(); |
| 150 | |
| 151 | //IUnknown members |
| 152 | STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); |
| 153 | STDMETHODIMP_(ULONG) AddRef(); |
| 154 | STDMETHODIMP_(ULONG) Release(); |
| 155 | |
| 156 | //IShell members |
| 157 | STDMETHODIMP QueryContextMenu(HMENU hMenu, |
| 158 | UINT indexMenu, |
| 159 | UINT idCmdFirst, |
| 160 | UINT idCmdLast, |
| 161 | UINT uFlags); |
| 162 | |
| 163 | STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); |
| 164 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 165 | STDMETHODIMP GetCommandString(UINT_PTR idCmd, |
Bram Moolenaar | f4b8e57 | 2004-06-24 15:53:16 +0000 | [diff] [blame] | 166 | UINT uFlags, |
| 167 | UINT FAR *reserved, |
| 168 | LPSTR pszName, |
| 169 | UINT cchMax); |
| 170 | |
| 171 | //IShellExtInit methods |
| 172 | STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, |
| 173 | LPDATAOBJECT pDataObj, |
| 174 | HKEY hKeyID); |
| 175 | }; |
| 176 | |
| 177 | typedef CShellExt *LPCSHELLEXT; |
| 178 | #pragma data_seg() |
| 179 | |
| 180 | #endif |