📄 dropedit.cpp
字号:
// DropEdit.cpp : implementation file
//
#include "stdafx.h"
#include "yuvviewer.h"
#include "DropEdit.h"
#include <sys/types.h>
#include <sys/stat.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDropEdit
CDropEdit::CDropEdit()
{
m_bUseDir=FALSE;
}
CDropEdit::~CDropEdit()
{
}
BEGIN_MESSAGE_MAP(CDropEdit, CEdit)
//{{AFX_MSG_MAP(CDropEdit)
ON_WM_DROPFILES()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDropEdit message handlers
CString CDropEdit::ExpandShortcut(CString &inFile)
{
CString outFile = "";
ASSERT(inFile != _T(""));
IShellLink* psl;
HRESULT hres;
LPTSTR lpsz = inFile.GetBuffer(MAX_PATH);
hres = ::CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
IID_IShellLink, (LPVOID*) &psl);
if (SUCCEEDED(hres))
{
IPersistFile* ppf;
hres = psl->QueryInterface(IID_IPersistFile, (LPVOID*) &ppf);
if (SUCCEEDED(hres))
{
WORD wsz[MAX_PATH];
::MultiByteToWideChar(CP_ACP, 0, lpsz, -1, wsz, MAX_PATH);
hres = ppf->Load(wsz, STGM_READ);
if (SUCCEEDED(hres))
{
WIN32_FIND_DATA wfd;
// find the path from that
HRESULT hres = psl->GetPath(outFile.GetBuffer(MAX_PATH),
MAX_PATH,
&wfd,
SLGP_UNCPRIORITY);
outFile.ReleaseBuffer();
}
ppf->Release();
}
psl->Release();
}
inFile.ReleaseBuffer();
return outFile;
}
void CDropEdit::OnDropFiles(HDROP hDropInfo)
{
// TODO: Add your message handler code here and/or call default
WORD wNumFilesDropped = DragQueryFile(hDropInfo, -1, NULL, 0);
CString firstFile="";
for (WORD x = 0 ; x < wNumFilesDropped; x++) {
WORD wPathnameSize = DragQueryFile(hDropInfo, x, NULL, 0);
char * npszFile = (char *) LocalAlloc(LPTR, wPathnameSize += 1);
if (npszFile == NULL) continue;
DragQueryFile(hDropInfo, x, npszFile, wPathnameSize);
if (firstFile=="")
firstFile=npszFile;
LocalFree(npszFile);
}
DragFinish(hDropInfo);
CString expandedFile = ExpandShortcut(firstFile);
if (expandedFile!="")
firstFile=expandedFile;
struct _stat buf;
int result = _stat( firstFile, &buf );
if( result == 0 ) {
if ((buf.st_mode & _S_IFDIR) == _S_IFDIR) {
if (m_bUseDir)
SetWindowText(firstFile);
} else if ((buf.st_mode & _S_IFREG) == _S_IFREG) {
if (!m_bUseDir)
SetWindowText(firstFile);
}
}
CEdit::OnDropFiles(hDropInfo);
}
int CDropEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CEdit::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
DragAcceptFiles(TRUE);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -