blob: e17f2ac2c946eeda7d52dca09bc99a8b4a3108ac [file] [log] [blame]
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00001/* 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 Moolenaar175aa242010-02-17 17:24:27 +010017#if defined(_MSC_VER) && _MSC_VER > 1000
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000018#pragma once
Bram Moolenaar175aa242010-02-17 17:24:27 +010019#endif
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000020
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 Moolenaarf9393ef2006-04-24 19:47:27 +000031# define STRICT
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000032#endif
33
34#define INC_OLE2 // WIN32, get ole2 from windows.h
35
Bram Moolenaar362e1a32006-03-06 23:29:24 +000036/* Visual Studio 2005 has 'deprecated' many of the standard CRT functions */
Bram Moolenaar175aa242010-02-17 17:24:27 +010037#if defined(_MSC_VER) && _MSC_VER >= 1400
Bram Moolenaar362e1a32006-03-06 23:29:24 +000038# define _CRT_SECURE_NO_DEPRECATE
39# define _CRT_NONSTDC_NO_DEPRECATE
40#endif
41
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000042#include <windows.h>
43#include <windowsx.h>
44#include <shlobj.h>
Bram Moolenaar271273c2016-02-21 20:30:22 +010045#include <wchar.h>
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000046
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000047/* Accommodate old versions of VC that don't have a modern Platform SDK */
Bram Moolenaar167632f2010-05-26 21:42:54 +020048#if (defined(_MSC_VER) && _MSC_VER < 1300) || !defined(MAXULONG_PTR)
Bram Moolenaarf9393ef2006-04-24 19:47:27 +000049# undef UINT_PTR
50# define UINT_PTR UINT
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000051#endif
52
Bram Moolenaarf4b8e572004-06-24 15:53:16 +000053#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>
60#include <shlguid.h>
61
62//
63// The class ID of this Shell extension class.
64//
65// class id: {51EEE242-AD87-11d3-9C1E-0090278BBD99}
66//
67//
68// NOTE!!! If you use this shell extension as a starting point,
69// you MUST change the GUID below. Simply run UUIDGEN.EXE
70// to generate a new GUID.
71//
72
73// {51EEE242-AD87-11d3-9C1E-0090278BBD99}
74// static const GUID <<name>> =
75// { 0x51eee242, 0xad87, 0x11d3, { 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99 } };
76//
77//
78
79// {51EEE242-AD87-11d3-9C1E-0090278BBD99}
80// IMPLEMENT_OLECREATE(<<class>>, <<external_name>>,
81// 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99);
82//
83
84// {51EEE242-AD87-11d3-9C1E-0090278BBD99} -- this is the registry format
85DEFINE_GUID(CLSID_ShellExtension, 0x51eee242, 0xad87, 0x11d3, 0x9c, 0x1e, 0x0, 0x90, 0x27, 0x8b, 0xbd, 0x99);
86
87// this class factory object creates context menu handlers for windows 32 shell
88class CShellExtClassFactory : public IClassFactory
89{
90protected:
91 ULONG m_cRef;
92
93public:
94 CShellExtClassFactory();
95 ~CShellExtClassFactory();
96
97 //IUnknown members
98 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
99 STDMETHODIMP_(ULONG) AddRef();
100 STDMETHODIMP_(ULONG) Release();
101
102 //IClassFactory members
103 STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *);
104 STDMETHODIMP LockServer(BOOL);
105
106};
107typedef CShellExtClassFactory *LPCSHELLEXTCLASSFACTORY;
108#define MAX_HWND 100
109
110// this is the actual OLE Shell context menu handler
111class CShellExt : public IContextMenu,
112 IShellExtInit
113{
Bram Moolenaar7bc25ae2015-05-04 18:27:36 +0200114private:
115 BOOL LoadMenuIcon();
116
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000117protected:
118 ULONG m_cRef;
119 LPDATAOBJECT m_pDataObj;
120 UINT m_edit_existing_off;
Bram Moolenaar7bc25ae2015-05-04 18:27:36 +0200121 HBITMAP m_hVimIconBitmap;
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000122
123 // For some reason, this callback must be static
124 static BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam);
125
126 STDMETHODIMP PushToWindow(HWND hParent,
127 LPCSTR pszWorkingDir,
128 LPCSTR pszCmd,
129 LPCSTR pszParam,
130 int iShowCmd,
131 int idHWnd);
132
133 STDMETHODIMP InvokeGvim(HWND hParent,
134 LPCSTR pszWorkingDir,
135 LPCSTR pszCmd,
136 LPCSTR pszParam,
137 int iShowCmd);
138
139 STDMETHODIMP InvokeSingleGvim(HWND hParent,
140 LPCSTR pszWorkingDir,
141 LPCSTR pszCmd,
142 LPCSTR pszParam,
143 int iShowCmd,
144 int useDiff);
145
146public:
147 int m_cntOfHWnd;
148 HWND m_hWnd[MAX_HWND];
149 CShellExt();
150 ~CShellExt();
151
152 //IUnknown members
153 STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *);
154 STDMETHODIMP_(ULONG) AddRef();
155 STDMETHODIMP_(ULONG) Release();
156
157 //IShell members
158 STDMETHODIMP QueryContextMenu(HMENU hMenu,
159 UINT indexMenu,
160 UINT idCmdFirst,
161 UINT idCmdLast,
162 UINT uFlags);
163
164 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi);
165
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000166 STDMETHODIMP GetCommandString(UINT_PTR idCmd,
Bram Moolenaarf4b8e572004-06-24 15:53:16 +0000167 UINT uFlags,
168 UINT FAR *reserved,
169 LPSTR pszName,
170 UINT cchMax);
171
172 //IShellExtInit methods
173 STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder,
174 LPDATAOBJECT pDataObj,
175 HKEY hKeyID);
176};
177
178typedef CShellExt *LPCSHELLEXT;
179#pragma data_seg()
180
181#endif