请教各位如何增加文件的属性和标签页

pengfangxu8 2014-08-06 03:35:59
在windows下,右键点击一个文件,会弹出一个标签对话框,这个对话框中有很多标签页,我想增加一个自己的标签页并且将我自己的一些信息加入到这个新加的标签页中,就像SVN那样,在文件的属性对话框中会增加一个subversion标签页,会将一些信息加入到这个标签页中。谢谢各位了。
...全文
557 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2014-08-07
  • 打赏
  • 举报
回复
搜“数字签名”
pengfangxu8 2014-08-07
  • 打赏
  • 举报
回复
我们公司的文件大部分是用SVN管理的,不希望别人带出公司,就算带出去,到时候也能追查得到,就这个需求,现在的想法是将公司的所有文件做个标记,但是又不能让别人知道,因为如果知道打了标记别人在带出前就已经处理掉标记了,怎么加这个标记,现在没有一个好的思路,麻烦您给几个思路,您觉得怎么实现好,谢谢!
pengfangxu8 2014-08-07
  • 打赏
  • 举报
回复
大侠,我测试了,不得行,麻烦您了!谢谢! 我给您发私信,请您查收,谢谢!
赵4老师 2014-08-06
  • 打赏
  • 举报
回复
你先看看我这个例子代码能不能显示出Subversion标签页中的内容,如果不能, 在http://www.codeproject.com搜“Shell Extension”
pengfangxu8 2014-08-06
  • 打赏
  • 举报
回复
大侠,对不起,是我没有没有把问题讲清楚,请您原谅,我重新描述下问题:
在windows环境下,右键点击一个文件->点击属性,然后然后弹出一个文件属性的对话框,这个对话框中有很多标签页,比如有常规,安全,详细信息,以前的版本等等标签页。如下图:

我想在这个属性对话框中加入我自己的标签页,就叫mytest吧,在新加的mytest这个这个标签页中加入一些我自己的信息,假如像这样:"author: xxx",这只是举例子,就想SVN一样它加入了Subversion这个标签页,在这个标签页下面还加了它自己的信息,如下如:

麻烦您下,帮我整个例子,在文件属性页中加入mytest这个标签页,在这个标签页中加入"author: xxx"这个信息,谢谢您!非常感谢!
赵4老师 2014-08-06
  • 打赏
  • 举报
