shellextobj.cpp

来自「随着计算机信息技术的飞速发展」· C++ 代码 · 共 68 行

CPP
68
字号
// ShellExtObj.cpp : Implementation of CShellExtObj
#include "stdafx.h"
#include "ShellExt_TxtInfo.h"
#include "ShellExtObj.h"

/////////////////////////////////////////////////////////////////////////////
// CShellExtObj

// Load the file's name selected
HRESULT CShellExtObj::Load ( LPCOLESTR wszFilename, DWORD dwMode )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());    // init MFC

    // Let CString convert the filename to ANSI if necessary.
    m_sFilename = wszFilename;

    return S_OK;
}

HRESULT CShellExtObj::GetInfoTip (DWORD dwFlags,LPWSTR* ppwszTip )
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());    // init MFC

	LPMALLOC   pMalloc;
	CStdioFile file;
	DWORD      dwFileSize;
	CString    sFirstLine;
	BOOL       bReadLine;
	CString    sTooltip;

    USES_CONVERSION;

	if ( !file.Open ( m_sFilename , CFile::modeRead | CFile::shareDenyWrite ))
        return E_FAIL;

	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 ( bReadLine )
    {
        sTooltip += _T("\n");
        sTooltip += sFirstLine;
    }

	*ppwszTip = (LPWSTR) pMalloc->Alloc ( (1 + lstrlen(sTooltip)) * sizeof(wchar_t) );

    if ( NULL == *ppwszTip )
    {
        pMalloc->Release();
        return E_OUTOFMEMORY;
    }

    // Use the Unicode string copy function to put the tooltip text in the buffer.
    wcscpy ( *ppwszTip, T2COLE((LPCTSTR) sTooltip) );

	pMalloc->Release();
    return S_OK;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?