From ff391d9a6afb856e20e827edbad0aff9e6caffe3 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Mon, 6 Jul 2020 18:00:25 +0200 Subject: Windows: Support direct password drag-n-drop from external applications (e.g. KeePass) which is more secure than using clipboard. --- src/Common/Dlgcode.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/Common/Dlgcode.h') diff --git a/src/Common/Dlgcode.h b/src/Common/Dlgcode.h index 9e77c0a9..52d94f10 100644 --- a/src/Common/Dlgcode.h +++ b/src/Common/Dlgcode.h @@ -691,6 +691,61 @@ typedef void (CALLBACK* WaitThreadProc)(void* pArg, HWND hWaitDlg); void BringToForeground(HWND hWnd); void ShowWaitDialog(HWND hwnd, BOOL bUseHwndAsParent, WaitThreadProc callback, void* pArg); +// classes used to implement support for password drag-n-drop from KeePass Password Safe +// Implementation based the following source code with many modifications to fix isses and add features +// URL: https://www.codeguru.com/cpp/misc/misc/draganddrop/article.php/c349/Drag-And-Drop-between-Window-Controls.htm + +interface GenericDropTarget : public IDropTarget +{ +public: + GenericDropTarget(CLIPFORMAT* pFormats, size_t count); + ~GenericDropTarget(); + + // basic IUnknown stuff + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject); + ULONG STDMETHODCALLTYPE AddRef(void); + ULONG STDMETHODCALLTYPE Release(void); + + HRESULT STDMETHODCALLTYPE DragEnter(struct IDataObject *,unsigned long,struct _POINTL,unsigned long *); + HRESULT STDMETHODCALLTYPE DragOver(unsigned long,struct _POINTL,unsigned long *); + HRESULT STDMETHODCALLTYPE DragLeave(void); + HRESULT STDMETHODCALLTYPE Drop(struct IDataObject *,unsigned long,struct _POINTL,unsigned long *); + + // called by parents + BOOL Register(HWND hWnd); + void Revoke(); + + // call parent we have goodies + virtual void GotDrop(CLIPFORMAT format); + virtual DWORD GotDrag(void); + virtual void GotLeave(void); + virtual DWORD GotEnter(void); +public: + BYTE *m_Data; + + POINT m_DropPoint; + + DWORD m_KeyState; + +protected: + HWND m_DropTargetWnd; + std::vector m_SupportedFormat; + volatile LONG m_dwRefCount; +}; + +class PasswordEditDropTarget : public GenericDropTarget +{ +public: + PasswordEditDropTarget(); + + // called by child we have drop + void GotDrop(CLIPFORMAT format); + DWORD GotDrag(void); + void GotLeave(void); + DWORD GotEnter(void); +}; + + #endif // __cplusplus #endif // TC_HEADER_DLGCODE -- cgit v1.2.3