回复
显示属性:
#pragma comment(lib,"ole32")
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <ole2.h>
#include <locale.h>
void DumpXML(char *xml) {
    static char b[8192];
    static WCHAR wstr[1024];
    char *p,*q;
    FILE *f;
    int i,L;

    f=fopen(xml,"rb");
    if (NULL==f) return;
    fread(b,1,8192,f);
    fclose(f);
    printf("================= %s =================\n",xml);
    p=b;
    for (i=0;i<3;i++) {//跳过前两个标签
        p=strchr(p,'<');
        if (!p) return;
        p++;
    }
    while (1) {
        if ('/'!=p[0]) {
            q=strchr(p,'>');
            if (!q) return;
            printf("%32.*s: ",q-p,p);
            p=q+1;
            q=strchr(p,'<');
            if (!q) return;
            L=q-p;
            for (i=0;i<L;i++) if ((unsigned char)p[i]>=0x80) break;
            if (i<L) {
                i=MultiByteToWideChar(CP_UTF8,0,p,L,wstr,1024);
                wstr[i] = 0;
                printf("%.*s UTF8(%S)\n",L,p,wstr);
            } else {
                printf("%.*s\n",L,p);
            }
            p=q+1;
        } else {
            p=strchr(p,'<');
            if (!p) return;
            p++;
        }
    }
}
void TryWinRAR(char *filename) {
    char cmd[1080];

    if (access("c:\\progra~1\\winrar\\winrar.exe",0)) return;
    system("rd /s /q docProps 1>NUL 2>NUL");
    sprintf(cmd,"c:\\progra~1\\winrar\\winrar.exe x \"%.1000s\" docProps\\*.xml",filename);
    system(cmd);
    if (!access("docProps\\core.xml",0)) DumpXML("docProps\\core.xml");
    if (!access("docProps\\app.xml",0)) DumpXML("docProps\\app.xml");
	system("rd /s /q docProps 1>NUL 2>NUL");
}
void DumpPropVariant(PROPVARIANT *pPropVar)	{//	Dumps simple PROPVARIANT values.
	if (pPropVar->vt & VT_ARRAY) {// Don't iterate arrays, just inform as an array.
		printf("%32s%s",""," (Array)\n");
		return;
	}
	if (pPropVar->vt & VT_BYREF) {// Don't handle byref for simplicity, just inform byref.
		printf("%32s%s",""," (ByRef)\n");
		return;
	}
	switch(pPropVar->vt) {
	case VT_EMPTY:printf("%32s%s",""," (VT_EMPTY)\n"                                                );break;
	case VT_NULL :printf("%32s%s",""," (VT_NULL)\n"                                                 );break;
	case VT_BLOB :printf("%32s%s",""," (VT_BLOB)\n"                                                 );break;
	case VT_BOOL :printf("%-32s" " (VT_BOOL)\n",         pPropVar->boolVal ? "TRUE/YES" : "FALSE/NO");break;
	case VT_I2	 :printf("%-32d" " (VT_I2)\n"  , (int)   pPropVar->   iVal                          );break;
	case VT_I4	 :printf("%-32d" " (VT_I4)\n"  , (int)   pPropVar->   lVal                          );break;
	case VT_R4	 :printf("%-32.2lf (VT_R4)\n"  , (double)pPropVar-> fltVal                          );break;
	case VT_R8	 :printf("%-32.2lf (VT_R8)\n"  , (double)pPropVar-> dblVal                          );break;
	case VT_BSTR: // OLE Automation	string.
		{
			// Translate into ASCII.
			char dbcs[1024];
			char *pbstr	= (char	*)pPropVar->bstrVal;
			int	i =	wcstombs(dbcs, pPropVar->bstrVal, *((DWORD *)(pbstr-4)));
			dbcs[i]	= 0;
			printf("%-32s (VT_BSTR)\n", dbcs);
		}
	break;
	case VT_LPSTR: // Null-terminated string.
		{
			char *pbstr	= (char	*)pPropVar->pszVal;
			int	i,L;
			L=strlen(pbstr);
			for	(i=0;i<L;i++) if ((unsigned	char)pbstr[i]>=0x80) break;
			if (i<L) {
				WCHAR wstr[1024];
				int	i =	MultiByteToWideChar(CP_UTF8,0,pbstr,-1,wstr,1024);
				wstr[i]	= 0;
				printf("%-32s (VT_LPSTR) UTF8(%S)\n", pPropVar->pszVal,wstr);
			} else {
				printf("%-32s (VT_LPSTR)\n", pPropVar->pszVal);
			}
		}
	break;
	case VT_LPWSTR:
		printf("%-32S (VT_LPWSTR)\n", pPropVar->pwszVal);
	break;
	case VT_FILETIME:
		{
			FILETIME lft;
			FileTimeToLocalFileTime(&pPropVar->filetime, &lft);
			SYSTEMTIME lst;
			FileTimeToSystemTime(&lft, &lst);

			printf("%d-%02d-%02d %02d:%02d.%02d              (VT_FILETIME)\n",
				lst.wYear, lst.wMonth,	lst.wDay,
				lst.wHour, lst.wMinute,	lst.wSecond);
		}
	break;
	case VT_CF:	// Clipboard format.
		printf("%32s%s",""," (Clipboard format)\n");
	break;
	default: //	Unhandled type,	consult	wtypes.h's VARENUM structure.
		printf("%32s (Unhandled type: 0x%08lx)\n", "", pPropVar->vt);
		break;
	}
}
void DumpBuiltInProps(IPropertySetStorage *pPropSetStg)	{//	Dump's built-in properties of a property storage.
	printf("\n==================================================\n");
	printf("BuiltInProperties Properties...\n");
	printf("==================================================\n");

	IPropertyStorage *pPropStg = NULL;
	HRESULT	hr;

	// Open	summary	information, getting an	IpropertyStorage.
	hr = pPropSetStg->Open(FMTID_SummaryInformation,
	STGM_READ |	STGM_SHARE_EXCLUSIVE, &pPropStg);
	if (FAILED(hr))	{
		printf("No Summary-Information.\n");
		return;
	}
	// Array of	PIDSI's you are interested in.
	struct pidsiStruct {
		char *name;
		long pidsi;
	} pidsiArr[] = {
		{"Title"          ,PIDSI_TITLE              }, // VT_LPSTR
		{"Subject"        ,PIDSI_SUBJECT            }, // ...
		{"Author"         ,PIDSI_AUTHOR             },
		{"Keywords"       ,PIDSI_KEYWORDS           },
		{"Comments"       ,PIDSI_COMMENTS           },
		{"Template"       ,PIDSI_TEMPLATE           },
		{"LastAuthor"     ,PIDSI_LASTAUTHOR         },
		{"Revision Number",PIDSI_REVNUMBER          },
		{"Edit Time"      ,PIDSI_EDITTIME           }, // VT_FILENAME (UTC)
		{"Last printed"   ,PIDSI_LASTPRINTED        }, // ...
		{"Created"        ,PIDSI_CREATE_DTM         },
		{"Last Saved"     ,PIDSI_LASTSAVE_DTM       },
		{"Page Count"     ,PIDSI_PAGECOUNT          }, // VT_I4
		{"Word Count"     ,PIDSI_WORDCOUNT          }, // ...
		{"Char Count"     ,PIDSI_CHARCOUNT          },
		{"Thumpnail"      ,PIDSI_THUMBNAIL          }, // VT_CF
		{"AppName"        ,PIDSI_APPNAME            }, // VT_LPSTR
		{"Doc Security"   ,PIDSI_DOC_SECURITY       }, // VT_I4
		{0				  ,0						},
	};
	// Count elements in pidsiArr.
	int	nPidsi = 0;
	for	(nPidsi=0; pidsiArr[nPidsi].name; nPidsi++);

	// Initialize PROPSPEC for the properties you want.
	PROPSPEC *pPropSpec	= new PROPSPEC[nPidsi];
	PROPVARIANT	*pPropVar =	new	PROPVARIANT[nPidsi];

	for	(int i=0; i<nPidsi;	i++) {
		ZeroMemory(&pPropSpec[i], sizeof(PROPSPEC));
		pPropSpec[i].ulKind	= PRSPEC_PROPID;
		pPropSpec[i].propid	= pidsiArr[i].pidsi;
	}

	// Read	properties.
	hr = pPropStg->ReadMultiple(nPidsi,	pPropSpec, pPropVar);

	if (FAILED(hr))	{
		printf("IPropertyStg::ReadMultiple() failed w/error %08lx\n",hr);
	} else {
		// Dump	properties.
		for	(i=0; i<nPidsi;	i++) {
			printf("%16s: ", pidsiArr[i].name);
			DumpPropVariant(pPropVar + i);
		}
	}

	// De-allocate memory.
	delete [] pPropVar;
	delete [] pPropSpec;

	// Release obtained	interface.
	pPropStg->Release();

}
void DumpCustomProps(IPropertySetStorage *pPropSetStg) {// Dump's custom properties of a property storage.
	printf("\n==================================================\n");
	printf("Custom Properties...\n");
	printf("==================================================\n");

	IPropertyStorage *pPropStg = NULL;
	HRESULT	hr;
	IEnumSTATPROPSTG *pEnumProp;

	// Open	User-Defined-Properties, getting an	IpropertyStorage.
	hr = pPropSetStg->Open(FMTID_UserDefinedProperties,
		STGM_READ |	STGM_SHARE_EXCLUSIVE, &pPropStg);
	if (FAILED(hr))	{
		printf("No User Defined Properties.\n");
		return;
	}

	// Get property	enumerator.
	hr = pPropStg->Enum(&pEnumProp);
	if (FAILED(hr))	{
		pPropStg->Release();
		printf("Couldn't enumerate custom properties.\n");
		return;
	}

	// Enumerate properties.
	STATPROPSTG	sps;
	ULONG fetched;
	PROPSPEC propSpec[1];
	PROPVARIANT	propVar[1];
	while(pEnumProp->Next(1, &sps, &fetched)   ==  S_OK)   {
		// Build a PROPSPEC	for	this property.
		ZeroMemory(&propSpec[0], sizeof(PROPSPEC));
		propSpec[0].ulKind = PRSPEC_PROPID;
		propSpec[0].propid = sps.propid;

		// Read	this property.
		hr = pPropStg->ReadMultiple(1, &propSpec[0], &propVar[0]);
		if (!FAILED(hr)) {
			// Translate Prop name into	ASCII.
			char dbcs[1024];
			char *pbstr	= (char	*)sps.lpwstrName;
			int	i =	wcstombs(dbcs, sps.lpwstrName,*((DWORD *)(pbstr-4)));
			dbcs[i]	= 0;

			// Dump	this property.
			printf("%16s: ", dbcs);
			DumpPropVariant(&propVar[0]);
		}
	}

	// Release obtained	interface.
	pEnumProp->Release();
	pPropStg->Release();

}
void DumpProps(char	*filename) {// Dump's custom and built-in properties of a compound document.
	// Translate filename to Unicode.
	WCHAR wcFilename[1024];
// setlocale( LC_ALL, "" );
	int	i =	mbstowcs(wcFilename, filename, strlen(filename));
// setlocale( LC_ALL, "C" );
	wcFilename[i]  = 0;

	IStorage *pStorage = NULL;
	IPropertySetStorage	*pPropSetStg = NULL;
	HRESULT	hr;

	// Open	the	document as	an OLE compound	document.
	hr = ::StgOpenStorage(wcFilename, NULL,
	STGM_READ |	STGM_SHARE_EXCLUSIVE, NULL,	0, &pStorage);

	if (FAILED(hr))	{
		if (hr == STG_E_FILENOTFOUND)
			printf("File not found.");
		else if	(hr	== STG_E_FILEALREADYEXISTS)	{
			printf("Not a compound file.\nTry use WinRAR to open docx/xlsx/pptx,view docProps\\core.xml and docProps\\app.xml\n");
			if ('.'==filename[strlen(filename)-5]) TryWinRAR(filename);
		} else
			printf("StgOpenStorage() failed w/error %08lx", hr);
		return;
	}

	// Obtain the IPropertySetStorage interface.
	hr = pStorage->QueryInterface(IID_IPropertySetStorage, (void **)&pPropSetStg);
	if (FAILED(hr))	{
		printf("QI for IPropertySetStorage failed w/error %08lx", hr);
		pStorage->Release();
		return;
	}

	// Dump	properties.
	DumpBuiltInProps(pPropSetStg);
	DumpCustomProps(pPropSetStg);

	// Release obtained	interfaces.
	pPropSetStg->Release();
	pStorage->Release();
}
void main(int argc,	char **argv) {
	if (argc !=	2) {
		printf("OLE/ZIP Document Property Viewer\n");
		printf("Usage: %s filename", argv[0]);
		return;
	}
	setlocale( LC_ALL, "chs" );
	printf("[File] %s\n",argv[1]);
	DumpProps(argv[1]);
}
pengfangxu8 2014-08-06
  • 打赏
  • 举报
回复
大侠,给个例子吧,谢谢您!英文头大,呵呵,见谅。
赵4老师 2014-08-06
  • 打赏
  • 举报
回复
IPropertySetStorage::Create Creates and opens a new property set in the property set storage object. HRESULT Create( REFFMTID fmtid, //Format identifier of the property set to be //created CLSID * pclsid, //Pointer to initial CLSID for this property set DWORD grfFlags, //PROPSETFLAG values DWORD grfMode, //Storage mode of new property set IPropertyStorage** ppPropStg //Address of output variable that receives the //IPropertyStorage interface pointer ); Parameters fmtid [in] Format identifier of the property set to be created. pclsid [in] Pointer to the initial CLSID for this property set. May be NULL, in which case it is set to all zeroes. grfFlags [in] Values from the PROPSETFLAG enumeration. grfMode [in] Access mode in which the newly created property set is to be opened, taken from certain values of the STGM enumeration, as described in the Remarks. ppPropStg [out] Address of IPropertyStorage* pointer variable that receives the interface pointer to the new property storage sub-object. Return Values This method supports the standard return value E_UNEXPECTED, as well as the following: S_OK The property set was created. STG_E_FILEALREADYEXISTS A property set of the indicated name already exists, and STGM_CREATE was not specified. STG_E_ACCESSDENIED The requested access to the property storage object has been denied. STG_E_INSUFFICIENTMEMORY There is not sufficient memory to perform this operation. STG_E_INVALIDPARAMETER A parameter is invalid. Remarks IPropertySetStorage::Create creates and opens a new property set sub-object (supporting the IPropertyStorage interface) contained in this property set storage object. The property set automatically contains code page and locale ID properties. These are set to the current system default, and the current user default, respectively. The grfFlags parameter is a combination of values taken from the enumeration PROPSETFLAG. The grfMode parameter specifies the access mode in which the newly created set is to be opened. Values for this parameter are as in the like-named parameter to IPropertySetStorage::Open, with the addition of the following values: Value Meaning STGM_FAILIFTHERE If another property set with the specified fmtid already exists, the call fails. This is the default action; that is, unless STGM_CREATE is specified, STGM_FAILIFTHERE is implied. STGM_CREATE If another property set with the specified fmtid already exists, it is removed and replaced with this new one. STGM_DIRECT Open the property set without an additional level of transaction nesting. This is the default (the behavior if neither STGM_DIRECT nor STGM_TRANSACTED is specified). STGM_TRANSACTED Open the property set with an additional level of transaction nesting (beyond the transaction, if any, on this property set storage). This is possible only when you specify PROPSETFLAG_NONSIMPLE in the grfFlags parameter. Changes in the property set must be committed with IPropertyStorage::Commit before they are visible to the transaction on this property set storage. STGM_READ Read access is desired on the property set. Read permission is required on the property set storage. STGM_WRITE Write access is desired on the property set. Write permission is not required on the property set storage; however, such write permission is required for changes in the storage to be committed. STGM_READWRITE Read-write access is desired on the property set. Note that this flag is not the binary OR of the values STGM_READ and STGM_WRITE. STGM_SHARE_EXCLUSIVE Prevents others from subsequently opening the property set either in STGM_READ or STGM_WRITE mode. Note The only access mode supported by Create is STGM_SHARE_EXCLUSIVE. To use the resulting property set in an access mode other than STGM_SHARE_EXCLUSIVE, the caller should close the stream and then re-open it with a call to IPropertySetStorage::Open. QuickInfo Windows NT: Use version 4.0 or later. Windows: Use Windows 95 or later. Available as a redistributable for Windows 95. Windows CE: Unsupported. Header: Declared in objidl.h. See Also IPropertySetStorage::Open

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