?? txtinfoshlext.cpp
字號:
// TxtInfoShlExt.cpp : Implementation of CTxtInfoShlExt
#include "stdafx.h"
#include "resource.h"
#include "TxtInfo.h"
#include "TxtInfoShlExt.h"
/////////////////////////////////////////////////////////////////////////////
// CTxtInfoShlExt
STDMETHODIMP CTxtInfoShlExt::Load ( LPCOLESTR wszFilename, DWORD dwMode )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); // init MFC
UNREFERENCED_PARAMETER(dwMode);
// Let CString convert the filename to ANSI.
m_sFilename = wszFilename;
return S_OK;
}
STDMETHODIMP CTxtInfoShlExt::GetInfoTip ( DWORD dwFlags, LPWSTR* ppwszTip )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState()); // init MFC
USES_CONVERSION;
LPMALLOC pMalloc;
CStdioFile file;
DWORD dwFileSize;
CString sFirstLine;
BOOL bReadLine;
CString sTooltip;
UNREFERENCED_PARAMETER(dwFlags);
// Try to open the file.
if ( !file.Open ( m_sFilename , CFile::modeRead | CFile::shareDenyWrite ) )
return E_FAIL;
// Get an IMalloc interface from the shell.
if ( FAILED( SHGetMalloc ( &pMalloc ) ))
return E_FAIL;
// Get the size of the file.
dwFileSize = file.GetLength();
// Read in the first line from the file.
bReadLine = file.ReadString ( sFirstLine );
sTooltip.Format ( _T("File size: %lu"), dwFileSize );
// If we were able to read in the first line, add it to the tooltip.
if ( bReadLine )
{
sTooltip += _T("\n");
sTooltip += sFirstLine;
}
// Allocate a buffer for Explorer. Note that the must pass the string
// back as a Unicode string, so the string length is multiplied by the
// size of a Unicode character.
ULONG cbText = (1 + sTooltip.GetLength()) * sizeof(wchar_t);
*ppwszTip = (LPWSTR) pMalloc->Alloc ( cbText );
// Release the IMalloc interface now that we're done using it.
pMalloc->Release();
if ( NULL == *ppwszTip )
return E_OUTOFMEMORY;
// Use the Unicode string copy function to put the tooltip text in the buffer.
wcscpy ( *ppwszTip, T2COLE(LPCTSTR(sTooltip)) );
return S_OK;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -