📄 oledragdropexptoolbarctrl.h
字号:
#pragma once
#include "ExplorerToolBarCtrl.h"
template <class T>
class COleDragDrogExplorerToolBarCtrlImpl :
public CExplorerToolBarCtrlImpl<T>,
public IDropTargetImpl<T>,
public IDropSourceImpl<T>
{
public:
DECLARE_WND_SUPERCLASS(NULL, CToolBarCtrl::GetWndClassName())
typedef CExplorerToolBarCtrlImpl<T> baseClass;
// Data members
bool m_bDragAccept;
bool m_bRButtonDown;
int m_nDraggingCmdID;
int m_nCurrentDrop;
// Ctor
COleDragDrogExplorerToolBarCtrlImpl(int nInsertPointMenuItemID, int nMinID, int nMaxID)
: baseClass(nInsertPointMenuItemID, nMinID, nMaxID),
m_bDragAccept(false), m_bRButtonDown(false), m_nDraggingCmdID(-1), m_nCurrentDrop(-1)
{
}
// Overrides
void OnInitExplorerToolBarCtrl()
{
RegisterDragDrop();
}
void OnTermExplorerToolBarCtrl()
{
RevokeDragDrop();
}
HRESULT OnGetExplorerToolBarDataObject(int nCmdID, IDataObject** ppDataObject)
{
ATLASSERT(ppDataObject != NULL);
CString strUrl = _GetPathFromCmdID(nCmdID);
ATLASSERT(!strUrl.IsEmpty());
MtlRemoveTrailingBackSlash(strUrl);
HRESULT hr = CHlinkDataObject::_CreatorClass::CreateInstance(NULL, IID_IDataObject, (void**)ppDataObject);
if (FAILED(hr)) {
*ppDataObject = NULL;
return E_NOTIMPL;
}
#ifdef _ATL_DEBUG_INTERFACES
ATLASSERT(FALSE && _T("_ATL_DEBUG_INTERFACES crashes the following\n"));
#endif
CHlinkDataObject* pHlinkDataObject = NULL;// this is hack, no need to release
hr = (*ppDataObject)->QueryInterface(IID_NULL, (void**)&pHlinkDataObject);
if (SUCCEEDED(hr)) {
pHlinkDataObject->m_arrNameAndUrl.Add(std::make_pair(CString(),strUrl));
return S_OK;
}
return E_NOTIMPL;
}
// Message map and handlers
BEGIN_MSG_MAP(COleDragDrogExplorerToolBarCtrlImpl<T>)
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
CHAIN_MSG_MAP(baseClass)
ALT_MSG_MAP(1)
CHAIN_MSG_MAP_ALT(baseClass, 1)
END_MSG_MAP()
LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
LRESULT lRet = DefWindowProc();// required
int nCmdID = _HitTestCmdID(pt);
if (nCmdID == -1) {
return 0;
}
_DoDragDrop(nCmdID, pt, (UINT)wParam, true);
return lRet;
}
LRESULT OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
int nCmdID = _HitTestCmdID(pt);
if (nCmdID == -1) {
return 0;
}
_DoDragDrop(nCmdID, pt, (UINT)wParam, false);
return 0;
}
// IDropTarget
DROPEFFECT OnDragEnter(IDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
m_bDragAccept = _MtlIsHlinkDataObject(pDataObject);
if (!m_bDragAccept)
return DROPEFFECT_NONE;
m_bRButtonDown = ::GetAsyncKeyState(VK_RBUTTON) < 0;
return _MtlStandardDropEffect(dwKeyState);
}
DROPEFFECT OnDragOver(IDataObject* pDataObject, DWORD dwKeyState, CPoint point, DROPEFFECT dropOkEffect)
{
if (!m_bDragAccept)
return DROPEFFECT_NONE;
int nID = _HitTestCmdID(point);
if (nID != -1) {
if (m_nCurrentDrop != nID)
MarkButton(m_nCurrentDrop, FALSE);
MarkButton(m_nCurrentDrop = nID, TRUE);
if (m_nDraggingCmdID == nID)
return DROPEFFECT_NONE;
}
else {
OnDragLeave();
}
if (m_nDraggingCmdID != -1)
return _MtlStandardDropEffect(dwKeyState);
else
return _MtlStandardDropEffect(dwKeyState) | _MtlFollowDropEffect(dropOkEffect);
}
DROPEFFECT OnDrop(IDataObject* pDataObject, DROPEFFECT dropEffect, DROPEFFECT dropEffectList, CPoint point)
{
DROPEFFECT dropResult = DROPEFFECT_NONE;
MarkButton(m_nCurrentDrop, FALSE);
CString strFolder, strPath;
_HitTest(point, strFolder, strPath);
if (strFolder.IsEmpty() && strPath.IsEmpty())
return DROPEFFECT_NONE;
// first, file dropped or not
CSimpleArray<CString> arrFiles;
if (MtlGetDropFileName(pDataObject, arrFiles)) {
if (m_bRButtonDown && !strPath.IsEmpty()) {
if (MtlOnRButtonDropOpenFromApp(m_hWnd, point, strPath, arrFiles[0]))
return dropResult;
}
if (m_bRButtonDown && MtlOnRButtonDrop(m_hWnd, dropEffect, point))
return dropResult;
if (dropEffect & DROPEFFECT_COPY) {
if (MtlCopyFile(strFolder, arrFiles)) {
dropResult = DROPEFFECT_COPY;
}
}
else if (dropEffect & DROPEFFECT_MOVE) {
if (MtlMoveFile(strFolder, arrFiles)) {
dropResult = DROPEFFECT_MOVE;
}
}
else if (dropEffect & DROPEFFECT_LINK) {
dropResult = DROPEFFECT_LINK;
MtlMakeSureTrailingBackSlash(strFolder);
for (int i = 0; i < arrFiles.GetSize(); ++i) {
MtlCreateShortCutFile(strFolder + MtlGetDisplayTextFromPath(arrFiles[i]) + _T("傊偺籍澳动
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -